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, /etc/hosts.allow and /etc/hosts.deny, which list the machines allowed to access services via the network, and those that are not.

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:

Example of architecture: One NFS-server VM and two client VMs.

NFS archi

Configuring Your NFS Server

Before you begin:

  • Configure two security groups, for example "NFS-Server" and "NFS-Client". For more information, see About Security Groups.

  • Authorize the VM that supports the NFS server to receive traffic from the other VMs on port 2049 using TCP protocol. For more information, see About Security Group Rules.

It is not necessary to install the epel-release repository to configure the NFS server and client VMs.

  1. Install the CentOS 7 nfs-utils package:

    $ sudo yum install nfs-utils
  2. Create the folder to share between VMs:

    $ sudo mkdir /space1
  3. 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, or nogroup values if the root_squash option is activated (by default with NFSv4).

  4. 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.

  5. Configure the necessary services to start simultaneously with the VM creation:

    $ sudo systemctl enable nfs-server
  6. Restart the services to ensure the process is working properly:

    $ sudo systemctl restart nfs-server
  7. 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

  1. Install the CentOS 7 nfs-utils package:

    $ sudo yum install nfs-utils
  2. Test your connection:

    1. 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.

    2. 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.

    3. Repeat this step for every client VM.

  3. 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.

  4. 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