Mounting an NFS Home Share on CentOS 7 Clients
-
Home directories present both a unique challenge and opportunity for utilizing remote shares in UNIX. As an opportunity they allow us to keep servers lean and share home directories broadly giving end users consistent files and environments with minimal effort, reducing storage needs and speeding system deployment. The challenge is that we want to avoid the overhead and risks of having home directories continuously mounted when unneeded. Home directories are probably the most common usage of NFS shares to normal servers (outside of unique uses such as backup targets and virtualization shared storage.)
To tackle the problems associated with persistent mount mounts (such as delays or failures at boot time) on Linux we look to the use of automounting - that is a daemon that will look for a filesystem require and initiate the NFS mount at the time of use rather than proactively.
Note: In my examples, nfs is the /etc/hosts entry for my NFS server. You will need to use the name of your server wherever you see me referencing nfs as a server name.
The Linux daemon that handles this is autofs. Autofs is not installed in a CentOS 7 minimal install so we need to add it.
yum -y install autofs nfs-utils
Now to configure autofs to look for home directories to mount:
echo "/home /etc/auto.home" >> /etc/auto.master echo "* nfs:/home/&" >> /etc/auto.home
Now to move the old /home out of the way in case something is there already.
mv /home /tmp/home.old; mkdir /home
And we can start up AutoFS:
systemctl enable autofs.service systemctl restart autofs.service reboot
Now we have two convenient ways for testing the automounter. By default the "net" filesystem is enabled and we can simply navigate to...
cd /net/nfs/home
And our files should be visible there. You will often need to navigate directly into a subfolder of the mount to see them.
If you have home directories created on the share already then we can test mounting in that way:
sudo su - username
This should, if all is working, take you right into the newly mounted home directory. You can test with these commands:
pwd df .
-
If the NFS server is down I assume the only way I could login would be with the root account?
-
@anonymous said:
If the NFS server is down I assume the only way I could login would be with the root account?
That's correct, unless you take other measures. You can always have an admin account that is not on the NFS, which would be recommended.
So example:
Normal Account: anon:/home/anon
Special Account: anonadmin:/opt/home/anonadmin/home would be mounted via NFS
/opt/home would be local to the /opt filesystem (we use /opt over /var in this example because /var is often remotely mounted as well and more volatile.)This is a solid workaround so that if anything is wrong with the mounting system on either end, or in the network, that the machine remains reachable and manageable in a simple manner. It is also common to place "utility" accounts in /opt/home for a similar reason. If you have an application that runs and needs a home directory, you likely don't want it mounting it over NFS and pulling data externally like a user would.
-
Keep in mind that this is not a process for "normal" servers, this is a technique used for servers with users. If you had a pure server that there is no reason for users to log into, you would not likely want to do this in most cases. You would probably not have user accounts at all.
-
I've never used autofs, does it do the /etc/fstab stuff for you, or just replace it altogether for the home folder?
-
@johnhooks said:
I've never used autofs, does it do the /etc/fstab stuff for you, or just replace it altogether for the home folder?
AutoFS does not use
fstab
at all, it is specifically to replace that as the connections are not permanent, they are ephemeral. It mounts filesystems at the time of use, not proactively. This is better for security as the mounts are not discoverable and better for performance as they are not mounted when not used. It's also good for reliability as if a mount fails now, it will attempt a remount later. It also unmounts after a time of disuse.AutoFS uses mount commands under the hood, not the fstab during startup. You can use it with any filesystem. Home is common, and the /net filesystem is standard, but you could use it for anything. It's fully customizable.
-
Tested on the second CentOS 7 server and working there, too. So far so good. And the NFS from OpenSuse Leap 42.1 over the Scale cluster is insanely fast, it looks instant when using it.
-
@scottalanmiller said:
@johnhooks said:
I've never used autofs, does it do the /etc/fstab stuff for you, or just replace it altogether for the home folder?
AutoFS does not use
fstab
at all, it is specifically to replace that as the connections are not permanent, they are ephemeral. It mounts filesystems at the time of use, not proactively. This is better for security as the mounts are not discoverable and better for performance as they are not mounted when not used. It's also good for reliability as if a mount fails now, it will attempt a remount later. It also unmounts after a time of disuse.AutoFS uses mount commands under the hood, not the fstab during startup. You can use it with any filesystem. Home is common, and the /net filesystem is standard, but you could use it for anything. It's fully customizable.
I realized how stupid this question was after I walked away and got in the shower. I was hoping to make it back before you read it haha.
-
No such luck
-
What happens if you are connected and then lose connection to the NFS server? Does it store data until reconnection?
-
@johnhooks said:
What happens if you are connected and then lose connection to the NFS server? Does it store data until reconnection?
Store data? Where would it "store data"? What are you picturing? The filesystem would be gone, same as any "mapped drive" situation.
-
@scottalanmiller said:
@johnhooks said:
What happens if you are connected and then lose connection to the NFS server? Does it store data until reconnection?
Store data? Where would it "store data"? What are you picturing? The filesystem would be gone, same as any "mapped drive" situation.
Store as in cache somewhere until it can reconnect.
-
No, there is nothing like that. The filesystem is just not there. It would warn you, though, so you would know not to be trying to save to something that doesn't exist.