NFS Server
Install required services for it to run as NFS server :
yum install nfs-utils libnfsidmap -y
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
systemctl start rpc-statd
systemctl start nfs-idmapd
Create a directory where we want to set as the NFS Directory, in this case we call it “shared_home”. Afterwards, change the ownership and permission of the new directory :
mkdir /shared_home
chown -R nfsnobody. shared_home/
chmod 777 /shared_home/
Edit file /etc/exports to allow which server that will use the NFS directory.
vi /etc/exports
E.g. content of the file where we allow server 10.62.8.32 to access the NFS directory :
/shared_home 10.62.8.32(rw,sync,no_root_squash,no_subtree_check)
Run below command to apply the new configuration
exportfs -a
Client Server
Client server for example, a Web Server that will mount the NFS directory to local directory for example “/home”, before we can connect to the NFS server, we need to install few services :
yum -y install nfs-utils libnfsidmap -y
systemctl enable rpcbind
systemctl start rpcbind
Verify the directory that the NFS server is sharing
showmount -e 10.62.8.34
Mount the NFS directory
mount -t nfs -vvvv -o nfsvers=3 10.62.8.34:/shared_home /home
To apply the NFS directory permanently even after reboot, we need to add the new mount in /etc/fstab
vi /etc/fstab
Insert content as below
10.62.8.34:/shared_home /home nfs defaults,vers=3,nolock 0 0
To verify, run command
df -h
If you can see the new mounted directory, it is successful, example as below
[root@web-2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.6G 16G 9% /
devtmpfs 908M 0 908M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.8M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda1 1014M 189M 826M 19% /boot
nfs-1:/shared_home 17G 1.6G 16G 9% /home
tmpfs 184M 0 184M 0% /run/user/0
You are free to perform reboot test, to verify /etc/fstab is working properly