Setup NFS server on CentOS 7

Scenario: How to setup NFS server and NFS client.
System:
– CentOS 7 NFS server IP Address: 192.168.99.11
– CentOS 6 NFS client IP Address: 192.168.99.17

Steps:
1) Configure NFS server
– Install NFS packages on the CentOS server with yum:
yum install nfs-utils

– Create the directory that will be shared by NFS:
mkdir /NFSdisk

– Change the permissions of the folder as follows:
chmod -R 755 /NFSdisk
chown nfsnobody:nfsnobody /NFSdisk

– Start service and enable at boot:
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

– Edit firewall allow NFS service

firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --permanent --zone=public --add-service=mountd
firewall-cmd --permanent --zone=public --add-service=rpc-bind
firewall-cmd --reload

– Share the NFS directory over the network a follows,in this scenario will share to 4 servers(NFS client):
vi /etc/exports

/NFSdisk 192.168.99.15(rw,sync,no_root_squash)
/NFSdisk 192.168.99.17(rw,sync,no_root_squash)
/NFSdisk 192.168.99.9(rw,sync,no_root_squash)
/NFSdisk 192.168.99.7(rw,sync,no_root_squash)

Note: Whenever we modify /etc/exports, we must run: exportfs -a

2) Example configure NFS client on CentOS/RHEL linux server
– Create the directory where we want to mount the NFS shares
mkdir /dataNFS

– Run below command to temporary mount NFS(will loose if server reboot)
mount -t nfs 192.168.99.11:/NFSdisk /dataNFS

[root@centos6 /]# mount -t nfs 192.168.99.11:/NFSdisk /dataNFS
[root@centos6 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolumeGroup-lv_root 9.9G 1.8G 7.6G 20% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolumeGroup-lv_opt 2.5G 68M 2.3G 3% /opt
/dev/mapper/VolumeGroup-lv_var 9.9G 199M 9.2G 3% /var
/dev/mapper/VolumeGroup-lv_home 1008M 68M 890M 8% /home
192.168.99.11:/NFSdisk 100G 33M 100G 1% /dataNFS
[root@centos6 /]#

– Mount pemanent;y,edit /etc/fstab .
vi /etc/fstab
and place below command

192.168.99.11:/NFSdisk /dataNFS nfs defaults 0 0

Reference:
https://www.howtoforge.com/nfs-server-and-client-on-centos-7
https://www.howtoforge.com/tutorial/setting-up-an-nfs-server-and-client-on-centos-7/

Leave a Reply

Your email address will not be published. Required fields are marked *