About NFS (Network File System) Mounts
NFS mounts work to share a directory between several servers. This has the advantage of saving disk space, as the home directory is only kept on one server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.
An NFS mount is set up between at least two servers. The machine hosting the shared network is called the server, while the ones that connect to it are called ‘clients’.
This tutorial requires 2 servers: one acting as the server and one as the client. We will set up the server machine first, followed by the client. The following IP addresses will refer to each one:
The system should be set up as root. You can access the root user by typing
Setting Up the NFS Server
Step One—Download the Required SoftwareStart off by using apt-get to install the nfs programs.
yum install nfs-utils nfs-utils-libSubsequently, run several startup scripts for the NFS server:
chkconfig nfs on service rpcbind start service nfs start
Step Two—Export the Shared Directory
The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.
Suppose we wanted to share the directory, /home.
We need to export the directory:
Add the following lines to the bottom of the file, sharing the directory with the client:
These settings accomplish several tasks:
Once you have entered in the settings for each directory, run the following command to export them:
Setting Up the NFS Client
Step One—Download the Required Software
Start off by using apt-get to install the nfs programs.
yum install nfs-utils nfs-utils-lib
Step Two—Mount the Directories
Once the programs have been downloaded to the the client server, create the directory that will contain the NFS shared files
mkdir -p /mnt/nfs/home
Then go ahead and mount it
mount 22.214.171.1249:/home /mnt/nfs/home
You can use the df -h command to check that the directory has been mounted. You will see it last on the list.
Filesystem Size Used Avail Use% Mounted on /dev/sda 20G 783M 18G 5% / 126.96.36.1999:/home 20G 785M 18G 5% /mnt/nfs/home
Additionally, use the mount command to see the entire list of mounted file systems.
Your list should look something like this:
/dev/sda on / type ext4 (rw,errors=remount-ro) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) nfsd on /proc/fs/nfsd type nfsd (rw) 188.8.131.529:/home on /mnt/nfs/home type nfs (rw,noatime,nolock,bg,nfsvers=2,intr,tcp,actimeo=1800,addr=184.108.40.2069)
Testing the NFS Mount
Once you have successfully mounted your NFS directory, you can test that it works by creating a file on the Client and checking its availability on the Server.
Create a file in the directory to try it out:
You should then be able to find the files on the Server in the /home.
You can ensure that the mount is always active by adding the directory to the fstab file on the client. This will ensure that the mount starts up after the server reboots.
220.127.116.119:/home /mnt/nfs/home nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
You can learn more about the fstab options by typing in:
After any subsequent server reboots, you can use a single command to mount directories specified in the fstab file:
You can check the mounted directories with the two earlier commands:
Removing the NFS Mount
Should you decide to remove a directory, you can unmount it using the umount command:
cd sudo umount /directory name
You can see that the mounts were removed by then looking at the filesystem again.
You should find your selected mounted directory gone.
Source Digital Ocean.