Tuesday 1 April 2014

How To Setup NFS Mount On Ubuntu

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.


Master: 172.16.6.12
Client: 172.16.6.13

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 /var/nfs/ does not exist, we need to do two things before we can export it. 

First, we need to create the directory itself:

# mkdir /var/nfs/

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 nobody:nogroup /var/nfs

After completing those steps, it’s time to export the directories to the other VPS:

# nano /etc/exports

Add the following lines to the bottom of the file, sharing both directories with the client:
/home 12.33.44.555(rw,sync,no_root_squash,no_subtree_check)

/var/nfs 12.33.44.555(rw,sync,no_subtree_check)

Once you have entered in the settings for each directory, run the following command to export them:

# exportfs -a


Setting Up the NFS Client


Step One—Download the Required Software


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

# apt-get install nfs-common portmap


Step Two—Mount the Directories


Once the programs have been downloaded to the the client server, create the directories that will contain the NFS shared files

# mkdir -p /mnt/nfs/home
# mkdir -p /mnt/nfs/var/nfs


Then go ahead and mount them

# mount 12.34.56.789:/home /mnt/nfs/home
# mount 12.34.56.789:/var/nfs /mnt/nfs/var/nfs

You can use the df -h command to check that the directories have been mounted. You will see them last on the list.

# df -h

Additionally, use the mount command to see the entire list of mounted file systems.

# mount


Testing the NFS Mount


Once you have successfully mounted your NFS directories, you can test that they work by creating files on the Client and checking their availability on the Server.

Create a file in each directory to try it out:

# touch /mnt/nfs/home/example /mnt/nfs/var/nfs/example

You should then be able to find the files on the Server in the /home and /var/nfs directories.

# ls /home

# ls /var/nfs/


You can ensure that the mount is always active by adding the directories to the fstab file on the client. This will ensure that the mounts start up after the server reboots.

# nano /etc/fstab


You can learn more about the fstab options by typing in:

# man nfs

Any subsequent restarts will include the NFS mount—although the mount may take a minute to load after the reboot You can check the mounted directories with the two earlier commands:

# df -h
 
# mount

Removing the NFS Mount


Should you decide to remove a directory, you can unmount it using the umount command:

# cd 
# sudo umount /directory name


You can see that the mounts were removed by then looking at the filesystem again.

# df -h





No comments:

Post a Comment