# 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](https://hackmd.io/_uploads/rySWpaRUp.png) Source from: [IBM Developer, The NFS architecture](https://developer.ibm.com/tutorials/l-network-filesystems/) # 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. ```bash $mkdir /shared $chown nobody.nogroup -R /shared $chmod 777 -R /shared ``` 2. install NFS package. ```bash $apt update $apt install nfs-kernel-server -y ``` 3. config the `/etc/exports` to use a new shared directory and indicate the subnet. ```bash # /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) ``` 4. export the directories specified in the `/etc/exports` ```bash $exportfs -a ``` ### NFS client 1. create a shared directory and set the permission of a directory ```bash $mkdir /shared $chown nobody.nogroup -R /shared $chmod 777 -R /shared ``` 2. install NFS package. ```bash $apt update $apt install nfs-common -y ``` 3. edit the `/etc/fstab` to mount the shared directory ```bash <master node private ip>:/shared /shared nfs defaults 0 0 ``` 4. mount the shared directory ```bash $mount -a ``` # Testing 1. create a file in `/shared` on server 1. ```bash $touch /shared/test ``` 2. check the file in `/shared` on server 2. ```bash $ls /shared/test ``` # Reference [1. Building a SLURM Cluster Using Amazon EC2 (AWS) Virtual Machines](https://mhsamsal.wordpress.com/2022/01/15/building-a-slurm-cluster-using-amazon-ec2-aws-virtual-machines/)