In this tutorial, we will learn how to Install and Configure NFS Server on RHEL/CentOS 7.
Network File system (NFS) is a commonly used file-based storage system that allows remote systems to access files over a computer network and interact with them as if they were locally mounted. This enables system Administrators to group resources onto centralized servers on a network for easy sharing.
Configuring NFS server.
To configure NFS server, we will be using two CentOS 7 servers; one acting as the Server while the other acting as the Client.
- The hostname and IP address of the server is set to server1.example.com and 192.168.122.10 respectively.
- The hostname and IP address of the server is set to server2.example.com and 192.168.122.11 respectively.
Before proceeding with the configuration, we will install NFS packages on both the Server and the Client by running the command below.
# yum install nfs-utils nfs-utils-lib -y
Once the packages are installed, edit the /etc/idmapd.conf file as follow.
On vim, set number on to display line numbers then uncomment line number 5 as shown in the screenshot below. Enter the appropriate domain name.
4 # The default is the host's DNS domain name. 5 Domain = example.co
Edit the file /etc/exports and add file system or directory to be exported to client and specify the options to apply as in the screenshot below:
NB: Each entry for an exported file system has the following structure:
export host(options)
For our case:
/home 192.168.122.11(rw,no_root_squash)
where:
– export is the file system or directory to be mounted on remote host
– host is the remote host
– options are comma separated list of options
Options used as in the above are:
– rw allows the client server both read and write access within the shared directory.
– no_root_squash allows root to connect to the designated directory.
Allow NFS server through the firewall if firewalld is running:
# firewall-cmd --add-service=nfs --permanent;firewall-cmd reload
Enable and start both rpcbind and nfs-server
# systemctl enable nfs-server rpcbind
# systemctl start nfs-server rpcbind
Configure NFS Client
After configuring the NFS server, the shared directory or file system has to be mounted on the client so it can be accessed.
But before that, edit the /etc/idmap.conf file and add a domain name by uncommenting line 5 and placing your appropriate domain name as we did for the NFS server above.
Enable and start rpcbind service
# systemctl enable rpcbind;systemctl start rpcbind
Mount the shared directory on NFS client.
Before mounting, you need to discover NFS exports, that is, the shares available on the NFS server as shown below.
# mount server1/example.com:/ /mnt/ # ls /mnt/home/ nfsfiles
Then mount the shared directory
# mount -t nfs server1.example.com:/home /home
Confirm that the shared directory is mounted by using df -hT. See the last line in the screenshot below.
NFS share can also be added to fstab for automounting when the system boots. To enable automounting, add the fstab entry as shown in the screenshot.
The _netdev mount option can also be used to tell the mount command to mount the file systems only when the network is activated. This option has been replaced by remote-fs.target systemd unit on RHEL 7. To ensure that file systems are mounted once the network is up, the remote-fs.target must be enabled.
To test this, navigate to /home directory on the NFS server and create a testfile.txt. Check its availability on the mount point on the NFS client. If the file exist the configuration is okay.
Configuring Automounting
NFS cannot be used to manage several mount points at a time. However, Kernel-based automount utility, autofs which is used on-demand mountng, that is, only when there is a need, can be used instead.
Default configuration file for autofs is /etc/auto.master. The master map lists autofs controlled mount points on the system and their corresponding configuration files or network sources called automount maps.
To proceed with the automountning configuration, Install autofs.
# yum -y install autofs
Edit the /etc/auto.master file
# vim /etc/auto.master
Add a direct mount point at the end of the file. Direct mounts always have /- as the starting point in the master map file.
/- /etc/auto.mount
Save and exit the /etc/auto.master file.
Edit the mount point (/etc/auto.mount) and create a new map in the form:
mount-point options location
/newmnt -fstype=nfs,rw server1.example.com:/home
Make sure the /newmnt directory exists.
Start and enable autofs:
# systemctl enable autofs;systemctl start autofs
Navigate into the /newmnt directory and run ll command and you should be able to see the shared files.
Upto there, we have successfully configured both the NFS server and NFS client, NFS mounting on fstab and auto-mounting using autofs. Stay tuned for more storage server configurations such as iSCSI, ceph, GlusterFS
Hi,
great….
Thanks a lot