Sunday 23 February 2014

NFS Server Configuration in RHEL 6


NFS Server Configuration in RHEL 6

NFS(Network File System)



A Network File System (NFS) allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally. This enables system administrators to consolidate resources onto centralized servers on the network.

  • NFS was developed by Sun Microsystems in 1980.
  • NFS stand for Network File System.
  • NFS is used to share files and printer between Linux / Unix systems.
  • Red Hat Enterprise Linux 6 supports NFSv2, NFSv3, and NFSv4 clients.
  • By default RHEL6 use NFSv4 if the server supports it.
  • TCP 2049 is the default port number for NFS.

Benefits of NFS :-


  •  NFS allows local access to remote files.
  •  It uses standard client/server architecture for file sharing between all *nix based machines.
  •  With NFS it is not necessary that both machines run on the same OS.
  •  With the help of NFS we can configure centralized storage solutions.
  •  Users get their data irrespective of physical location.
  •  No manual refresh needed for new files.
  •  Newer version of NFS also supports acl, pseudo root mounts.
  •  Can be secured with Firewalls and Kerberos.

NFS Versions :-


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 supports only TCP.
  • 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 and no longer requires rpcbind service.

Required Services :-


Red Hat Enterprise Linux uses a combination of kernal-level support and daemon processes to provide NFS file sharing. All NFS version depends on Remote Procedure Calls (RPC) service which is controlled by rpcbind service. In earlier version of RHEL portmap service was used to map RPC program number to IP address port number combinations. This service is now replaced by rpcbind to enable IPv6 support.

nfs

service nfs start starts the NFS server and the appropriate RPC processes to service requests for shared NFS file systems.


nfslock

service nfslock start activates a mandatory service that starts the appropriate RPC processes allowing NFS clients to lock files on the server.


rpcbind

rpcbind accepts port reservations from local RPC services. These ports are then made available (or advertised) so the corresponding remote RPC services can access them. rpcbind responds to requests for RPC services and sets up connections to the requested RPC service. This is not used with NFSv4.

The following RPC processes facilitate NFS services: 


rpc.mountd

This process is used by an NFS server to process MOUNT requests from NFSv2 and NFSv3 clients. It checks that the requested NFS share is currently exported by the NFS server, and that the client is allowed to access it. If the mount request is allowed, the rpc.mountd server replies with a Success status and provides the File-Handle for this NFS share back to the NFS client.

rpc.nfsd
rpc.nfsd allows explicit NFS versions and protocols the server advertises to be defined. It works with the Linux kernel to meet the dynamic demands of NFS clients, such as providing server threads each time an NFS client connects. This process corresponds to the nfs service.

lockd
lockd is a kernel thread which runs on both clients and servers. It implements the Network Lock Manager (NLM) protocol, which allows NFSv2 and NFSv3 clients to lock files on the server. It is started automatically whenever the NFS server is run and whenever an NFS file system is mounted.

rpc.statd
This process implements the Network Status Monitor (NSM) RPC protocol, which notifies NFS clients when an NFS server is restarted without being gracefully brought down. rpc.statd is started automatically by the nfslock service, and does not require user configuration. This is not used with NFSv4.

rpc.rquotad
This process provides user quota information for remote users. rpc.rquotad is started automatically by the nfs service and does not require user configuration.

rpc.idmapd
rpc.idmapd provides NFSv4 client and server upcalls, which map between on-the-wire NFSv4 names (which are strings in the form of user@domain) and local UIDs and GIDs. For idmapd to function with NFSv4, the /etc/idmapd.conf file must be configured. This service is required for use with NFSv4, although not when all hosts share the same DNS domain name. 

NFS Services:- :-



Its a System V-lanuched service. The NFS Server package includes three facilities, included in the portmap/rpcbind and nfs-utils packages.
  • portmap/rpcbind: It maps calls made from other machines to the correct RPC service(not required with NFSv4).
  • nfs: It translates remote file sharing requests into requests on the local file system.
  • rpc.mountd: This service is responsible for mounting and unmounting of file systems.


Important Files for NFS Configurations :-


  • /etc/exports It’s a main configuration file of NFS, all exported files and directories are defined in this file at the NFS Server end.
  • /etc/fstab: To mount a NFS directory on your system across the reboots, we need to make an entry in/etc/fstab.
  • /etc/sysconfig/nfs:Configuration file of NFS to control on which port rpc and other services are listening.

NFS Server Configuration Lab :-


NFS Server Videos :-

Part 1 (Basic Concept of NFS):- 




Part 2 (Server Configuration):-



Part 3 (Client Configuration) :- 



NFS Server Configuration steps :-


Step 1:- Configure the NIC (Network Interface Card).
               Execute the following command to configure NIC.
               
                #setup 

Step 2:- Restart the Network Service by executing the following command.

               #service network restart

Step 3:- Then check your NIC Configuration with the help of following command.
            
               # Ifconfig

Step 4:- In the next step we need to install NFS packages on our NFS Server as well as on NFS Client
               machine. We can install it via “yum” (Red Hat Linux) and “apt-get” (Debian and Ubuntu) package
               installers.

              To install NFS packages using “yum” in RHEL 6 execute following command it: -

              # yum install nfs-utils nfs-utils-lib
              #yum install rpcbind (not required with NFSv4)

              To install NFS packages using “apt-get” in Debian or Ubuntu execute following command it: -

              #apt-get install nfs-utils nfs-utils-lib

Step 5:- In this step you have to verify that NFS Server packages are installed.

              To verify the “nfs-utils” package execute the following command:-

              #rpm –qa nfs-utils*

              To verify the “rpc-bind” package execute the following command:-

              #rpm –qa rpcbind*

Step 6:- In the next step, create a new directory to share with client and named it whatever you want,
              you can also share an already existing directory with NFS.

              To create a new directory executes the following command:-

              #mkdir /nfsshare

Step 7:- Now we need to make an entry in “/etc/exports” and restart the services to make our directory
              shareable in the network.

              /nfsshare 172.18.209.10(rw, sync)

In the above example, there is a directory in / partition named “nfsshare” is being shared with client IP
172.18.209.10” with read and write (rw) privilege, you can also use hostname of the client in the place
of IP in above example.

NFS Options
Some other options we can use in “/etc/exports” file for file sharing is as follows.
  • 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.
  • rw: This option allows the client server to both read and write access within the shared directory.
  • 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 file system, 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.

Step 8:- Now start the rpcbind and nfs service by using the following command.

              #service rpcbind start (not required with NFSv4)

              #service nfs start

Note: - The portmap service was used to map RPC program numbers to IP address port number
combinations in earlier versions of Red Hat Enterprise Linux. This service is now replaced by rpcbind in Red Hat Enterprise Linux 6 to enable IPv6 support.

Step 9:- To turn on the above services at boot time, execute the following command.

              #chkconfig rpcbind on (not required with NFSv4)

              #chkconfig nfs on

Step 10:- Now execute the following command to show the available shares your NFS server.

              #showmount -e

NFS Client Configuration steps :-


Step 1:- Configure the NIC (Network Interface Card).
              Execute the following command to configure NIC.

              #setup

Where eth0 is your NIC number.

Step 2:- If you’re NIC not configured, then first configure your NIC.

              To configure NIC, execute the following command: -

              #setup

              Then restart the network service: -

              #service network restart

              And then check the connectivity with NFS Server:-

              #ping 172.18.209.9

Step 3:- In the next step we need to install NFS packages on our NFS Server as well as on NFS Client
               machine. We can install it via “yum” (Red Hat Linux) and “apt-get” (Debian and Ubuntu) package
               installers.

              To install NFS packages using “yum” in RHEL 6 execute following command it: -

              # yum install nfs-utils nfs-utils-lib
              #yum install rpcbind (not required with NFSv4)

              To install NFS packages using “apt-get” in Debian or Ubuntu execute following command it: -

              #apt-get install nfs-utils nfs-utils-lib

Step 4:- In this step you have to verify that NFS Server packages are installed.

              To verify the “nfs-utils” package execute the following command:-

              #rpm –qa nfs-utils*

              To verify the “rpc-bind” package execute the following command:-

              #rpm –qa rpcbind*

Step 5:- at the NFS client end, we need to mount that directory in our server to access it locally. To
              do so, first we need to find out that share available on the remote server or NFS Server.

              Execute the following command to find out the available share on the NFS Server.

              #showmount –e 172.18.209.9

Note: - where 172.18.209.9 is the NFS Server IP address.

Step 6:- Use the following command to mount that NFS share on our client machine.

              #mount –t nfs 172.18.209:/nfsshare /mnt

The above command will mount that shared directory in “/mnt/” on the client server. You can verify it
following command.

              #mount | grep nfs

Step 7:- In the previous step we mounted the nfs shared directory on to nfs client temporarily, to
              mount an NFS directory permanently on your system across the reboots, we need to make an
              entry in “/etc/fstab“.

              Now edit the “/etc/fstab” file and add the following line to this file.

              #vim /etc/fstab

              172.18.209.9:/nfsshare /mnt nfs defaults 0 0

To remove the NFS mount:-


If you want to unmount that shared directory from your server after you are done with the file sharing,
you can simply unmount that particular directory with “umount” command. See this example below.

              #umount /mnt

You can see that the mounts were removed by then looking at the file system again.

              #df –h –F nfs

Important commands for NFS:-



Some more important commands for NFS.
  • showmount -e : Shows the available shares on your local machine.
  • showmount -e &ltserver-ip or hostname&gt: 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.


Back to RHEL 6 Tutorials