Here are my demo nodes details.
NFS Server IP Address
192.168.12.5
NFS Client IP Address
192.168.12.7
Usage of NFS
File / Folder sharing between Linux systems
Allows to mount remote filesystems locally
Allows applications to share configuration and data files with multiple nodes.
Allows to have updated files across the share.
Install NFS Server
We need to install NFS packages on NFS server, install it using the following command.
[root@server ~]# yum install nfs-utils
Once the packages are installed, enable and start NFS services.
systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap
Create NFS Share
Create a directory to share with client servers. Here I will be creating a new directory named “nfsfileshare” in “/” partition.
Note: You can also share your existing directory with NFS.
[root@server ~]# mkdir /nfsfileshare
Allow client servers to read and write to the created directory.
[root@server ~]# chmod 777 /nfsfileshare/
We have to modify “/etc/exports“file to make an entry of directory “/nfsfileshare” that you want to share.
[root@server ~]# vi /etc/exports
/nfsfileshare 192.168.12.7(rw,sync,no_root_squash)
/nfsfileshare : shared directory
[root@server ~]# exportfs -r
Configure NFS client
We need to install NFS packages on NFS client-server to mount remote filesystem, install NFS packages using below command.
[root@client ~]# yum -y install nfs-utils
Once the packages are installed, enable and start NFS services.
systemctl enable rpcbind
systemctl start rpcbind
Mount NFS shares on clients
Before mounting the NFS share, we need to check the available shares on the NFS server. To do that, run the following command on the client-server.
[root@client ~]# showmount -e 192.168.12.5
Export list for 192.168.12.5:
/nfsfileshare 192.168.12.7
[root@client ~]# mkdir /mnt/nfsfileshare
[root@client ~]# mount 192.168.12.5:/nfsfileshare /mnt/nfsfileshare
[root@client ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 478M 0 478M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 620K 488M 1% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/mapper/fedora-root xfs 18G 1.3G 17G 8% /
tmpfs tmpfs 489M 4.0K 489M 1% /tmp
/dev/sda1 ext4 477M 93M 355M 21% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
192.168.12.5:/nfsfileshare nfs4 50G 858M 50G 2% /mnt/nfsfileshare
Automount NFS Shares
To mount the shares automatically on every reboot, need to modify “/etc/fstab” file of your client system.
Add “green” line at the end.
[root@client ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue May 22 11:30:49 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/fedora-root / xfs defaults 0 0
UUID=f748af6c-0de9-4dc0-98e6-959ffc400f2f /boot ext4 defaults 1 2
/dev/mapper/fedora-swap swap swap defaults 0 0
192.168.12.5:/nfsfileshare/ /mnt/nfsfileshare nfs rw,sync,hard,intr 0 0
save and close the file.
Reboot the client machine and check the share whether it is automatically mounted or not.
[root@client ~]# reboot