How to setup an NFS Server and configure NFS Storage in Proxmox VE
NFS (Network File System) is a distributed file system protocol developed by Sun Microsystem. NFS allows a server to share files and directories of a folder on a server over the network. When the NFS share is mounted on a client system, then NFS allows a user to access files and directories on the remote system as if they were stored locally.
In this tutorial, I will guide you trough the installation of an NFS server on CentOS 7, I'll show you how to create a new directory on CentOS 7 and then share it through the NFS protocol. Then we will add the NFS share that we've created on the Proxmox server as backup space the virtual machines.
We need two of the servers.
- Proxmox server with IP: 192.168.1.111
- CentOS 7 with IP: 192.168.1.102
Step 1 - Install NFS on CentOS 7
Connect to the CentOS server with SSH (and get root privileges with sudo commands if you did not use the root login).
Now install nfs with yum:
yum -y install nfs-utils libnfsidmap rpcbind
nfs-utils are the utilities to manage the NFS server. They have to be installed on the server and client.
rpcbind is a daemon that allows an NFS clients to discover the port that is used by the NFS server.
libnfsidmap is a library to help mapping id's for NFSv4.
If all packages installed successfully, enable rpcbind and nfs-server services to be started when the server is booting.
systemctl enable rpcbind
systemctl enable nfs-server
Then start all services:
systemctl start rpcbind
systemctl start nfs-server
systemctl start rpc-statd
systemctl start nfs-idmapd
Next, we will enable firewalld and open the NFS, mountd and rpc-bind service ports so we can access NFS from other servers in our network.
systemctl start firewalld
firewall-cmd --permanent --zone public --add-service mountd
firewall-cmd --permanent --zone public --add-service rpc-bind
firewall-cmd --permanent --zone public --add-service nfs
Reload the firewalld configuration to apply the changes:
To see the services that are allowed in the firewall, use following command:
Step 2 - Create a shared Directory
In this step, we will create a directory and share it with the proxmox server. I'll create the directory 'nfsproxmox' under the /var directory and change the permission to 777 so anyone can read and write to it.
mkdir -p /var/nfsproxmox
chmod -R 777 /var/nfsproxmox/
Please note, if this backup server is used for other services or is a multiuser system, then you should use stricter permissions like 755 or even 750 and chown the directory to the user that shall be able to write to it.
Next, modify the /etc/exports file to configure which directory to share, the client IP and other specific options.
Add the configuration below:
Save and exit.
/var/nfsproxmox = shared directory with read and write permission.
192.168.1.111 = nfs client IP address (In this tutorial we use Proxmox Server).
rw = Allow the both to read and write to the shared directory.
sync = Reply to requests only after the changes have been committed to stable storage. (Default)
no_root_squash = Allow the root user on the client machine have the same level and permission with root on the server to the shared directory.
Now export the shared directory with the following command:
Other useful NFS commands are:
exportfs -a = export all shared directory on /etc/exports file configuration.
exportfs -v = display all shared directory.
The NFS configuration on the server is finished, and now we can move to the next stage, configure proxmox to use NFS.
Step 3 - Configure Proxmox to use NFS Storage
I'll have a proxmox server with IP 192.168.1.111, installed with this tutorial.
Login to the proxmox server from the web browser:
Inside Proxmox web admin, click on "Datacenter" and then go to the tab "Storage", click on "Add" and select NFS.
Now type in the NFS configuration details:
ID = Enter the name of the NFS, I'll use "nfsproxmox" here.
Server IP = IP address of the NFS server, mine is 192.168.1.102.
Export = NFS shared directory - /var/nfsproxmox.
Content = Type of the file on the NFS server, Disk image, ISO file, Container, VZDump backup file etc.
Enable = Check it.
Max Backups = Maximum allowed backup of each VM.
And click "Add".
Now you can see the new storage on the left side.
Step 4 - Backup VM on Proxmox to the NFS Storage
In this tutorial, I've one virtual machine with ID 100 named "debian", and it's live now. In this step, we will backup that VM to the NFS storage "nfsproxmox".
Click on the VM name and go to tab "Backup" and click "Backup Now".
Select all you need:
Storage = Our NFS name/ID.
There are 3 backup modes:
- Snapshot (No Downtime, Online).
- Suspend (Same as Snapshot for KVM), Use suspend/resume and multiple rsync passes (OpenVZ and LXC).
- Stop = Shutdown the VM, then start KVM live backup and restart VM (Short Downtime.)
Compression = Available LZO and GZIP compression.
Click "Backup" to start the backup of the VM.
Now you can see the backup task is running:
To see the backup file, click on the nfs-id "nfsproxmox", and click on the tab "Content".
Step 5 - Restore a VM from NFS Storage
To restore the VM, Click on the VM that you want to restore and then click on "Restore" on the NFS storage.
You can see the pop-up box:
Source = backup file.
Storage = On which storage the VM will be stored.
VM ID = ID for restored VM.
Click "Restore" to start the restore VM.
Restore VM process:
If you want to replace the VM, then you can select the VM that you want to replace and go to the tab "Backup", there you will also see the backup file, select it and click "Restore".
NFS (Network File System) is a distributed file system protocol to allow clients to access the files and directories on the NFS server as if they were stored locally. We can store our data files and directories on the NFS server and then share them with all clients that that we allowed in the exports file. NFS is very useful for virtual server backups. We can use NFS as Proxmox storage, we can put on that storage ISO files, Virtual machine images files and VM Backup files. NFS is easy to install and integrate with Proxmox from within the Proxmox web admin.