Setting Up an NFS Server and Accessing it from VMs in OpenStack¶
In environments like the Barcelona Supercomputing Center (BSC), where OpenStack volumes do not support multi-attachment, sharing data across multiple virtual machines (VMs) can be challenging. A Network File System (NFS) server provides a useful workaround by allowing multiple VMs to access the same file system over the network.
This guide explains how to set up an NFS server and how to mount the shared directory on OpenStack VMs.
π OpenStack Security Group Rules for NFS Access¶
When setting up an NFS server and clients inside OpenStack, make sure your security group allows the necessary traffic.
Hereβs a complete set of Ingress rules to configure via the OpenStack Dashboard > Network > Security Groups:
π½ Ingress Rules (on the NFS Server)¶
Direction | Ether Type | Protocol | Port Range | Remote IP CIDR |
---|---|---|---|---|
Ingress | IPv4 | TCP | 111 | 192.168.0.0/24 |
Ingress | IPv4 | UDP | 111 | 192.168.0.0/24 |
Ingress | IPv4 | TCP | 2049 | 192.168.0.0/24 |
Ingress | IPv4 | UDP | 2049 | 192.168.0.0/24 |
Ingress | IPv4 | TCP | 20048 | 192.168.0.0/24 |
Ingress | IPv4 | UDP | 20048 | 192.168.0.0/24 |
π οΈ Step 1: Set Up the NFS Server¶
On the NFS Server VM¶
- Install NFS server packages
For Debian/Ubuntu:
sudo apt update
sudo apt install nfs-kernel-server -y
For RHEL/CentOS:
sudo yum install nfs-utils -y
sudo systemctl enable --now nfs-server
- Create a shared directory
sudo mkdir -p /mnt/nfs_share
sudo chown nobody:nogroup /mnt/nfs_share
sudo chmod 777 /mnt/nfs_share
- Configure
/etc/exports
Add the following line to /etc/exports
to allow access from your VM subnet (e.g., 192.168.0.0/24
):
/mnt/nfs_share 192.168.0.0/24(rw,sync,no_subtree_check)
- Apply the export configuration
sudo exportfs -rav
- Enable firewall rules (if applicable)
sudo ufw allow from 192.168.0.0/24 to any port nfs
π₯οΈ Step 2: Access the NFS Share from OpenStack VMs¶
On Each Client VM¶
- Install NFS client
For Debian/Ubuntu:
sudo apt update
sudo apt install nfs-common -y
For RHEL/CentOS:
sudo yum install nfs-utils -y
- Create a mount point
sudo mkdir -p /mnt/nfs_clientshare
- Mount the NFS share
Replace NFS_SERVER_IP
with your NFS serverβs IP address:
sudo mount NFS_SERVER_IP:/mnt/nfs_share /mnt/nfs_clientshare
- Make the mount persistent (optional)
Add the following line to /etc/fstab
:
NFS_SERVER_IP:/mnt/nfs_share /mnt/nfs_clientshare nfs defaults 0 0