Try   HackMD

What is NFS

NFS stands for Network File System. It's a distributed file system that allows user on a client computer to access shared files and directories among networked computers.

image

Source from: IBM Developer, The NFS architecture

When would use NFS

  1. File Sharing in a Network:
    NFS is widely used when you need to share files and directories among multiple computers in a network.
  2. Centralized Storage:
    NFS is useful when you want to centralize storage on a dedicated file server.

How to setup NFS on Ubuntu Servers

Pre-required

  • 2 instances with ubuntu 22.04 in the same subnet.
  • check the 2 instances could connect to each other.

NFS server (one of the instances)

  1. create a shared directory and set permission.
$mkdir /shared
$chown nobody.nogroup -R /shared
$chmod 777 -R /shared
  1. install NFS package.
$apt update
$apt install nfs-kernel-server -y
  1. config the /etc/exports to use a new shared directory and indicate the subnet.
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/shared 192.168.56.0/24(rw,sync,no_root_squash,no_subtree_check)

  1. export the directories specified in the /etc/exports
$exportfs -a

NFS client

  1. create a shared directory and set the permission of a directory
$mkdir /shared
$chown nobody.nogroup -R /shared
$chmod 777 -R /shared
  1. install NFS package.
$apt update
$apt install nfs-common -y
  1. edit the /etc/fstab to mount the shared directory
<master node private ip>:/shared  /shared nfs defaults   0 0
  1. mount the shared directory
$mount -a

Testing

  1. create a file in /shared on server 1.
$touch /shared/test
  1. check the file in /shared on server 2.
$ls /shared/test

Reference

1. Building a SLURM Cluster Using Amazon EC2 (AWS) Virtual Machines