Install NFS – Performance Tuning

Here’s a step-by-step guide to installing and optimizing an NFS (Network File System) server on Ubuntu for optimal performance.

Contents :

  1. NFS Server Installation :
    • Installing the NFS server package and configuring shared directories.
  2. NFS Client Installation :
    • Setting up the NFS client and mounting shared directories.

* NFS Server Installation

1. Update the System and Install NFS Server.
				
					# System upgrade (optional)
user:~$ sudo apt update
user:~$ sudo apt upgrade -y

# Install nfs server
user:~$ sudo apt install -y nfs-kernel-server
				
			
2. This ensures that the NFS server is running and will automatically start when the system reboots.
				
					user:~$ sudo systemctl start nfs-server
user:~$ sudo systemctl enable nfs-server
				
			
3. Create the directory to be shared. For example, create the /data/nfs directory and set the appropriate permissions.
				
					user:~$ sudo mkdir -p /data/nfs
user:~$ sudo chown nobody:nogroup /data/nfs
user:~$ sudo chmod 755 /data/nfs
				
			
4. To configure the shared directories, edit the /etc/exports file. Then, run the exportfs command to apply the settings.
				
					# Edit exports
user:~$ sudo vi /etc/exports
/data/nfs 192.168.1.0/24(rw,sync,no_subtree_check,no_root_squash)

# Apply exports
user:~$ sudo exportfs -a
				
			
  • 192.168.1.0/24: The network range allowed to access the NFS share (you can also specify a particular host by IP).
  • rw: Read/write permissions.
  • sync: Synchronous mode (ensures data integrity).
  • async: Asynchronous mode (improves performance but poses a risk to data integrity).
  • no_subtree_check: Disables subtree checking.
  • no_root_squash: Allows the root user on the client to maintain root privileges on the server.
5. To allow access to the NFS server, configure the firewall. Here’s an example using UFW (Ubuntu Firewall). If you’re using a different firewall, make sure to adjust the settings accordingly.
				
					# UFW Setting
user:~$ sudo ufw allow from 192.168.1.0/24 to any port nfs
user:~$ sudo ufw reload

# Check status
user:~$ sudo ufw status
				
			

* NFS Client Installation

1. To mount the NFS share on all client hosts, first, install the necessary NFS client package:
				
					# System upgrade (optional)
user:~$ sudo apt update
user:~$ sudo apt upgrade -y

# Install nfs server
user:~$ sudo apt install nfs-common -y
				
			
2. Create the directory where the NFS share will be mounted. For example, you can create the /data/nfs directory (the path does not need to be the same as the server’s path)
				
					user:~$ sudo mkdir -p /data/nfs
				
			
3. Mount the NFS server’s shared directory on the client. This is a test mount, so it will be removed after a reboot.
				
					# Edit exports
user:~$ sudo mount -t nfs -o vers=4,rsize=32768,wsize=32768,hard,intr {server_IP}:/data/nfs /data/nfs
				
			
  • vers=4: Use NFS version 4.
  • rsize=32768, wsize=32768: Set the read/write buffer size (up to 32768 bytes). The buffer size can affect performance.
  • hard: Retry in case of network failure.
  • intr: Allow interrupts on the mounted file system.
4. To ensure the NFS share is automatically mounted at boot, configure the /etc/fstab file as follows.
				
					# Edit fstab
user:~$ sudo vi /etc/fstab
{server_IP}:/data/nfs /data/nfs nfs defaults,rsize=32768,wsize=32768,hard,intr,vers=4 0 0
				
			

* macOS: Connect to a Shared Folder on an Ubuntu NFS Server

1. When mounting, add resvport, rw, and noowners to the settings configured on Ubuntu.
				
					# Mount to ubuntu nfs server : mount options server_path local_path
user:~$ sudo mount -t nfs -o vers=4,rsize=32768,wsize=32768,hard,intr,resvport,rw,noowners xx.xx.xx.xx:/data/nfs ~/nfs
				
			
  • resvport : Configures the use of reserved ports for NFS communication. This is useful in environments with specific security or firewall settings.
  • rw : Mounts with read and write permissions, provided the NFS server allows write access for this client.
  • noowners : Ignores ownership information on the mounted file system. This option is used on macOS to avoid issues with file permissions and ownership.

Leave a Reply

Your email address will not be published. Required fields are marked *