nfs

Deploy

Configuring an NFS (Network File System) server to use a local disk, and multiple servers mount the same NFS share is a common way to provide shared storage on a local network.

1. Set Up the NFS Server

  • Install NFS Packages: On your NFS server, install the required NFS utilities.

    1
    2
    3
    4
    5
    6
    7
    8
    # For Debian/Ubuntu
    sudo apt update
    sudo apt install nfs-kernel-server

    # For Red Hat/CentOS/Fedora:
    sudo dnf install nfs-utils
    sudo systemctl enable --now nfs-server
    sudo systemctl enable --now rpcbind
  • Create a Shared Directory: Make a directory on a local disk to share.

    1
    2
    3
    sudo mkdir -p /nfs_share
    sudo chown nobody:nobody /nfs_share # check nobody group by 'id nobody'
    sudo chmod 777 /nfs_share
  • Export the Directory: Edit /etc/exports to define what and how is shared. Here’s how to share with all clients in your local network:

    1
    /nfs_share 192.168.1.0/24(rw,sync,no_subtree_check)

    Adjust the subnet to match your network.

  • Apply Export Changes & Restart NFS:

    1
    2
    sudo exportfs -ra
    sudo systemctl restart nfs-kernel-server # or systemctl restart nfs-server

2. Configure NFS Clients

On every client server that needs to mount the NFS share:

  • Install NFS Client Utilities:

    1
    2
    3
    4
    5
    6
    # For Debian/Ubuntu
    sudo apt update
    sudo apt install nfs-common

    # For Red Hat/CentOS/Fedora:
    sudo yum install nfs-utils
  • Mount the NFS Share:

    1
    2
    sudo mkdir -p /mnt/nfs_share
    sudo mount -t nfs <server_ip>:/nfs_share /mnt/nfs_share

    Replace <server_ip> with the IP address of your NFS server. Now, any server with an IP in that subnet can mount /nfs_share.

  • Optional: Persist Mount Across Reboots
    Edit /etc/fstab on each client:

    1
    <server_ip>:/nfs_share /mnt/nfs_share nfs defaults 0 0