In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to mount NFS shares using autofs in LINUX? I believe that many inexperienced people are helpless about this. For this reason, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
A Method of Using Autofs to Mount NFS Share in LINUX System
Most Linux file systems are mounted at boot time and remain mounted while the system is running. The same is true for any remote file system that has been configured in fstab. However, sometimes you may want to mount remote file systems only on demand. For example, to improve performance by reducing network bandwidth usage, or to hide or obfuscate certain directories for security reasons. The autofs package provides this functionality. In this article, I'll show you how to configure basic automount.
Let's start with an assumption: Suppose an NFS server tree.mydatacenter.net is up and running. Suppose also that a data directory named ourfiles also has user directories for Carl and Sarah, both shared by servers.
Some best practices can make things work better: Users on the server have the same user ID as accounts on any client workstation. Also, your workstation and server should have the same domain name. Checking the relevant configuration file should confirm.
alan@workstation1:~$ sudo getent passwd carl sarah[sudo] password for alan:carl:x:1020:1020:Carl,,,:/home/carl:/bin/bashsarah:x:1021:1021:Sarah,,,:/home/sarah:/bin/bashalan@workstation1:~$ sudo getent hosts127.0.0.1 localhost127.0.1.1 workstation1.mydatacenter.net workstation110.10.1.5 tree.mydatacenter.net tree
As you can see, both client workstations and NFS servers are configured in the hosts file. I assume this is a basic home or even small office network that probably lacks the proper internal domain name service (i.e. DNS).
installation package
You only need to install two packages: nfs-common for NFS clients and autofs for automount.
alan@workstation1:~$ sudo apt-get install nfs-common autofs
You can verify that autofs files are in the/etc directory:
alan@workstation1:~$ 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*alan@workstation1:/etc$
Configure autofs
Now you need to edit several of these files and add the auto.home file. First, add the following two lines to the file auto.master:
/mnt/tree /etc/auto.misc/home/tree /etc/auto.home
Each line begins with the directory where the NFS share is mounted. Continue creating these directories:
alan@workstation1:/etc$ sudo mkdir /mnt/tree /home/tree
Next, add the following line to the file auto.misc:
ourfiles -fstype=nfs tree:/share/ourfiles
This line indicates that autofs will mount the ourfiles share matching auto.misc in the auto.master file. As shown above, these files will be in the/mnt/tree/ourfiles directory.
Step 3, create the file auto.home with the following lines:
* -fstype=nfs tree:/home/&
This line indicates that autofs will mount user shares matching auto.home in the auto.master file. In this case, Carl's and Sarah's files would be in the directory/home/tree/carl or/home/tree/sarah, respectively. An asterisk *(called a wildcard) enables each user's share to be mounted automatically at login.& The symbol can also be used as a wildcard to represent server-side user directories. Their home directories are mapped accordingly according to the passwd file. If you prefer a local home directory, you don't need to do this. Instead, users can use it as simple remote storage for specific files.
Finally, restart the autofs daemon to recognize and load these configuration changes.
alan@workstation1:/etc$ sudo service autofs restart
Testing autofs
If you change the directories listed in the file auto.master and run ls, you won't see anything immediately. For example, switch to directory/mnt/tree. First, the output of ls doesn't show anything, but after running cd ourfiles, the ourfiles shared directory is automatically mounted. The cd command will also be executed, and you will enter the newly mounted directory.
carl@workstation1:~$ cd /mnt/treecarl@workstation1:/mnt/tree$ lscarl@workstation1:/mnt/tree$ cd ourfilescarl@workstation1:/mnt/tree/ourfiles$
To further confirm that this is working correctly, the mount command displays details of the mounted share.
carl@workstation1:~$ mounttree:/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)
For Carl and Sarah, the/home/tree directory works the same way.
After reading the above, do you know how to mount NFS shares using autofs in LINUX? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.