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/fs-01.sda1

mkdir -p /mnt/nfs/fs-01.sdb1

prevent accedent writes:

sudo chmod 000 /mnt/nfs/fs-01.sda1

sudo chmod 000 /mnt/nfs/fs-01.sdb1

sudo mount fileshare-01:/mnt/local/sda1/ /mnt/nfs/fs-01.sda1/

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
Filesystem             Size  Used Avail Use% Mounted on/dev/sda                20G  948M   19G   5% /udev                   119M  4.0K  119M   1% /devtmpfs                   49M  208K   49M   1% /runnone                   5.0M     0  5.0M   0% /run/locknone                   122M     0  122M   0% /run/shmfileshare-01:/home      20G  948M   19G   5% /mnt/nfs/homefileshare-01:/var/nfs   20G  948M   19G   5% /mnt/nfs/var/nfs

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

Your list should look something like this:
/dev/sda on / type ext4 (rw,errors=remount-ro,barrier=0) [DOROOT]proc on /proc type proc (rw,noexec,nosuid,nodev)sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)none on /sys/fs/fuse/connections type fusectl (rw)none on /sys/kernel/debug type debugfs (rw)none on /sys/kernel/security type securityfs (rw)udev on /dev type devtmpfs (rw,mode=0755)devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)none on /run/shm type tmpfs (rw,nosuid,nodev)rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)fileshare-01:/home on /mnt/nfs/home type nfs (rw,vers=4,addr= fileshare-01,clientaddr=192.168.1.xxx)fileshare-01:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,vers=4,addr=12.34.56.78,clientaddr=192.168.1.xxx)


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/fs-01.sda1/test.txt
touch /mnt/nfs/fs-01.sdb1/test.txt

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

ls /mnt/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.
vi /etc/fstab

fileshare-999:/mnt/local/sdx1/test/ /mnt/nfs/fs-99.sdx1.test/ nfs4 _netdev,auto,hard,intr,retry=1,nolock,bg 0 0

fileshare-01:/mnt/local/sda1/ /mnt/nfs/fs-01.sda1/ nfs4 _netdev,auto,retry=1,nolock,bg,intr 0 0

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:

sudo umount /directory name


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


You should find your selected mounted directory gone.

Tag Cloud