Thursday, February 19, 2015

How to configure client system for access NFS server in RHEL6 and RHEL7

Configuration OF Client system to access NFS server:

In my previous post i talk about Configuration of NFS server. and now I talk about how to configure client system to access NFS shared directory.

1. To Check the share folder, execute this command
                  #showmount -e <IP OF NFS SERVER>







2. Create a Mount Point, By creating a directory:
                  #mkdir <Directory For Mount Point>






3. Now edit /etc/fstab file:
                 #vim /etc/fstab
 and make entry for nfs shared directory and define:

<nfs server ip>:<shared directory>      mount point      nfs     defaults     0 0














save and exit.

4. Execute this command after the entry for permanent mounting:
                #mount <mont point directory>















5. Execute following command to check :
                     #df -h

6. Now, you can see the shared file or directory:
    open your mount point.
                      #cd <mount point>
                      #ls

what is NFS and How to configure nfs server in rhel7?



What is NFS?
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.

How many NFS versions?
Currently, there are four versions of NFS.
   1.     nfsv2            ( nfs version 2 )
   2.     nfsv3            ( “                 3 )
   3.     nfsv4.0         ( “        4.0 )
   4.     nfsv4.1         ( “        4.1 )

* NFS version 2 (NFSv2) is no longer supported by Red Hat.

* NFS version 3 (NFSv3) supports safe asynchronous writes and is more robust at error handling than the previous NFSv2; it also supports 64-bit file sizes and offsets, allowing clients to access more than 2 GB of file data.

* NFSv4 works through firewalls and on the Internet, no longer requires an rpcbind service, supports ACLs, and utilizes stateful operations.

* Recently Red Hat Enterprise Linux 7 adds support for NFS version 4.1 (NFSv4.1), which provides a number of performance and security enhancements, including client-side support for Parallel NFS (pNFS). 


NOTE:

Red Hat Enterprise Linux 7 supports NFSv3, NFSv4.0, and NVSv4.1 clients. NFS clients attempt to mount using NFSv4.0 by default, and fall back to NFSv3 if the mount operation is not successful. 

All versions of NFS can use Transmission Control Protocol (TCP) running over an IP network, with NFSv4 requiring it.

NFSv3 can use the User Datagram Protocol (UDP) running over an IP network to provide a stateless network connection between the client and server. 

In order for NFS to work with a default installation of Red Hat Enterprise Linux with a firewall enabled, configure IPTables with the default TCP port 2049. Without proper IPTables configuration, NFS will not function properly.


How to Configure NFS Server:

There are two ways to configure an NFS server:

   1.     Through the manually editing the NFS configuration file ( /etc/exports )

If NFS package is not installed then install it:
                                        #yum install nfs* -y

the /etc/exports file only specifies the exported directory and the hosts permitted to access it, as in the following example:

                                        #vim /etc/exports
            Write it on blank file:
/directory    system1.example.com 
 
in this example you have a directory named “directory” and you want to share it with “system1.example.com”.
Change the permission of  shared directory:
                                          #chmod 777 /directory

Same as you can share multiple file with multiple hosts.

After modified the configuration file execute this command for maintain the table of exported NFS file system:
                                          #exportfs -r

NFS requires the rpcbind service to be running. Start it with the following command:
                                       #service rpcbind restart

Restart the NFS service:
In RHEL6:

#service nfs restart


In RHEL7:
#systemctl restart nfs
 


For verify or see the NFS server's export list execute following command:
                                        #showmount –e



Same example of NFS with default settings:

Each default for every exported file system must be explicitly overridden. For example, if the rw option is not specified, then the exported file system is shared as read-only. The following is a sample line from /etc/exports which overrides two default options:

/directory    system1.example.com(rw,async) 

Like this (in blue color) you can use following default settings:

ro (Read Only):
The exported file system is read-only. Remote hosts cannot change the data shared on the file system. To allow hosts to make changes to the file system (that is, read/write), specify the rw option. 

sync :
The NFS server will not reply to requests before changes made by previous requests are written to disk. To enable asynchronous writes instead, specify the option async.

wdelay :
The NFS server will delay writing to the disk if it suspects another write request is imminent. This can improve performance as it reduces the number of times the disk must be accesses by separate write commands, thereby reducing write overhead. To disable this, specify the no_wdelay. no_wdelay is only available if the default sync option is also specified.

root_squash :
This prevents root users connected remotely (as opposed to locally) from having root privileges; instead, the NFS server will assign them the user ID nfsnobody. This effectively "squashes" the power of the remote root user to the lowest local user, preventing possible unauthorized writes on the remote server. To disable root squashing, specify no_root_squash.



    2.     By the Command Line, By the using of exportfs” command.
  For more details read the man page of “exportfs”