当前位置:网站首页>How to mount NFS shares using autofs
How to mount NFS shares using autofs
2022-07-24 12:37:00 【Brother Xing plays with the clouds】
majority Linux File systems are mounted at boot time , And it is still mounted when the system is running . stay fstab The same is true for any remote file system configured in the file . however , Sometimes you may want to mount remote file systems only on demand — for example , Improve performance by reducing network bandwidth usage , Or hide or confuse some directories for security reasons . package autofs Provides this feature . In this paper , I will describe how to start and run the basic autoload configuration .
First , hypothesis NFS The server linux.linuxidc.com Started and running . And suppose this The server Share a named ourfiles Data directory and two for linuxidc and Sarah User directory for .
Some best practices will make things work better : stay The server Use the same user as on any client workstation for users ID It's a good idea , Because they have an account . in addition , Your workstation and server should have the same domain name . Check the relevant configuration files and confirm .
[email protected]:~$ sudo getent passwd linuxidc sarah [sudo] password for alan: linuxidc:x:1020:1020:linuxidc,,,:/home/linuxidc:/bin/bash sarah:x:1021:1021:Sarah,,,:/home/sarah:/bin/bash
[email protected]:~$ sudo getent hosts 127.0.0.1 localhost 127.0.1.1 linuxidc.linuxidc.com linuxidc 10.10.1.5 linux.linuxidc.com tree
As you can see , Client workstations and NFS Servers are configured in the host file . I assume that a basic home or even small office network may lack appropriate internal domain name services ( namely .,DNS).
Installation package
You only need to install two packages :NFS Common use of client functions NFS package , And provide automount Functional autofs package .
[email protected]:~$ sudo apt-get install nfs-common autofs
You can verify autofs The file has been placed in etc Catalog :
[email protected]:~$ cd /etc; ll auto* -rw-r--r-- 1 root root 12596 Nov 19 2015 autofs.conf -rw-r--r-- 1 root root 857 Mar 10 2017 auto.master -rw-r--r-- 1 root root 708 Jul 6 2017 auto.misc -rwxr-xr-x 1 root root 1039 Nov 19 2015 auto.net* -rwxr-xr-x 1 root root 2191 Nov 19 2015 auto.smb* [email protected]:/etc$
To configure autofs
Now you need to edit several of these files , And add files auto.home. First , To file auto.master Add the following two lines :
/mnt/tree /etc/auto.misc /home/tree /etc/auto.home
Every line is marked with NFS share At the beginning of the directory . Continue to create these directories :
[email protected]:/etc$ sudo mkdir /mnt/tree /home/tree
The second step , stay auto.misc Add the following lines to the file :
ourfiles -fstype=nfs tree:/share/ourfiles
This line indicates autofs stay auto Mount at the matching location in ourfiles share . be used for auto.misc Main file of . As shown above , These files can be found in the directory /mnt/ Trees /ourfiles Find .
Third , Create files automatically . Home and the following line :
* -fstype=nfs tree:/home/&
This line indicates autofs stay auto Mount user share at the matching location in . Automatically .home Main file of . In this case ,linuxidc and Sarah The files will be in the directory /home/tree/linuxidc or /home/tree/sarah Available in the . asterisk ( Called wildcards ) Make it possible for each user's share to be automatically mounted when logging in .& and It is also used as a wildcard to represent the user's directory on the server . Their home directories should be mapped to passwd In file . If you like the local home directory , You don't have to do this ; contrary , Users can use it as a simple remote storage for specific files .
Last , Restart autofs Daemon , Enable it to recognize and load these configuration file changes .
[email protected]:/etc$ sudo service autofs restart
test autofs
If you change to one of the directories listed in the file , Automatically . Master and run ls command , You won't see anything immediately . for example , Put the table of contents (cd) Change to /mnt/tree. First ,ls The output of does not show anything , But it's running cd ourfiles after ,ourfiles The shared directory will be automatically mounted .cd The command will also be executed , You will be placed in the newly mounted directory .
[email protected]:~$ cd /mnt/tree [email protected]:/mnt/tree$ ls [email protected]:/mnt/tree$ cd ourfiles [email protected]:/mnt/tree/ourfiles$
To further confirm that it is working ,mount The command will display the details of mounting the share .
[email protected]:~$ mount tree:/mnt/share/ourfiles on /mnt/tree/ourfiles type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.10.1.22,local_lock=none,addr=10.10.1.5)
about linuxidc and Sarah Come on ,/home/tree Directories work in the same way .
I find it useful to bookmark these directories in my file manager , In order to access .
边栏推荐
- 让一套代码完美适配各种屏幕
- 基于Kubernetes v1.24.0的集群搭建(一)
- Understand what goals the MES system can achieve
- 我在一个模块工程中使用注解配置了redis的序列化, 然后在另外一个模块引入这个模块,为什么这个配置
- Industry insight | how to better build a data center? It and business should "go together"
- 【功能测试】项目的测试——登录和发布文章功能
- 微信小程序生成二维码
- How QT creator changes the default build directory
- Unity rotation test
- 有没有2、3w前期适合一个人干的创业项目呢?做自媒体可以吗?
猜你喜欢
![[rust] rust language foundation | you should quickly get an impression when learning a language](/img/70/b420d62759f0c52bf4cc8d2a500813.png)
[rust] rust language foundation | you should quickly get an impression when learning a language

Solutions to problems in IE6 browser

Wechat applet - drawing dashboard

字符串匹配的KMP
How to render millions of 2D objects smoothly with webgpu?

Implementing deep learning framework from zero -- further exploration of the implementation of multilayer bidirectional RNN

6-16漏洞利用-rlogin最高权限登陆

基于ARM和FPGA的数字示波器设计——QMJ

String matching KMP

【功能测试】项目的测试——登录和发布文章功能
随机推荐
如何将Typora中图片上传到csdn
Seckill implementation diagram
支持刘海屏
Reserved instances & Savings Plans
Wechat applet generates QR code
使用Jenkins搭建CI服务器
String matching KMP
Using huggingface model to translate English
I used annotations to configure the serialization of redis in one module project, and then introduced this module in another module. Why is this configuration
Oceanbase Database Setup Test
Why is there discontinuity in MySQL auto increment primary key?
基于Kubernetes v1.24.0的集群搭建(三)
How QT creator changes the default build directory
Native Crash的一切
Okaleido tiger NFT is about to log in to binance NFT platform
thinkphp 实现数据库备份
Opencv:08 image pyramid
Buckle practice - 24 remove repeated letters
Video realizes the control of video progress, playback and pause
Reserved instances & Savings Plans