Configuring an NFS server and NFS client in CentOS / RHEL 7

Configuring an NFS server and NFS client in CentOS / RHEL 7

NFS

NFS allows a linux server to share directories with other UNIX clients over network. NFS server exports a directory and NFS client mounts this directory.


Configuring NFS server

1. Install the required nfs packages  :



[root@kubemaster ~]# rpm -qa | grep nfs-utils
[root@kubemaster ~]# yum install nfs-utils rpcbind -y
Loaded plugins: fastestmirror
base                                                                                                     | 3.6 kB  00:00:00
extras         


2. Enable the services at boot time:

[root@kubemaster ~]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@kubemaster ~]# systemctl enable rpcbind
[root@kubemaster ~]# systemctl start rpcbind
[root@kubemaster ~]# systemctl start nfs-server


3. Start the NFS services:

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

[root@kubemaster ~]#
4. Check the status of NFS service:

[root@kubemaster ~]# systemctl status nfs
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
   Active: active (exited) since Wed 2019-11-20 21:39:11 IST; 21s ago
  Process: 1925 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
  Process: 1908 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 1906 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 1908 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

Nov 20 21:39:11 kubemaster systemd[1]: Starting NFS server and services...
Nov 20 21:39:11 kubemaster systemd[1]: Started NFS server and services.

5. Create a shared directory:

[root@kubemaster ~]# mkdir /nfstest


6. Export the directory. The format of the /etc/exports file is :

dir client1 (options) [client2(options)...]
Client options include (defaults are listed first) :
ro / rw :
a) ro : allow clients read only access to the share.
b) rw : allow clients read write access to the share.
sync / async :
a) sync : NFS server replies to request only after changes made by previous request are written to disk.
b) async : specifies that the server does not have to wait.
wdelay / no_wdelay
a) wdelay : NFS server delays committing write requests when it suspects another write request is imminent.
b) no_wdelay : use this option to disable to the delay. no_wdelay option can only be enabled if default sync option is enabled.
no_all_squash / all_squash :
a) no_all_squash : does not change the mapping of remote users.
b) all_squash : to squash all remote users including root.
root_squash / no_root_squash :
a) root_squash : prevent root users connected remotely from having root access. Effectively squashing remote root privileges.
b) no_root_squash : disable root squashing.

Example :

[root@kubemaster ~]# vi /etc/exports
[root@kubemaster ~]# cat /etc/exports
/nfstest *(rw)
[root@kubemaster ~]#

7. Exporting the share :

[root@kubemaster ~]# exportfs -r
[root@kubemaster ~]# exportfs -a

8. Restart the NFS service:

# systemctl restart nfs-server


Configuring NFS client


1. Install the required nfs packages if not already installed on the server :

[root@kubenode1 ~]# rpm -qa | grep nfs-utils
[root@kubenode1 ~]# yum install nfs-utils -y
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.praction.in
 * extras: mirrors.praction.in
 * updates: mirrors.praction.in


2. Use the mount command to mount exported file systems. Syntax for the command:

 mount -t nfs -o options host:/remote/export /local/directory


[root@kubenode1 ~]# mount -t nfs -o ro,nosuid 192.168.1.200:/nfstest /nfstestclient

for Read write mount:
[root@kubenode1 ~]# mount -t nfs -o rw 192.168.1.200:/nfstest /nfstestclient

[root@kubenode1 ~]# df -h /nfstestclient
Filesystem              Size  Used Avail Use% Mounted on
192.168.1.200:/nfstest  6.2G  3.8G  2.5G  61% /nfstestclient

Test:


On server Create files inside the share :

[root@kubemaster ~]# touch a b c d
[root@kubemaster ~]# mv a b c d /nfstest/

On Client Check:

[root@kubenode1 ~]# ls -latr /nfstestclient
total 0
dr-xr-xr-x. 18 root root 265 Nov 20 21:41 ..
-rw-r--r--   1 root root   0 Nov 20 21:43 b
-rw-r--r--   1 root root   0 Nov 20 21:43 a
-rw-r--r--   1 root root   0 Nov 20 21:43 d
-rw-r--r--   1 root root   0 Nov 20 21:43 c
drwxr-xr-x   2 root root  42 Nov 20 21:44 .
[root@kubenode1 ~]#


0 Comments