Monday, December 21, 2015

Basic NFS Configuration

1. Basic NFS Configuration

1.1. NFS Server configuration

Run the below commands to begin the NFS Server installation:
[nfs-server ]# yum install nfs-utils rpcbind

Next we export some arbitrary directory called /opt/nfs. Create /opt/nfs directory:

[nfs-server ]# mkdir -p /opt/nfs

and edit /etc/exports NFS exports file to add the below line while replacing the IP address with the IP address of your client:
/opt/nfs NFS_client_IP(no_root_squash,rw,sync)

Next make sure to enable 2049 port on your firewall to allow clients requests:
[nfs-server ]# firewall-cmd --zone=public --add-port=2049/tcp --permanent
[nfs-server ]# firewall-cmd --reload

Start rpcbind daemon and NFS server in this order:
[nfs-server ]# service rpcbind start; service nfs start

Check the NFS server status:
[nfs-server ]# service nfs status 
 

1.2. NFS Client configuration

To be able to mount NFS exported directories on your client the following packages needs to be installed. Depending on your client's Linux distribution the installation procedure may be different. On Redhat 7 Linux the installation steps are as follows:

[nfs-client ]# yum install nfs-utils rpcbind
[nfs-client ]# service rpcbind start
 
What remains is to create a mount point directory eg. /mnt/nfs and mount previously NFS exported /opt/nfs directory:
[nfs-client ]# mkdir -p /mnt/nfs
[nfs-client ]# mount NFS-Server_IP:/opt/nfs /mnt/nfs/
 
Test correctness of our setup between NFS Server and NFS client. Create an arbitrary file within NFS mounted directory on the client side:
[nfs-client ]# cd /mnt/nfs/
[nfs-client ]# touch NFS.test
[nfs-client ]# ls -l
total 0
-rw-r--r--. 1 root root 0 Dec 11 08:13 NFS.test
 
Move the the server side and check whether our newly NFS.test file exists:
[nfs-server ]# cd /opt/nfs/
[nfs-server ]# ls -l
total 0
-rw-r--r--. 1 root root 0 Dec 11 08:13 NFS.test

2. Configuring permanent NFS mount

In order to have our NFS exports permanently available after the NFS server system reboot we need to make sure that nfs service starts after reboot:

[nfs-server ]# systemctl enable nfs-server
ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service'

To allow client to mount NFS exported directory permanently after reboot we need to define a mount procedure within /etc/fstab config file. Open /etc/fstab file and add the following line:

NFS-Server_IP:/opt/nfs /mnt/nfs nfs defaults   0 0

No comments: