Step-by-Step Guide to Create and Attach an NFS Mount Point to a New Server


Prerequisites:

  1. NFS Server: A server with NFS (Network File System) installed and configured to export the directory.
  2. Client Server: The server where the NFS mount point will be attached.
  3. Network Connectivity: Ensure both servers can communicate over the network.

Steps on the Source NFS Server where the storage is present

1. Install NFS Utilities


sudo yum install -y nfs-utils # For Red Hat-based systems sudo apt-get install -y nfs-kernel-server # For Debian-based systems

2. Create the Directory to Export


sudo mkdir -p /mnt/shared

3. Set Permissions for the Directory


sudo chmod 777 /mnt/shared

4. Edit the Exports File

Add the directory to /etc/exports with the appropriate permissions:


sudo nano /etc/exports

Add the following line to export the directory:


/mnt/shared *(rw,sync,no_root_squash)
  • rw: Read-write access.
  • sync: Synchronize changes immediately.
  • no_root_squash: Allows root on the client to act as root on the NFS server.

5. Export the Directory

Run the following command to make the changes effective:


sudo exportfs -rav

6. Start and Enable the NFS Service


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

Steps on the Client Server

1. Install NFS Utilities


sudo yum install -y nfs-utils # For Red Hat-based systems sudo apt-get install -y nfs-common # For Debian-based systems

2. Create a Mount Point


sudo mkdir -p /mnt/nfs_shared

3. Mount the NFS Share Temporarily

Use the mount command to mount the NFS share:


sudo mount -t nfs <NFS_SERVER_IP>:/mnt/shared /mnt/nfs_shared

Replace <NFS_SERVER_IP> with the IP address of the NFS server.

4. Verify the Mount

Check if the NFS share is mounted:


df -h

You should see the NFS share listed as /mnt/nfs_shared.


Persist the Mount Across Reboots

  1. Open the fstab file:


    sudo nano /etc/fstab
  2. Add an entry for the NFS share:


    <NFS_SERVER_IP>:/mnt/shared /mnt/nfs_shared nfs defaults 0 0
  3. Save the file and exit.

  4. Test the fstab entry by unmounting and remounting all filesystems:

    sudo umount /mnt/nfs_shared sudo mount -a

Verification

  1. Test writing and reading files on the mount point:


    sudo touch /mnt/nfs_shared/test_file ls -l /mnt/nfs_shared/
  2. Ensure the file appears on both the NFS server and client.


Troubleshooting

  1. Firewall:

    • Ensure the required NFS ports are open:

      sudo firewall-cmd --add-service=nfs --permanent sudo firewall-cmd --add-service=rpc-bind --permanent sudo firewall-cmd --add-service=mountd --permanent sudo firewall-cmd --reload
  2. SELinux:

    • Allow NFS through SELinux:

      sudo setsebool -P nfs_export_all_rw 1







Please do like and subscribe to my youtube channel: https://www.youtube.com/@foalabs If you like this post please follow,share and comment