Title: Implement an NFS Server
Course: CIS 208: Linux/UNIX III: Intermediate System Administration, Networking, and Security ~ For IGNITE Review > Section: Learning Modules

Implement an NFS Server

For each server that will run NFS, ensure that it has the hard drive space required.  If needed, add more storage and create partitions dedicated to one or more share.  For example, if a 200 GB drive is added and 100 GB needs to be dedicated to a project, partition it with two 100 GB partitions.  This will ensure that 100 GB is available to the project, even if someone mistakenly tries to copy 150 GB of data to the other share.

NFS runs inside the Linux kernel, but packages are required to manage it.  "yum -y install nfs nfs-utils" will install the utilities and the files to manage the services.  The three services are named rpcbind, nfs, and nfslock.  All three should be set to run automatically at boot.

The /etc/exports file is used to configure shares.  Here are two sample entries for shares. The first allows any host to access the files in readonly mode. The second only allows a single host to access the files in read-write mode.

/data/project1 *(ro)
/data/project2 172.18.1.2(rw,async)

The following entry will share the /home directory on the NFS file server.  The async option is not used, since it will ensure any problems with file transfers will be noticed immediately.

/home *(rw)

After updating the /etc/exports file, run "exportfs -r" to import the new settings.

On another host, run "showmount -e 172.18.1.1" to see the list of available shares.  To mount the /data/project1 directory at /project1, run "mkdir /project1" then "mount -t nfs 172.18.1.1:/data/project1 /project1".  To mount the share automatically at boot, add "172.18.1.1:/data/project1  /project1  nfs  defaults 0 0" to /etc/fstab.

Before allowing users to access the shares, ensure that the UIDs match.  Connect to each client and run id for the local UID and GID of each user.  If the IDs on the client do not match the IDs on the server, it will be necessary to update them.  For example, if user catmiller is UID 500 and GID 500 on the client, and he is UID 10000 and GID 10000 on the server, it will be necessary to stop any processes running as this user.  "ps -u 500" will list them.  Next run "find / -uid 500 -exec chown 10000 {} \;" and "find / -gid 500 -exec chgrp 10000 {} \;".  The last step is to update the UID and GID in /etc/passwd and the GID in /etc/group.  The user man now login as before and will have the correct permissions on the nfs share.

If a shared home directory is desired, create a new mountpoint for the nfs home directory such as /nfshome.  Mount the new directory and copy the user's current home directory to the share.  For example, "cp -pr /home/catmiller /nfshome".  Then update the home directory for the user in /etc/passwd.  As before, ensure that the user is not logged in or running any processes during the transition.