Summary

  Subject:

Create a NFS Server

  Updated:

2023-01-21

  Author:

Tim Hammond ([email protected])

Derek Pasnick ([email protected])

  Operating Systems:

Rocky 8

  Background:

This guide was written to setup a dedicated NFS server. The documenation assumens that LVM was already setup.

 

Table of Contents

NFS Notes

Miscellaneous

  • Ensure that the NFS volume is exported using NFS over TCP
  • Make sure that the NAS server exports a particular share as either NFS 3
  • On each ESXi host, configure a VMkernel Network port for NFS traffic.
  • Use only ASCII characters, or unpredictable failures might occur.

VMware NFS Locking

  • NFS 3 locking on ESXi does not use the Network Lock Manager (NLM) protocol.
  • VMware provides its own locking protocol.
  • NFS 3 locks are implemented by creating lock files on the NFS server.
  • Lock files are named .lck-file_id.

VMware Best Practices for NAS Storage

VM Config

It is assumed that the server has already been built and the underlying storage has already been setup.

If you would like to use LVM for your storage, please check out this article:
Rocky - Linux LVM Concepts and Examples for a NFS Server

Install

Install Software

sudo dnf -y install nfs-utils lsof

Add Firewall Rules

sudo firewall-cmd --permanent --zone=public --add-service=nfs sudo firewall-cmd --permanent --zone=public --add-service=mountd sudo firewall-cmd --permanent --zone=public --add-service=rpc-bind sudo firewall-cmd --reload sudo firewall-cmd --list-all

Restart Services

sudo systemctl enable nfs-server sudo systemctl enable rpcbind sudo systemctl start nfs-server sudo systemctl start rpcbind

Folder Permissions

The folders should have already been created during LVM setup. Make sure the machine is already joined to the domain. Create share for NFS file server - using Active Directory groups.

sudo chmod -R 755 /mnt/nfs sudo chown -R syseng /mnt/nfs sudo chgrp -R nfs-admins /mnt/nfs

Crontab - Script to set Permissions

Note to future self, apply the changes above in the "Set Folder Permissions - Manually" section. The crontab job documented below is to help ensure that futre files are getting the appropriate permmisions.

Create a script to change the permissions.

sudo tee -a /usr/local/bin/permissionsSet.sh >/dev/null <<EOF #!/bin/bash # This crontab job is set to run every hour at XX.00. find /mnt/nfs -type d -exec chmod 755 {} \; find /mnt/nfs -type f -exec chmod 644 {} \; find /mnt/nfs -type f -exec chown syseng {} \; find /mnt/nfs -type f -exec chgrp nfs-admins {} \; EOF

Make the script exectuable.

sudo chmod +x /usr/local/bin/permissionsSet.sh

Verify that everything looks right.

sudo cat /usr/local/bin/permissionsSet.sh

Crontab - Create Job

To add new crontab jobs, use the command below. This will use the default editor. In most cases, the default editor is vi/vim. You cannot use vi/vim on its own. You have to use the crontab command.

By using "sudo" in the command, this will add the jobs to the root accounts cronjob. As a result, using "sudo" in the actual commands is not necessary. After the text editor is open, paste the following line.

The following command will execute a script that will reapply the appropriate permissions every hour at XX:00. If you want to change the script to run at XX:30, but still every hour, simply use 30 * * * *. This is based on setting a time, not frequency.

crontab -e
0 * * * * /usr/local/bin/permissionsSet.sh

sudo su -c '(crontab -l; echo "0 * * * * /usr/local/bin/permissionsSet.sh";) | crontab -'

Verify the crontab job is scheduled for root.

sudo crontab -l -u root

If you need to make any changes, use the following cmd.

sudo crontab -e -u root

NFS Exports Setup

Create and configure shares. Use the IP address of the NFS client. To open it up to any host, use *. There should not be a space after the IP address nor the (switches).

sudo tee -a /etc/exports >/dev/null <<EOF # Exports /mnt/nfs 192.168.30.0/24(rw,async,no_subtree_check) /mnt/nfs 192.168.31.0/24(rw,async,no_subtree_check) EOF

Proceeding Commands

Export switches - commands to publish new shares. You do not need to restart NFS to publish new shares.

You do not need to restart NFS to publish new shares.

  • exportfs -v : Displays a list of shares files and export options on a server
  • exportfs -a : Exports all directories listed in /etc/exports
  • exportfs -u : Unexport one or more directories
  • exportfs -r : Reexport all directories after modifying /etc/exports
sudo exportfs -arv

Restart NFS Server service; you do not need to restart NFS to publish new shares

sudo systemctl restart nfs-server

Optional: Additional configuration files

  • /etc/exports - main config file; controls which file systems are exported to remote hosts and specifies options
  • /etc/fstab - controls which file systems are mounted during system startup (including NFS directories)
  • /etc/sysconfig/nfs - controls which ports RPC services run on
  • /etc/hosts.allow - TCP wrapper; controlles the access to the NFS server
  • /etc/hosts.deny - TCP wrapper; controlles the access to the NFS server

NFS Client Setup

For more information on setting up Linux or Windows hosts to access NFS exports, refer to the following: Join a Linux machine to Windows Active Directory