log / setup vm as nfs server
Preparation
- VM for Application (NFS Client)
- VM for Data/File Storage (NFS Server)
Setup
Setup on NFS Server
1. Update and install NFS server package
sudo apt update
sudo apt install nfs-kernel-server
2. Create directory to share
sudo mkdir /nfs_share
3. Set permission for shared directory
sudo chown nobody:nogroup /nfs_share
sudo chmod 777 /nfs_share
4. Configure NFS export
sudo nano /etc/exports
add this line
/nfs_share VM_APP_IP(rw,sync,no_subtree_check)
5. Apply changes and restart server
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
Setup on NFS Client
1. Update and install NFS server package
sudo apt update
sudo apt install nfs-common
2. Create mount point
sudo mkdir /mnt/nfs_clientshare
3. Mount NFS Share
sudo mount VM_DATA_IP:/nfs_share /mnt/nfs_clientshare
4. Edit fstab to make mount permanent
sudo nano /etc/fstab
add this line
VM_DATA_IP:/nfs_share /mnt/nfs_clientshare nfs defaults 0 0
Testing
On NFS Client, try creating file in mount point
touch /mnt/nfs_clientshare/testfile
If success, file will be appears also in NFS Server in folder /nfs_share
You also can use this command to verify mount, run this on NFS Client
mount | grep nfs
or
df -h
Additional: Firewall Configuration
Check and Enable Firewall
Check if active
sudo ufw status
If it shows “Status: inactive”, the firewall is not enabled.
Enable if not active
sudo ufw enable
Check existing rule
sudo ufw status verbose
On NSF Server
Allow NFS traffic
sudo ufw allow from VM_APP_IP to any port nfs
sudo ufw allow 2049
alternatively, we need to open this port