Using NFS server will share the files/ Directories over the network.
Using this service will install operating system and access the remote server directory/file to read/write files and will share the file/directory to other machines.
Installing NFS packages:
Use the below command to install all the required packages in one shot.
#yum install nfs*
Check whether the packages are installed by executing below command
[root@server ~]# rpm -qa | grep nfs
Important configuration files:
/etc/exports : This file contains which all are exported to remote machines
/etc/host.allow : Daemon/ Client which matches the entry available in this file, will be granted access.
/etc/host.deny : Access is denied for daemon/ client which matches in this file.
/etc/fstab : Will mount the shared directories/ filesystems permanently using this file.
/etc/sysconfig/nfs: Will manage the nfs port using this file.
Services which need to be enabled and started:
Command to enable the services:
#systemctl enable rpcbind
#systemctl enable nfs-server
[root@server ~]# systemctl enable rpcbind
[root@server ~]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
Command to start the services:
#systemctl start rpcbind
#systemctl start nfs-server
[root@server ~]# systemctl start nfs-server
[root@server ~]# systemctl start rpcbind
create directory for sharing:
[root@server ~]# mkdir /nfshare
set the all permission to all
#chmod 777 /nfshare
Now share the directory using NFS by mentioning the directory details in /etc/exports file
save and exit from the file
Now use the below command to make it available in network as a shared directory
[root@server ~]# exportfs -r
Enable the services permanently in firewall in this session
[root@server ~]# firewall-cmd --permanent --zone public --add-service mountd
[root@server ~]# firewall-cmd --permanent --zone public --add-service rpc-bind
[root@server ~]# firewall-cmd --permanent --zone public --add-service nfs
reload the firewall changes and make effect in this session by executing below command
[root@server ~]# firewall-cmd --reload
Now all the configuration has been done in server side and have to check and mount the shared directory in client machine.
showmount command will help us to list the directory which is shared from remote machine.
[root@node1 ~]# showmount -e 192.168.43.226
Export list for 192.168.43.226:
Now we need to mount the shared directory in client. Before that we should create a directory to use that as a mount point.
[root@node1 ~]# mkdir /nfsmount
Mount the directory temporarily
#mount 192.168.43.226:/nfshare /nfsmount
Mount permanently by editing /etc/fstab file and make entry
192.168.43.226:/nfshare/ /nfsmount nfs rw,sync 0 0
save and exit from the file.
unmount the directory because we mounted temporarily before restart and after restart issue mount to check whether the shared directory is listing or not. If its not listing then there is an issue with entry in /etc/fstab file.
Restart the client and check using mount command
[root@node1 ~]# mount | grep /nfsmount
192.168.43.226:/nfshare/ on /nfsmount type nfs (rw,sync,vers=4,addr=192.168.43.226,clientaddr=192.168.43.67)