Personal tools

Log in

Changes

From IGEP - ISEE Wiki

Jump to: navigation, search

How To Set Up an NFS Mount on Ubuntu 16.04

837 bytes removed, 18:24, 5 March 2018
no edit summary
==Introduction==
NFS, or Network File System, is a distributed file system protocol that allows you to mount remote directories on your server. This lets you manage storage space in a different location and write to that space from multiple clients. NFS provides a relatively quick and easy way to access remote systems over a network and works well in situations where the shared resources will be accessed regularly.
In this guide, we'll cover how to configure NFS mounts.
===Prerequisites===We will be using two servers in this tutorial: one will share part of its filesystem with the other.  
To follow along, you will need:
* Two Ubuntu 16.04 servers, each with a non-root user with sudo privileges and private networking, if it’s available to you.
For assistance setting up a user with these privileges, follow our Initial Server Setup with Ubuntu 16.04 guide.
For help setting up private networking, see How To Set Up And Use DigitalOcean Private Networking .
Throughout the tutorial, we refer to the server that shares its directories as the host and the server that mounts these directories as the client. In order to keep them straight, we’ll use the following IP addresses as stand-ins for the host and client values:
Host: 203.0.113.0
 
Client: 203.0.113.256
 
You should replace these values with your own host and client ip addresses.
ls -la /var/nfs/general
Output
4 drwxr-xr-x 2 root root 4096 Jul 25 15:26 .
NFS will translate any root operations on the client to the nobody:nogroup credentials as a security measure. Therefore, we need to change the directory ownership to match those credentials.
/etc/exports
directory_to_share client(share_option1,...,share_optionN)
We’ll need to create a line for each of the directories that we plan to share. Since our example client has an IP of 203.0.113.256, our lines will look like the following. Be sure to change the IPs to match your client:
/etc/exports
/var/nfs/general 203.0.113.256(rw,sync,no_subtree_check)/home 203.0.113.256(rw,sync,no_root_squash,no_subtree_check)
We’re using the same configuration options for both directories with the exception of no_root_squash. Let’s take a look at what each one means.
Status: active
To Action From-- ------ ----OpenSSH ALLOW AnywhereOpenSSH (v6) ALLOW Anywhere (v6)
On our system, only SSH traffic is being allowed, so we’ll need to add a rule for NFS traffic.
Status: active
To Action From-- ------ ----OpenSSH ALLOW Anywhere 2049 ALLOW 203.0.113.256 OpenSSH (v6) ALLOW Anywhere (v6)
This confirms that UFW will only allow NFS traffic on port 2049 from our client machine.
df -h
Output
Filesystem Size Used Avail Use% Mounted onudev 238M 0 238M 0% /devtmpfs 49M 628K 49M 2% /run/dev/vda1 20G 1.2G 18G 7% /tmpfs 245M 0 245M 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 245M 0 245M 0% /sys/fs/cgrouptmpfs 49M 0 49M 0% /run/user/0203.0.113.0:/home 20G 1.2G 18G 7% /nfs/home203.0.113.0:/var/nfs/general 20G 1.2G 18G 7% /nfs/general
Both of the shares we mounted appear at the bottom. Because they were mounted from the same file system, they show the same disk usage. To see how much space is actually being used under each mount point, use the disk usage command du and the path of the mount. The -s flag will provide a summary of usage rather than displaying the usage for every file. The -h will print human readable output.
ls -l /nfs/general/general.test
Output
-rw-r--r-- 1 nobody nogroup 0 Aug 1 13:31 /nfs/general/general.test
Because we mounted this volume without changing NFS’s default behavior and created the file as the client machine’s root user via the sudo command, ownership of the file defaults to nobody:nogroup. Client superusers won’t be able to perform typical administrative actions, like changing the owner of a file or creating a new directory for a group of users, on this NFS-mounted share.
ls -l /nfs/home/home.test
Output
-rw-r--r-- 1 root root 0 Aug 1 13:32 /nfs/home/home.test
We created home.test as root via the sudo command, exactly the same way we created the general.test file. However, in this case it is owned by root because we overrode the default behavior when we specified the no_root_squash option on this mount. This allows our root users on the client machine to act as root and makes the administration of user accounts much more convenient. At the same time, it means we don’t have to give these users root access on the host.
/etc/fstab
. . .
203.0.113.0:/var/nfs/general /nfs/general nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0203.0.113.0:/home /nfs/home nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
Note: More information about the options we are specifying here can be found in the man page that describes NFS mounting in the fstab with the man nfs command.
Output
Filesystem Size Used Avail Use% Mounted on/dev/vda 59G 1.3G 55G 3% /none 4.0K 0 4.0K 0% /sys/fs/cgroupudev 2.0G 12K 2.0G 1% /devtmpfs 396M 320K 396M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 2.0G 0 2.0G 0% /run/shmnone 100M 0 100M 0% /run/user
If you also want to prevent them from being remounted on the next reboot, edit /etc/fstab and either delete the line or comment it out by placing a # symbol at the beginning of the line. You can also prevent auto-mounting by removing the auto option, which will allow you to mount it manually.