Network File System (NFS) protocol allow Linux client to mount remote file systems and interact with those file systems as they are mounted locally.
NFS was developed by Sun Microsystems in 1980
NFS stand for Network File System
NFS is used to share files between Linux / Unix systems
CentOS 6 supports NFSv2, NFSv3, and NFSv4 clients.
By default CentOS 6 use NFSv4 if the server supports it.
NFSv1
NFSv1 was the development stage of NFS protocol. It was used only for in house experimental purpose. When a stable version of NFS was ready, Developers decided to release it as the new version of NFS known as NFSv2.
NFSv2
NFSv2 supports only 32 bit.
NFSv2 only allowed the first 2 GB of a file to be read
NFSv2 operated only over UDP
NFSv3
NFSv3 supports 64 bit file system.
NFSv3 can handle files larger than 2 GB.
NFSv3 supports asynchronous writes on the server. asynchronous writes improve write performance.
NFSv3 supports additional file attributes in many replies, to avoid the need to re-fetch them.
NFSv3 supports READDIRPLUS operation. READDIRPLUS operation get file handles and attributes along with file names when scanning a directory.
NFSv3 supports TCP. Using TCP as a transport made NFS over a WAN more feasible.
NFSv4
NFSv4 retains all NFSv3 advantages.
NFSv4 supports ACLs.
NFSv4 uses the virtual file system to present the server's export.
NFSv4 supports Pseudo file system. Pseudo File System provide maximum flexibility. Exports Pathname on servers can be changed transparently to clients.
NFSv4 have locking operations as the part of protocol which keep track of open files and delegations.
NFSv4 works through firewalls and on the Internet.
1)NFS Network File System, is a server-client protocol used for sharing files between linux/unix to unix/linux systems. NFS enables you to mount a remote share locally. You can then directly access any of the files on that remote share.
2)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.
3)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' .
4)We will set up the server machine first .
a) Start off by using yum to install the nfs programs
]# yum install nfs-utils nfs-utils-lib rpcbind
b) Subsequently, run several startup scripts for the NFS server.
]# service nfs start
]# service rpcbind start
]# chkconfig nfs on
]# chkconfig rpcbind on
c) Export the Shared Directory.
A) 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.
B) Suppose we wanted to share the directory, /home.
C) We need to export the directory .
D) ]# vi /etc/exports
-Add the following lines to the bottom of the file, sharing the directory with the client.
/home 192.168.1.0/24 (rw,sync,no_root_squash,no_subtree_check)
-These settings accomplish several tasks:
rw: This option allows the client server to both read and write within the shared directory.
ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
sync: Sync confirms requests to the shared directory only once the changes have been committed.
no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
no_root_squash: This phrase allows root to connect to the designated directory .
d) Once you have entered in the settings for each directory, run the following command to export them .
]# exportfs -a
5)We will set up the client server .
a) Start off by using yum to install the nfs programs.
]# yum install nfs-utils nfs-utils-lib rpcbind
b) Subsequently, run several startup scripts for the NFS client .
]# service nfs start
]# service rpcbind start
]# chkconfig nfs on
]# chkconfig rpcbind on
c)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
d) Then go ahead and mount it .
]# mount Server IP :/home /mnt/nfs/home
e)You can use the df -h command to check that the directory has been mounted. You will see it last on the list.
]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda 20G 783M 18G 5% /
server IP:/home 20G 785M 18G 5% /mnt/nfs/home
f)Additionally, use the mount command to see the entire list of mounted file systems .
]# mount
/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)
server IP:/home on /mnt/nfs/home type nfs (rw,noatime,nolock,bg,nfsvers=2,intr,tcp,actimeo=1800,addr=12.34.56.789)
g)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.
]# vi /etc/fstab
server IP:/home /mnt/nfs/home nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
]# mount -a
6) Testing the NFS Mount .
a)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:
]# touch /mnt/nfs/home/example