Skip to main content

NFS mount on Centos/RHEL 6.6

Setup and Configure NFS Mounts on Linux Server

To setup we will need 2 servers. Master and Slave.
nfsmaster.server.com     192.168.33.135     # Hosts the NFS shared drive.
nfsslave.server.com     192.168.33.132  # Client to use the master shared drive.
NOTE: You can add the hostnames in the /etc/hosts file and user the hostnames in the configuration rather than IP addresses.
Steps to setup NFS.
  1. Install NFS and rpcbind on master and slave servers. nfs-utils nfs-utils-lib rpcbind
  2. Configure NFS on master server.
  3. Configure mount points on slave server.
  4. Mount NFS on slave server.

Installing NFS Server and NFS Slave

We need to install NFS packages using yum.
[root@nfsmaster ~]# yum install nfs-utils nfs-utils-lib
[root@nfsmaster ~]# yum install rpcbind 
Make sure to install rpcbind and start it first. Now start the services on both machines.
[root@nfsmaster ~]# /etc/init.d/rpcbind start
NOTE: Start rpcbind first else you will get the below error.
[root@nfsmaster /]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
[FAILED]
Starting NFS daemon: [FAILED]
After starting rpcbind check the rpcinfo. should look similar as below.
[root@nfsmaster /]# rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  rpcbindper
    100000    3   tcp    111  rpcbindper
    100000    2   tcp    111  rpcbindper
    100000    4   udp    111  rpcbindper
    100000    3   udp    111  rpcbindper
    100000    2   udp    111  rpcbindper
    100024    1   udp  33472  status
    100024    1   tcp  40795  status
Now we start the NFS service.
[root@nfsmaster ~]# service nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Setting services to start on reboot.
[root@nfsmaster ~]# chkconfig rpcbind on
[root@nfsmaster ~]# chkconfig nfs on
NOTE : Starting services on both the machines

Setting Up the NFS Server

First we will be configuring the NFS server.

Configure Export directory

For sharing a directory with NFS, we need to make an entry in /etc/exports configuration file. Lets create a directory to be shared across the network. We are creating a common shared directory for all the login users.
[root@nfsmaster ~]# mkdir /export/home
Now we need to make an entry in /etc/exports and restart the services to make our directory shared in the network.
[root@nfsmaster ~]# vi /etc/exports
# directory  Slave-IP  (permissions on the directory)
/export/home 192.168.33.132(rw,sync,no_root_squash)
/export/home 192.168.33.135(rw,sync,no_root_squash)
/export/home 192.168.33.131(rw,sync,no_root_squash)
In the above example, there is a directory as /export/home.
This is shared with Slaves with IP 192.168.33.132 with read and write (rw) privilege, you can also use hostname of the Slave in the place of IP.
In the above /etc/exports we have 3 clients which are allowed to access the shared mount.
1. 192.168.33.132 - nfsslave     (slave)
2. 192.168.33.135 - nfsmaster     (master)
3. 192.168.33.131 - nfsslave2     (another slave)
Now restart NFS service.
[root@nfsmaster home]# service nfs restart
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS quotas:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]
Shutting down RPC idmapd:                                  [  OK  ]
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

NFS Options

Some other options we can use in /etc/exports file for file sharing is as follows.
  1. ro: With the help of this option we can provide read only access to the shared files i.e Slave will only be able to read.
  2. rw: This option allows the Slave server to both read and write access within the shared directory.
  3. sync: Sync confirms requests to the shared directory only once the changes have been committed.
  4. 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.
  5. no_root_squash: This phrase allows root to connect to the designated directory.
For more options with /etc/exports, you are recommended to read the man pages for export.

Configuring and Setup of NFS Slave.

After the server is configured we need to mount the shared drive on the slave.
  1. Create a directory in slave to mount the shared drive.
  2. Mount the drive to the newly created mount point.
  3. update /etc/fstab to make changes permanent.
First lets check the mount points on the server.
[root@nfsslave ~]# showmount -e 192.168.33.135

Export list for 192.168.33.135:
/export/home 192.168.33.132,192.168.33.135,192.168.33.131
Command above shows that the directory /export/home is available at 192.168.33.135 and ready to be shared with 132,131 and 135 servers.

Create Mount Point and Mount Shared NFS Directory.

Creating a new mount point.
[root@nfsslave ~]# mkdir -p /nfs_client_mount
To mount that shared NFS directory we can use following mount command.
[root@nfsslave ~]# mount -t nfs 192.168.33.135:/export/home /nfs_client_mount
The above command will mount that shared directory in /nfs_client_mount on the slave server.
Update /etc/fstab file to automount on reboot.
[root@nfsslave ~]# vi /etc/fstab
Add the following new line as shown below.
192.168.33.135:/export/home /nfs_client_mount  nfs defaults 0 0
Checking mount points.
[root@nfsslave home]# mount -a
[root@nfsslave home]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.33.135:/export/home on /nfs_client_mount type nfs (rw,vers=4,addr=192.168.33.135,clientaddr=192.168.33.132)
Testing by creating a TEST directory on slave which will be created in /export/home on master, which hosts the shared NFS drive.
[root@nfsslave ~]# df -h -F nfs
Filesystem            Size  Used Avail Use% Mounted on 
192.168.33.135:/export/home
                       18G  5.1G   12G  31% /nfs_client_mount
[root@nfsslave ~]#
[root@nfsslave ~]# cd /nfs_client_mount/
[root@nfsslave home]# mkdir TEST
Check directory creation on Master.
[root@nfsmaster ~]# cd /export/home/
[root@nfsmaster home]# ls
TEST
We can see the newly created directory. We are good. :)

Removing the NFS Mount

If we need to unmount the NFS directory on slave.
[root@nfsslave ~]# umount /nfs_client_mount
Check if the NFS is unmounted.
[root@nfsslave ~]# df -h -F nfs
df: no file systems processed
No NFS available.

Important commands for NFS

Some more important commands for NFS.
showmount -e : Shows the available shares on your local machine
showmount -e : 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
http://www.tecmint.com/how-to-setup-nfs-server-in-linux/
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/nfs-serverconfig.html
http://maazanjum.com/2014/02/17/starting-nfs-quotas-cannot-register-service-rpc-unable-to-receive-errno-connection-refused/

Comments

Popular posts from this blog

Zabbix History Table Clean Up

Zabbix history table gets really big, and if you are in a situation where you want to clean it up. Then we can do so, using the below steps. Stop zabbix server. Take table backup - just in case. Create a temporary table. Update the temporary table with data required, upto a specific date using epoch . Move old table to a different table name. Move updated (new temporary) table to original table which needs to be cleaned-up. Drop the old table. (Optional) Restart Zabbix Since this is not offical procedure, but it has worked for me so use it at your own risk. Here is another post which will help is reducing the size of history tables - http://zabbixzone.com/zabbix/history-and-trends/ Zabbix Version : Zabbix v2.4 Make sure MySql 5.1 is set with InnoDB as innodb_file_per_table=ON Step 1 Stop the Zabbix server sudo service zabbix-server stop Script. echo "------------------------------------------" echo " 1. Stopping Zabbix Server ...

Installing Zabbix Version 2.4 Offline (Zabbix Server without Internet).

There might be situations where you have a remote/zabbix server which does not have internet connectivity, due to security or other reasons. So we create a custom repo on the remote/zabbix server so that we can install zabbix using rpms Here is how we are planning to do this. Download all the dependency rpms on a machine which has internet connection, using yum-downloadonly or repotrack . Transfer all the rpms to the remote server. Create a repo on the remote server. Update yum configuration. Install. NOTE: This method can be used to install any application, but here we have used zabbix as we had this requirement for a zabbix server. Download dependent rpms . On a machine which has internet connection install the package below. And download all the rpms . Make sure the system are similar (not required to be identical - At-least the OS should be of same version) mkdir /zabbix_rpms yum install yum-downloadonly Downloading all the rpms to location /zabbix_rpms/ ,...

Access Filter in SSSD `ldap_access_filter` [SSSD Access denied / Permission denied ]

Access Filter Setup with SSSD ldap_access_filter (string) If using access_provider = ldap , this option is mandatory. It specifies an LDAP search filter criteria that must be met for the user to be granted access on this host. If access_provider = ldap and this option is not set, it will result in all users being denied access. Use access_provider = allow to change this default behaviour. Example: access_provider = ldap ldap_access_filter = memberOf=cn=allowed_user_groups,ou=Groups,dc=example,dc=com Prerequisites yum install sssd Single LDAP Group Under domain/default in /etc/sssd/sssd.conf add: access_provider = ldap ldap_access_filter = memberOf=cn=Group Name,ou=Groups,dc=example,dc=com Multiple LDAP Groups Under domain/default in /etc/sssd/sssd.conf add: access_provider = ldap ldap_access_filter = (|(memberOf=cn=System Adminstrators,ou=Groups,dc=example,dc=com)(memberOf=cn=Database Users,ou=Groups,dc=example,dc=com)) ldap_access_filter accepts standa...