Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use autofs to mount NFS share in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use autofs to mount NFS sharing in linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

First of all, let's make some assumptions: suppose there is a NFS server, tree.mydatacenter.net, up and running. Also assume that a data directory called ourfiles also has user directories for Carl and Sarah, both of which are shared by the server.

Some practices can make work better: the user on the server has the same user ID as the account on any client workstation. In addition, your workstation and server should have the same domain name. Check the relevant configuration files should be confirmed.

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/bash alan@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, the client workstation and the NFS server are configured in the hosts file. I assume that this is a basic home or even a small office network that may lack a suitable internal domain name service (that is, DNS).

Install the package

You only need to install two packages: nfs-common for NFS clients and autofs that provides automatic mount.

Alan@workstation1:~$ sudo apt-get install nfs-common autofs

You can verify that autofs-related files have been placed 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$ configuration autofs

Now you need to edit some 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 to create 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 in the auto.master file that matches auto.misc. As shown above, these files will be in the / mnt/tree/ourfiles directory.

The third step is to create the file auto.home using the following line:

*-fstype=nfs tree:/home/&

This line indicates that autofs will mount the user share that matches the auto.home in the auto.master file. In this case, the files for Carl and Sarah will be in the directory / home/tree/carl or / home/tree/sarah, respectively. The asterisk * (called a wildcard) allows each user's share to be mounted automatically at login. The & symbol can also be used as a wildcard to represent a server-side user directory. Their home directories are mapped accordingly according to the passwd file. If you prefer the local home directory, you do not need to do this. Instead, users can use it as simple remote storage for specific files.

* restart the autofs daemon to identify and load these configuration changes.

Alan@workstation1:/etc$ sudo service autofs restart Test autofs

If you change the directory listed in the file auto.master and run the ls command, you won't see anything immediately. For example, change to the directory / mnt/tree. First, the output of ls will not show anything, but after running cd ourfiles, the ourfiles shared directory will be 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 it is working properly, the mount command displays the details of the mounted share.

Carl@workstation1:~$ 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)

It works the same way for Carl and Sarah,/home/tree directories.

This is the end of this article on "how to use autofs to mount NFS sharing in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report