Setting Up an NFS Server
The Network File System (NFS) protocol enables a network of machines to share storage via a dedicated host. This storage is an NFS server: visible to all remote machines, it allows system administrators to manage just one centralized resource.
This guide explains how to configure an NFS server on a CentOS 7 OUTSCALE machine image (OMI).
Foreword
This procedure relies on the mechanism of the security groups provided by IaaS rather than the mechanism of the NFS. For more information, see About Security Groups and About Security Group Rules.
You must create two separate security groups to ensure that only the desired client virtual machines (VMs) have access to the file server.
Linux provides two files, |
It is recommended to use a Net rather than the public Cloud. For more information, see About Nets.
We recommend using NFS version 4 (NFSv4) protocol.
The examples presented in the procedures are based on the parameters described in the following picture:
Configuring Your NFS Server
Before you begin:
|
It is not necessary to install the |
-
Install the CentOS 7
nfs-utils
package:$ sudo yum install nfs-utils
-
Create the folder to share between VMs:
$ sudo mkdir /space1
-
Modify the folder permissions so that only the NFS can access the shared files:
$ sudo chmod -R 755 /space1 $ sudo chown nfsnobody:nfsnobody /space1
You can use the
nfsnobody
,nobody
, ornogroup
values if the root_squash option is activated (by default with NFSv4). -
Authorize the export of the file system to other VMs by adding the following line in the
/etc/exports
file:/space1 *(rw,sync)
The wildcard
*
enables any machine to access the NFS server. You can limit client VMs' access by using their host name.Note however that as part of a dynamic infrastructure such as IaaS, client VMs may change regularly.
Synchronous or Asynchronous?
NFS allows two types of write operations:
-
synchronous (
sync
) is the standard option. Data consistency is ensured for ongoing reads/writes when a power cut or an abnormal disruption of the server occurs. -
asynchronous (
async
) can increase performances in IaaS. With this option, the server shows the client that the write operations were indeed completed, to avoid blockage of the entire system waiting for their completion. Because of it, data integrity is lower.
Choose your option depending on your Recovery Point Objective (RPO) and rely on the Snapshot mechanism for back-ups. For more information, see Creating a Snapshot of a Volume.
-
-
Configure the necessary services to start simultaneously with the VM creation:
$ sudo systemctl enable nfs-server
-
Restart the services to ensure the process is working properly:
$ sudo systemctl restart nfs-server
-
Verify that the NFS server displays the services to the other VMs:
$ showmount -e 10.0.1.111
The showmount -e command returns the mount point,
/space1
here:Export list for 10.0.1.111: /space1 10.0.1.0/24
Your NFS Server is now configured.
Configuring Your Client VMs
-
Install the CentOS 7
nfs-utils
package:$ sudo yum install nfs-utils
-
Test your connection:
-
From a client VM, create a file in the
/mnt/
folder.The
/mnt/
folder is meant for tests only. It is recommended to use another path for production purposes. -
From another client VM, execute the following command:
$ mount -t nfs4 10.0.1.111:/space1/ /mnt/
You need to specify:
-
The IP of the server, 10.0.1.111 here.
-
The mount point of the server,
/space1
here. -
The mount point of the client,
/mnt/
here.
-
-
Repeat this step for every client VM.
-
-
Add the following line to your
/etc/fstab
file:10.0.1.111:/space1 /mnt nfs rw 0 0
The mount command is not persistent. It is recommended to configure it following the procedure above to make sure it still exists after the restart of a VM.
-
Test your configuration:
$ mount -a $ echo $?
The echo $? command returns
0
when everything works. Otherwise, a problem has occurred.
Your NFS server is ready to be used within your network.
Related Pages