Tuesday, March 11, 2014

How to Install and Configure NFS on CentOS 5.5


This tutorial explains how to set up an NFS server and an NFS client on CentOS 5.5. NFS stands for Network File System; through NFS, a client can access (read, write) a remote share on an NFS server as if it was on the local hard disk.

Server side:
On the NFS server:
Make sure yuo have nfs-utils and nfs-utils-lib installed

# rpm -qa | grep nfs
nfs-utils-lib-1.0.8-7.6.el5
nfs-utils-1.0.9-47.el5_5

If "rpm -qa" returns nothing, do a
# yum install nfs-utils nfs-utils-lib

Set runlevel:
# chkconfig --list | grep nfs
nfs            0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@ni3 ~]# chkconfig --level 345 nfs on
[root@ni3 ~]# chkconfig --list | grep nfs
nfs             0:off 1:off 2:off 3:on 4:on 5:on 6:off

Check portmap runlevel:
# chkconfig --list | grep portmap
portmap         0:off 1:off 2:off 3:off 4:off 5:off 6:off
# chkconfig --level 345 portmap on

Start portmap service:
# service portmap start
Starting portmap:                                          [  OK  ]

Start NFS server:
# service nfs start

Export directories on the server. For example, I want to export "/share/lxu"
# vi /etc/exports
/share/lxu            xxx.xxx.xxx.xxx(ro,root_squash,no_subtree_check)

For a complete list of mount options, check out the following page:
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Deployment_Guide/s1-nfs-server-config-exports.html

Export directories:
# exportfs -a

Verify the exported directories:
# exportfs
/share/lxu
 xxx.xxx.xxx.*

Client side:
Make sure you have nfs-utils and nfs-utils-lib installed

# rpm -qa | grep nfs
nfs-utils-lib-1.0.8-7.6.el5
nfs-utils-1.0.9-47.el5_5

If "rpm -qa" returns nothing, do a
# yum install nfs-utils nfs-utils-lib

Check portmap runlevel:
# chkconfig --list | grep portmap
portmap         0:off 1:off 2:off 3:off 4:off 5:off 6:off
# chkconfig --level 345 portmap on

Start portmap:
# service portmap start
Starting portmap:                                          [  OK  ]

Create mount directory:
# mkdir -p /mnt/nfs/lxu
Mount diretories:
mount server_IP:/share/lxu /mnt/nfs/lxu

Verify mount point:
[tony@bi4 nfs]$ mount | grep nfs
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
server_IP:/share/lxu on /mnt/nfs/lxu type nfs (rw,addr=server_IP)

To mount NFS shares at boot time, edit your /etc/fstab file and add the following entry:
# vi /etc/fstab
add
192.168.0.100:/share/lxu  /mnt/nfs/lxu   nfs      rw,sync,hard,intr  0     0

Mount parameters:

  • rw - Read and write
  • sync - Acknowledge data after it's written out to disk, prevent data corruption
  • hard - The user cannot terminate the process waiting for the NFS communication to resume unless the intr option is also specified
  • intr - Allow signals to interrupt an NFS call. Useful for aborting when the server doesn't respond

No comments: