Network File System (NFS) is a distributed file system protocol that allows you to mount remote directories on your server, enabling you to manage storage space in a different location and write to that space from multiple clients. If you’re using DigitalOcean’s Block Storage, running an NFS server on an attached droplet is a good solution to expose a block storage volume. Let’s get started with the setup:

Pre-requisites

Two Ubuntu servers: You’ll need two servers for this tutorial—one to act as the host (sharing its filesystem) and the other as the client (mounting the shared directories).

Each server should have:

non-root user with sudo privileges.

UFW firewall set up.

Private networking (if available).

The host server should have a block storage volume attached to it.

Step 1: Downloading and Installing the Components

Host Server:

Install the "nfs-kernel-server" package, which allows you to share directories:

sudo apt update
sudo apt install nfs-kernel-server

 

Verify that NFS versions 3 and 4 are enabled:

sudo cat /proc/fs/nfsd/versions

 

Create the File Systems:

Set up the NFS root directory (e.g., /srv/nfs4) and bind mount the directories you want to export (e.g., /var/www and /opt/backups):

sudo mkdir -p /srv/nfs4/backups
sudo mkdir -p /srv/nfs4/www
sudo mount --bind /opt/backups /srv/nfs4/backups
sudo mount --bind /var/www /srv/nfs4/www

 

Make the bind mounts permanent by editing /etc/fstab:

sudo nano /etc/fstab

Add the following lines:
/opt/backups /srv/nfs4/backups none bind 0 0
/var/www /srv/nfs4/www none bind 0 0

 

Step 2: Exporting the File Systems

Edit the NFS exports file:

sudo nano /etc/exports

 

Add the following lines (replace placeholders with actual paths and client IPs):

/srv/nfs4/backups client_ip(rw,sync,no_subtree_check)
/srv/nfs4/www client_ip(rw,sync,no_subtree_check)

 

Apply the changes:

sudo exportfs -a

 

Step 3: Firewall Configuration

Allow NFS traffic through the firewall:

sudo ufw allow from client_ip to any port nfs
sudo ufw enable

 

Now your NFS server is set up! The host will share its directories, and the client can mount them using the provided IP address.

Remember to replace placeholders with actual values.

For more detailed instructions, you can refer to the DigitalOcean tutorial on setting up an NFS server using block storage

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution