Setting Up the NFS Server

About NFS (Network File System) Mounts


NFS mounts work to share a directory between several virtual servers. This has the advantage of saving disk space, as the home directory is only kept on one virtual private server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.

Setup


An NFS mount is set up between at least two virtual servers. The machine hosting the shared network is called the server, while the ones that connect to it are called ‘clients’.

This tutorial requires 2 servers: one acting as the server and one as the client. We will set up the server machine first, followed by the client. The following IP addresses will refer to each one:

Master: fileshare-01
Client: database-01

There are 3 ways to do this.

OPTION 1 (Public share, everything is owned by
OPTION 2 (User share, user has access to only there data)
OPTION 3 ()

The system should be set up as root. You can access the root user by typing
sudo su



Setting Up the NFS Server


Step One—Download the Required Software

Start off by using apt-get to install the nfs programs.
apt-get install nfs-kernel-server portmap


Step Two—Export the Shared Directory

The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.

Suppose we wanted to share two directories: /home and /var/nfs.

Because the /mnt/local/ does not exist, we need to do two things before we can export it.

First, we need to create the directory itself:
mkdir /mnt/local/

We will have 2 physical disks loaded at this location /sda1 and /sdb1
sudo chmod 755 sda1 sdb1
Second, we should change the ownership of the directory to the user, nobody and the group, no group. These represent the default user through which clients can access a directory shared through NFS.

Go ahead and chown the directory:
chown root:root /mnt/local

Option 1:
chown nobody:nogroup /mnt/local/sda1
chown nobody:nogroup /mnt/local/sdb1
Option 2:
chown uid:gui /mnt/local/sda1
chown uid:gui /mnt/local/sdb1

After completing those steps, it’s time to export the directories to the other VPS.
vi /etc/exports

Add the following lines to the bottom of the file, sharing both directories with the client:

Share with clients on subnet:  ->  192.168.1.0/24   (This is the one we will use) 
Share with specific server:      -> database-01 	

Option 1:

/mnt/local/sda1 192.168.1.0/24(rw,nohide,no_subtree_check,async,all_squash)
/mnt/local/sdb1 192.168.1.0/24(rw,nohide,no_subtree_check,async,all_squash)

Option 2:  Below is what QBW has

/mnt/local/sda1 192.168.1.0/24(rw,sync,no_root_squash,nohide,no_subtree_check)
/mnt/local/sdb1 192.168.1.0/24(rw,sync,no_root_squash,nohide,no_subtree_check)

/mnt/local/sdb1/test 192.168.1.0/24(rw,sync,root_squash,nohide,no_subtree_check)



These settings accomplish several tasks:

  • rw: This option allows the client server to both read and write within the shared directory

  • sync: Sync confirms requests to the shared directory only once the changes have been committed.

  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.

  • no_root_squash: This phrase allows root to connect to the designated directory

Once you have entered in the settings for each directory, run the following command to export them:
 /etc/init.d/nfs-kernel-server restart


to see your exports
exportfs -v

Now for the CLIENT.

Tag Cloud