Monday, March 30

NFS Configuration on Linux RHEL/CentOS 7


                                                         NFS (NETWORK FILE SYSTEM)

       

          
   NFS (Network File System) is used to sharing the files and folders between linux to unix and unix to linux machines,NFS was  developed by Sun Mycro Systems in the year 1984.


                               

                 NFS Configuration on Linux RHEL/CentOS 6


 
Features: 

        
 1. Every one can access same data.

      2. Reduce Storage Cost and Easy to use.

      3. Centralized Management of Files.

      4. Secured with Firewalls and Kerberos.


NFS Configuration : 


  •          NFS Port Number      :    2049
  •          Service Name            :    nfs-server
  •          Packages                  :    nfs-utils & nfs-utils-lib
  •          /etc/exports               :  It is main Configuration file of NFS, define all exported files and    folders   in this path. 
  •          /etc/sysconfig/nfs     :  It is also Configuration file of NFS to controle on which port rpc and other services are listening.

To setup NFS Server, we have at least two Linux Machines.In this article we will be using two machines, one is NFS Server and  another one is NFS Client
     
          NFS Server    :    192.168.0.99

          NFS Client      :   192.168.0.20


        Server Side Configuration(192.168.0.99)

 
Configure Server machine (192.168.0.99) using below steps

Step 1:  Install NFS Packages & start services

Install NFS Packages using yum command

 
   [root@bsrtech ~]# yum install  nfs-utils nfs-utils-lib -y

Enable  nfs service:

  
 [root@bsrtech ~]# systemctl enable rpcbind

  [root@bsrtech ~]# systemctl enable nfs-server

  [root@bsrtech ~]# systemctl enable nfs-lock

  [root@bsrtech ~]# systemctl enable nfs-idmap

Start  nfs service:

  [root@bsrtech ~]# systemctl start rpcbind

  [root@bsrtech ~]# systemctl start nfs-server

  [root@bsrtech ~]# systemctl start nfs-lock

  [root@bsrtech ~]# systemctl start nfs-idmap

Step 2 : Configure Shared Folders

      
Create Shared Directory name is “project1” , and give permissions to that directory
 
    [root@bsrtech ~]# mkdir /project1

    [root@bsrtech ~]# chmod 777 /project1



Open NFS configuration file and configure shared options

     [root@bsrtech ~]# vim /etc/exports

     
syntax : <share directory>  <clients range> <permissions>
    

    
/project1  192.168.0.20(rw,sync,no_root_squash,no_all_squash)

Where

1. /project1 – shared Directory
2. 192.168.0.20 – IP Address  of client
3. rw – Writable permission to shared folder
 Note:  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.
4.sync – Synchronize shared directory
5.no_root_squash – Enable root privilege
6.no_all_squash - Enable user’s authority


Change permissons of /project1 folder for read only options

 
[root@bsrtech ~]# chmod 750 /project1

 [root@bsrtech ~]# systemctl restart  nfs-server


Create some files in shared directory

 
[root@bsrtech ~]# cd /project1

 [root@bsrtech project1]# touch f1 f2 f3 f4

            
Client Side Configuration (192.168.0.20)
  
Configure Client machine (192.168.0.20) using below steps
 Step 1: Install NFS Packages & start NFS service

   
 Install NFS Packages using yum command

   [root@bsrtech ~]# yum install  nfs-utils  nfs-utils-lib -y

Enable  nfs service:

  
 [root@bsrtech ~]# systemctl enable rpcbind
  [root@bsrtech ~]# systemctl enable nfs-server

  [root@bsrtech ~]# systemctl enable nfs-lock

  [root@bsrtech ~]# systemctl enable nfs-idmap

Start  nfs service:

  [root@bsrtech ~]# systemctl start rpcbind

  [root@bsrtech ~]# systemctl start nfs-server

  [root@bsrtech ~]# systemctl start nfs-lock

  [root@bsrtech ~]# systemctl start nfs-idmap

Step2 : To findout which files or directories are exported from the server 
  
  [root@nfsclient ~]# showmount -e 192.168.0.99

  
 where 192.168.0.99 is server ip address

 Step3 : Mount shared NFS Directory
 
  
  Mount Sahred NFS directory using mount command, first create folder for mount point

  
 [root@nfsclient ~]# mkdir /opt/myproject

   [root@nfsclient ~]# mount -t nfs 192.168.0.99:/project1   /opt/myproject


  
 Verify above mount point using mount command
   
[root@nfsclient ~]# mount


 
The above mount command mounted the  nfs shared directory on to nfs client on temporarily, to mount permanently write in /etc/fstab see below

  
 [root@nfsclient ~]# vim /etc/fstab

    
 192.168.0.99:/project1    /opt/myproject   nfs  defaults   0  0

step 4 : Check the shared files & folders


   
 Move to shared mounted directory    

  
 [root@nfsclient ~]# cd /opt/myproject

   [root@nfsclient  myproject]# ls


      
 f1  f2  f3  f4  

  
 (these are shared files from nfs server machine)


No comments:

Post a Comment

:: Linux - Legends ::