Linux NFS QuickGuide
NFS Server Daemons
portmap enables NFS clients to discover the NFS services available on a given NFS server
nfsd provides all nfs servide except file locking and quota management
mountd processes nfs client mount requests
statd implements nfs lock recovery when an nfs server system crashes
lockd starts the kernel's nfs lock manager
rquotad provides file system quota information nfs exports to NFS clients using file system quotas
Daemon start sequence : portmap, nfsd, mountd, statd, rquotad
files:
/exports : lists nfs shares and permissions, mount options, etc
/var/lib/nfs/rmtab : lists each NFS export that is mounted by an NFS client.
each time rpc.mounted receives a mount request, it adds
an entry to /var/lib/nfs/rmtab file.
/var/lib/nfs/etab : contains currently exported filesystems
[root@localhost usr]# cat /etc/exports
#
/usr/share 192.168.200.0/255.255.255.0(rw,insecure,sync,anonuid=600,anongid=600)
share options:
secure : requires client request to originate fr om secure port
secure_lock : requires that clients requsting lock authentication before activating the lock
async : allows the server to cache disk write to improve performance
subtree_check : if only part of a filesystem is exported, this checks to make sure the file is
in the exported protion of the fs
root_squash : maps all requests from a user ID of 0 to uid of anonymous user -2 in linux
anonuid = uid : set the UID of annomous account to uid
To start nfs service:
1. #service nfs start
2. #/etc/rc.d/init.d/nfs start
By default 8 copies of nfsd started, to enable the server to process multiple requests, change this value
/etc/sysconfig/nfs RPCNFSDCOUNT=8
[root@localhost sysconfig]# vi /etc/sysconfig/nfs
[root@localhost sysconfig]# service nfs restart
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[root@localhost sysconfig]# ps -ef grep nfsd grep -v grep
root 5847 1 0 20:34 ? 00:00:00 [nfsd]
root 5848 1 0 20:34 ? 00:00:00 [nfsd]
root 5849 1 0 20:34 ? 00:00:00 [nfsd]
root 5850 1 0 20:34 ? 00:00:00 [nfsd]
root 5851 1 0 20:34 ? 00:00:00 [nfsd]
root 5852 1 0 20:34 ? 00:00:00 [nfsd]
root 5853 1 0 20:34 ? 00:00:00 [nfsd]
root 5854 1 0 20:34 ? 00:00:00 [nfsd]
root 5855 1 0 20:34 ? 00:00:00 [nfsd]
root 5856 1 0 20:34 ? 00:00:00 [nfsd]
root 5857 1 0 20:34 ? 00:00:00 [nfsd]
root 5858 1 0 20:34 ? 00:00:00 [nfsd]
root 5859 1 0 20:34 ? 00:00:00 [nfsd]
root 5860 1 0 20:34 ? 00:00:00 [nfsd]
root 5861 1 0 20:34 ? 00:00:00 [nfsd]
root 5862 1 0 20:34 ? 00:00:00 [nfsd]
[root@localhost sysconfig]# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 32768 status
100024 1 tcp 32770 status
100011 1 udp 932 rquotad
100011 2 udp 932 rquotad
100011 1 tcp 935 rquotad
100011 2 tcp 935 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 udp 32770 nlockmgr
100021 3 udp 32770 nlockmgr
100021 4 udp 32770 nlockmgr
100021 1 tcp 32776 nlockmgr
100021 3 tcp 32776 nlockmgr
100021 4 tcp 32776 nlockmgr
100005 1 udp 956 mountd
100005 1 tcp 959 mountd
100005 2 udp 956 mountd
100005 2 tcp 959 mountd
100005 3 udp 956 mountd
100005 3 tcp 959 mountd
[root@localhost sysconfig]# cat /var/lib/nfs/rmtab
192.168.200.135:192.168.200.0/255.255.255.0:0x00000001
192.168.200.0/255.255.255.0:/usr/share:0x00000002
[root@localhost sysconfig]# cat /var/lib/nfs/etab
/usr/share 192.168.200.0/255.255.255.0(rw,sync,wdelay,hide,nocrossmnt,insecure,root_squash,no_all_squash,subtree_check,secure_locks,mapping=identity,anonuid=600,anongid=600)
[root@localhost sysconfig]# cat /etc/exports
#
/usr/share 192.168.200.0/255.255.255.0(rw,insecure,sync,anonuid=600,anongid=600)
[root@localhost sysconfig]# exportfs -v
/usr/share 192.168.200.0/255.255.255.0(rw,wdelay,insecure,root_squash,anonuid=600,anongid=600)
root@ubuntu:/mnt# showmount 192.168.200.128
Hosts on 192.168.200.128:
192.168.200.0/255.255.255.0
192.168.200.135
root@ubuntu:/mnt# showmount -a 192.168.200.128
All mount points on 192.168.200.128:
192.168.200.0/255.255.255.0:/usr/share
192.168.200.135:192.168.200.0/255.255.255.0
root@ubuntu:/mnt# showmount -e 192.168.200.128
Export list for 192.168.200.128:
/usr/share 192.168.200.0/255.255.255.0
root@ubuntu:/mnt# showmount -d 192.168.200.128
Directories on 192.168.200.128:
/usr/share
192.168.200.0/255.255.255.0
NFS Client
/etc/fstab
* is the default value
rsize = n *4096 sets the nfs read buffer size to n bytes
wsize = n *4096 sets the nfs write buffer size to n bytes
timeo = n *7 sets the RPC transmission timeout to n thenths of a second
retry = n *10000 sets the time to retry a mount before giving up
port = n *2049 sets the NFS server port to which to connect to
bg *no enables mount attempts to run in the background if first mount attempt time out
fg *yes causes mount attempts to run in foreground if the first mount attempt time out
soft *no allows an NFS file operation to fail and terminate
hard *yes allows an NFS file operation to continue retry after reporting "server not responding"
intr *no allows signals (control+c) to interrupt a failed NFS operation
lock enables NFS locking and starts the statd and lockd daemons
exportfs -o async,rw 192.168.200.128:/var/tmp
mount -t nfs server:/share -o rsize=8192, wsize=8192, hard, intr, nolock
mount -t iso9660 -o ro /dev/cdrom /cdrom
fstab file structure:
/etc/fstab six fields: fstab-sync
(1)block-device-to-be-mounted:
(2)mount-point:
(3)fs-type:
(4)mount-options:
(5)dump command to determine if it needs to be dumped or not 0=no
(6)fsck check-order
[root@localhost /]# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
NFS Troubleshooting:
1. when mount -t nfs remote:share local_mount_point, the system stalls and can't mount...
check /var/log/messages file and see error "kernel: RPC: failed to contact portmap (errno -5)"
portmap (rpc ) is not started.
service portmap status ; to verify portmap is running or stopped
service portmap start or /etc/init.d/portmap start to start portmap
make sure also enable portmap at reboot, e.g. 'chkconfig --level 345 portmap on'
why portmap/rpc must be started to use NFS? check out my blog article "understanding UNIX RPC in 1 minute!"
Thanks for viewing!