Skip to content

Instantly share code, notes, and snippets.

@voxx
Last active August 4, 2022 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voxx/84e9a78d47cc093aab99a42f352d4fbd to your computer and use it in GitHub Desktop.
Save voxx/84e9a78d47cc093aab99a42f352d4fbd to your computer and use it in GitHub Desktop.
RHEL7 NFS Server and Client Setup for Load Balanced Magento 2.2 app

INSTALL NFS SERVER COMPONENTS

$ sudo yum install nfs-utils

START SERVER DAEMONS

$ sudo systemctl enable rpcbind
$ sudo 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.

CONFIGURE NFS EXPORTS TO SHARE WITH MULTIPLE NODES

  • Replace [example.tld], [192.168.xx.xxx], [UID], and [GID] for each entry.
  • Ensure UID and GID match on NFS server and client!
$ sudo nano /etc/exports

And Add

/var/www/html/vhosts/[example.tld]/wwwroot/pub          [192.168.xx.xxx](rw,insecure,nohide,sync,anonuid=[UID],anongid=[GID],no_subtree_check)        [192.168.xx.xxx](rw,insecure,nohide,sync,anonuid=[UID],anongid=[GID],no_subtree_check)
/var/www/html/vhosts/[example.tld]/wwwroot/var          [192.168.xx.xxx](rw,insecure,nohide,sync,anonuid=[UID],anongid=[GID],no_subtree_check)        [192.168.xx.xxx](rw,insecure,nohide,sync,anonuid=[UID],anongid=[GID],no_subtree_check)
/var/www/html/vhosts/[example.tld]/wwwroot/generated          [192.168.xx.xxx](rw,insecure,nohide,sync,anonuid=[UID],anongid=[GID],no_subtree_check)        [192.168.xx.xxx](rw,insecure,nohide,sync,anonuid=[UID],anongid=[GID],no_subtree_check)

RESTART DAEMON TO LOAD NEW EXPORT CONFIGURATION

$ sudo systemctl restart nfs-server

TEST EXPORTS OUTPUT

$ sudo exportfs
/var/www/html/vhosts/[example.tld]/wwwroot/pub [192.168.xx.xxx]
/var/www/html/vhosts/[example.tld]/wwwroot/var [192.168.xx.xxx]
/var/www/html/vhosts/[example.tld]/wwwroot/generated [192.168.xx.xxx]

REBOOT SERVER TO ENSURE SERVICES START AUTOMATICALLY FOR FUTURE MAINTENANCE

$ sudo reboot
Connection to [hostname.example.tld] closed by remote host.
Connection to [hostname.example.tld] closed.

VERIFY SERVICES AND EXPORTS AGAIN

$ sudo systemctl status nfs-server
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
  Drop-In: /run/systemd/generator/nfs-server.service.d
           └─order-with-mounts.conf
   Active: active (exited) since Fri 2018-07-13 18:26:26 PDT; 2min 56s ago
  Process: 1280 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
 Main PID: 1280 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

Jul 13 18:26:25 [hostname.example.tld] systemd[1]: Starting NFS server and services...
Jul 13 18:26:26 [hostname.example.tld] systemd[1]: Started NFS server and services.
$ sudo systemctl status rpcbind
● rpcbind.service - RPC bind service
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-07-13 18:26:23 PDT; 3min 56s ago
 Main PID: 732 (rpcbind)
   CGroup: /system.slice/rpcbind.service
           └─732 /sbin/rpcbind -w

Jul 13 18:26:23 [hostname.example.tld] systemd[1]: Starting RPC bind service...
Jul 13 18:26:23 [hostname.example.tld] systemd[1]: Started RPC bind service.
$ sudo exportfs
/var/www/html/vhosts/[example.tld]/wwwroot/pub [192.168.xx.xxx]
/var/www/html/vhosts/[example.tld]/wwwroot/var [192.168.xx.xxx]
/var/www/html/vhosts/[example.tld]/wwwroot/generated [192.168.xx.xxx]

INSTALL NFS CLIENT COMPONENTS ON EACH CLIENT NODE

$ sudo yum install nfs-utils

CONFIGURE AUTOMATIC NFS MOUNTS FROM NFS-SERVER VIA FSTAB

  • Replace [example.tld] and [192.168.xx.xxx] for each entry.
$ sudo nano /etc/fstab

Append to bottom of file:

...
[192.168.xx.xxx]:/var/www/html/vhosts/[example.tld]/wwwroot/pub            /var/www/html/vhosts/[example.tld]/wwwroot/pub           nfs     auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800,_netdev 0 0
[192.168.xx.xxx]:/var/www/html/vhosts/[example.tld]/wwwroot/var            /var/www/html/vhosts/[example.tld]/wwwroot/var           nfs     auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800,_netdev 0 0
[192.168.xx.xxx]:/var/www/html/vhosts/[example.tld]/wwwroot/generated           /var/www/html/vhosts/[example.tld]/wwwroot/generated           nfs     auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800,_netdev 0 0

TEST MOUNTS

  • It will throw an error if there is a problem
$ sudo mount -a

REBOOT SERVER TO ENSURE MOUNTS ARE ESTABLISHED PROPERLY ON BOOT

$ sudo reboot
Connection to [hostname.example.tld] closed by remote host.
Connection to [hostname.example.tld] closed.

VERIFY MOUNTS AFTER REBOOT ON EACH CLIENT

$ df -h
Filesystem                                                                Size  Used Avail Use% Mounted on
...
tmpfs                                                                     782M     0  782M   0% /run/user/1001
192.168.xx.xxx:/var/www/html/vhosts/[example.tld]/wwwroot/pub               94G  8.1G   86G   9% /var/www/html/vhosts/[example.tld]/wwwroot/pub
192.168.xx.xxx:/var/www/html/vhosts/[example.tld]/wwwroot/var               94G  8.1G   86G   9% /var/www/html/vhosts/[example.tld]/wwwroot/var
192.168.xx.xxx:/var/www/html/vhosts/[example.tld]/wwwroot/generated               100M  8.1G   86G   0% /var/www/html/vhosts/[example.tld]/wwwroot/generated

FIN! <3

@voxx
Copy link
Author

voxx commented Jul 21, 2018

Check NFS Client Statistics

$ nfsstat -rc
Client rpc stats:
calls      retrans    authrefrsh
10668      0          10668

**** The goal is to have 0 retransmisions.

Check NFS Server Statistics

$ nfsstat -rs
Client rpc stats:
calls      retrans    authrefrsh
10668      0          10668

**** The goal is to have 0 bad calls from the clients.

Update Server Thread Count

Generally the default NFS Server Thread Count is 8. We can increase that and should especially when it is highly utilized.
Set in the /etc/sysconfig/nfs configuration file.

...
RPCNFSDCOUNT = 16

RHEL8 - Set in the /etc/nfs.conf configuration file using new nfsconf tool.

$ sudo nfsconf --set nfsd threads 16

@voxx
Copy link
Author

voxx commented Sep 18, 2018

REEXPORT NFS Directories

$ sudo exportfs -ra

**** Also take note of the options we're using, -ra:
-a

Export or unexport all directories.

-r

Reexport all directories, synchronize (removes deleted, adds new)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment