Remote Filesystems and Autofs
Configuring a Base NFS Server
Note: Setting up an NFS server is not required for the exam
dnf install nfs-utils
mkdir -p /nfsdata /home/ldap/ldapuser{1..9}
echo "/nfsdata *(rw,no_root_squash)" >> /etc/exports
echo "/home/ldap *(rw,no_root_squash)" >> /etc/exports
systemctl enable --now nfs-server
for i in nfs mountd rpc-bind; do firewall-cmd --add-service $i --permanent; done
firewallcmd --reload
Mounting NFS Shares
From the client:
showmount -e {nfs-host-address}
mount {nfs-host-address}:/path/to/share /mnt
Configuring Automount
Example: autofs managed directory, /autofs-mounts, containing a single mount, nfsdata
/etc/auto.master.d/autofs-mounts.autofs
/autofs-mounts /etc/auto.autofs-mounts
/etc/auto.autofs-mounts
nfsdata -rw localhost:/nfsdata
Autofs for Home Directories
- It is common for an NFS server to provide access to home directories
- In this configuration, autofs can be used to automatically mount home directories when a user logs into a system
- This is very convenient for users that need to log into several different machines
Example:
/etc/auto.master.d/ldap.autofs
/home/ldap /etc/auto.ldap
/etc/auto.ldap
* -rw localhost:/home/ldap/&
Systemd Automount
- Systemd automounts offer similar functionality to autofs with one downside, they do not offer wildcard mounts
Example:
/etc/systemd/system/nfsdata.mount
[Unit]
Description="nfs mount"
Requires=network-online.target
After=network-online.target
[Mount]
What=localhost:/nfsdata
Where=/nfsdata_am
Options=
Type=nfs
[Install]
WantedBy=multi-user.target
/etc/systemd/system/nfsdata.automount
[Unit]
Description="nfs automount"
Requires=network-online.target
After=network-online.target
[AutoMount]
Where=/nfsdata_am
TimeoutIdleSec=30
[Install]
WantedBy=multi-user.target
Note: The Where location has to match the unit name. A mount point of /nfs/data would become nfs-data.mount. A mount point of /nfs-data would need to contain escape characters, so it’s best to use an underscore instead.
To generate the mount unit name for a path:
systemd-escape -p --suffix=mount "/nfs-data"
Lab Exercise
Configure a second server, nfsserver, to host an nfs share. Create home directories /home/ldap/user{1..9} and export /home/ldap.
- From the workstation, set up automount for the home directories on /home/ldap. The result should be that the directory /home/ldap/userN is mounted when userN logs in. Test it by creating a userN and logging in.
Solution
-
—
/etc/auto.master
/home/ldap /etc/auto.ldap/etc/auto.ldap
* nfsserver:/home/ldap/&
Note: Sander van Vugt used
* nfsserver:/home/ldap/&in the/etc/auto.ldapfile. This setup did not seem to work, but* nfsserver:/home/ldapdid.
- Clint Jordan