What a n00b!

Oversimplified NFS Server How-To

This how-to assumes that both systems are running Ubuntu, although it can be easily ported to work with other distributions. For our example, we will use two systems: ServerA and ServerB. ServerA will be the NFS "server" which will be used to store the actual data files and ServerB will connect to ServerA to use the files as though they are mounted locally. For our example, we will also assume that both servers are on the same private LAN with ServerA at IP address 10.10.0.2 and ServerB at 10.10.0.3.

NFS Server Installation

On the server side (ServerA) you'll need three core pieces of software. To install, as a user who has permission to sudo, run:

sudo apt-get install nfs-kernel-server nfs-common portmap

After the install finishes, it will start the portmap and nfs services. You can restart each by using the following commands respectively:

sudo /etc/init.d/portmap restart

sudo /etc/init.d/nfs-kernel-server restart

What's commonly referred to as shares in Windows is referred to an export in NFS. The key file to edit to setup your exports is going to be /etc/exports. Open up your exports file with your favorite text editor (replacing vim with the text editor of your choice if you like):

sudo vim /etc/exports

To allow ServerB to access /srv/data with read-write privileges, add the following line to the end of your /etc/exports file:

/srv/data 10.10.0.3 (no_subtree_check,rw)

You can allow the whole 10.10.0.x subnet by replacing 10.10.0.0/24 with the IP in the above line. Also, change the "rw" to "ro" to make the export read-only. Once you are done, export your newly exported filesystems:

exportfs -ra

Now we're ready to go to the "client" (ServerB).

NFS Client Installation

On your client end, you'll need to install the same software with the exception of the NFS server software:

sudo apt-get install nfs-common portmap

Once the software installs, portmap will start up and you're ready to go. For our example, we're going to assume you want to mount the export on the remote server to /home/shared. Now you can mount your export:

sudo mount 10.10.0.2:/srv/data /home/shared

Now your system ServerB has mounted a share on ServerA and can access data in the exported directory. Keep in mind that NFS bases permissions on the UID's on both end. A user with the same UID on each end will be required to read-write if you have the permissions set for write only to the owner. You can change permissions on ServerA using chmod.

Setting To Mount on Boot

In order for your NFS export to mount on boot, you'll want to add the NFS server in your /etc/fstab file. At the end of the file, for our example, you'll add a line like this:

10.10.0.2:/srv/data /home/shared nfs defaults 0 0

Be sure to do a test reboot before assuming this setup is ready for production!

Comments

Comments powered by Disqus