Skip to content

Instantly share code, notes, and snippets.

@bzon
Last active August 13, 2017 11:36
Show Gist options
  • Save bzon/ebe9d0cf0d6bf1265c838ceade355a89 to your computer and use it in GitHub Desktop.
Save bzon/ebe9d0cf0d6bf1265c838ceade355a89 to your computer and use it in GitHub Desktop.
NFS Storage Guide

Only proven to work on CentOS and Rhel servers.

  1. Attach a storage device in the server. In this scenario, it's /dev/sdb. lsblk

    DEVICE_NAME="/dev/sdb"
    NFS_DIR="/nfs-dir"
    FS_TYPE="xfs"
    #FS_TYPE="ext4" #I recommend for AWS EBS
  2. Format the storage device. In this scenario, it's xfs. mkfs.$FS_TYPE $DEVICE_NAME .

  3. Create the directory to mount and mount the formatted storage device.

    mkdir $NFS_DIR
    mount $DEVICE_NAME $NFS_DIR
  4. Add an entry to /etc/fstab to persist the storage device mount configuration.

    • Get the UUID of the storage device .

      blkid | grep $DEVICE_NAME
      /dev/sdb: UUID="e5eac1a0-4ea9-48ff-801a-063c3ef5d041" TYPE="xfs"
    • Modify /etc/fstab .

      echo "UUID=e5eac1a0-4ea9-48ff-801a-063c3ef5d041 $NFS_DIR $FS_TYPE defaults,nofail 1 2" >> /etc/fstab
    • Validate mount config and ensure there are no errors mount -a

  5. Prepare the exports configuration file .

    echo "$NFS_DIR *(rw,root_squash)" >> /etc/exports.d/nfs-dir.exports
  6. Update nfs exports configuration .

    exports -a
    exports -v
  7. Ensure that the new NFS export directory has the right permission

    chown nfsnobody:nfsnobody $NFS_DIR
    chmod 777 $NFS_DIR
  8. Ensure that SELinux allows writing to the exported directory .

    setsebool -P virt_use_nfs 1
    setsebool -P virt_sandbox_use_nfs 1
  9. Ensure that the NFS server allows server traffic .

    # for NFSv4 and NFSv3
    iptables -I INPUT 1 -p tcp --dport 2049 -j ACCEPT
    # for NFSv3 only
    iptables -I INPUT 1 -p tcp --dport 20048 -j ACCEPT
    iptables -I INPUT 1 -p tcp --dport 111 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment