How To Configure NFS Server With Client on RHEL/Contos 6x
Q. What is NFS?
-- NFS stands for Network File System, a file system developed by Sun Microsystems, Inc. It is a client/server system that allows users to access files across a network and treat them as if they resided in a local file directory. For example, if you were using a computer linked to a second computer via NFS, you could access files on the second computer as if they resided in a directory on the first computer.
Scenario :
192.168.100.220 ser1.domain.com (NFS Server)
192.168.100.221 ser2.domain.com (NFS Client)
Used Ports :
TCP: 111, 2049
UDP: 111, 32806
Here :
/assets and /var/www/html/domain.com/assets
These two are the directory, which are going to be share via NFS.
Step: 1. Install NFS Server ( On Server) :
# yum -y install nfs-utils rpcbind
Step: 2. Configure NFS Server :
# vi /etc/exports
# Access For All :
/assets *(rw,async)
/var/www/html/domain.com/assets *(rw,async)
OR
# Access For Particular Network :
/assets 192.168.100.0/24(rw,async)
/var/www/html/domain.com/assets 192.168.100.0/24(rw,async)
-- Save & Quit (:wq)
Important Note :
============
Step: 3. To Exexute the Changes made on /etc/exports :
# exportfs -ar
Step: 4. Restart the NFS Service :
# service rpcbind restart
# service nfs restart
# service nfslock restart
# chkconfig rpcbind on
# chkconfig nfs on
# chkconfig nfslock on
Step: 5. Install NFS on Client Machine :
# yum -y install nfs-utils rpcbind
Step: 6. Configure NFS Client :
# showmount -e NFS_Server_IP_Address
Export list for 192.168.100.220:
/assets 192.168.100.221
/var/www/html/domain.com/assets 192.168.100.221
Step: 7. Create a new Directory on your Client & Mount the NFS Export to the Directory :
# mkdir /assets
# mkdir -p /var/www/html/domain.com/assets
# mount -t nfs 192.168.100.220:/assets /assets
# mount -t nfs 192.168.100.220:/var/www/html/domain.com/assets /var/www/html/domain.com/assets
Step: 8. Restart the NFS Service :
# service rpcbind restart
# service nfs restart
# service nfslock restart
# chkconfig rpcbind on
# chkconfig nfs on
# chkconfig nfslock on
Step: 9. Finally, Mount NFS Directory Permanently on your System across the Reboots :
# vi /etc/fstab
192.168.100.220:/assets /assets defaults 0 0
192.168.100.220:/var/www/html/domain.com/assets /var/www/html/domain.com/assets nfs defaults 0 0
-- Save & Quit (:wq)
Step: 10. After any subsequent Server reboots, You can use a Single Command to mount Directories specified in the fstab file :
# mount -a
Step: 11. Now You can check the Mounted Directories :
# df -h -F nfs
Important commands for NFS :
- showmount -e : Shows the available shares on your local machine
- showmount -e <server-ip or hostname>: Lists the available shares at the remote server
- showmount -d : Lists all the sub directories
- exportfs -v : Displays a list of shares files and options on a server
- exportfs -a : Exports all shares listed in /etc/exports, or given name
- exportfs -u : Unexports all shares listed in /etc/exports, or given name
- exportfs -r : Refresh the server’s list after modifying /etc/exports