NFS(Network File System) is quite common protocol and still in demand, though even if Cluster File System is in popular and becomes familiar with every engineer. For example, it is sometimes necessary to use NFS, when replacing an old and on-premise system composed with NFS server and clients. I've been using NFS v3, but I will try v4 as it use static tcp 2049 port by default, which enables iptables less directives than that of v3.
I'll list how to setup NFS both v3 and v4, and also how to monitor both of them with nagios.
NFSv3
- connect NFS server using tcp
- use static ports
NFS Server
- install nfs-utils on NFS server and Client
# yum -y install nfs-utils nfs-utils-lib
/usr/local/src 192.168.100.0/24(rw,no_root_squash,sync)
- /etc/sysconfig/nfs fixing the daemons' ports
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662
-A INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 111 -j ACCEPT
-A INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT
-A INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 662 -j ACCEPT
-A INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 892 -j ACCEPT
-A INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 32803 -j ACCEPT
# chkconfig iptables on
# /etc/init.d/iptables start
# for daemons in \
portmap \
nfslock \
nfs ; do
/etc/init.d/$daemons start
done
- verify the ports are static
# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 941 rquotad
100011 2 udp 941 rquotad
100011 1 tcp 944 rquotad
100011 2 tcp 944 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100021 1 udp 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32803 nlockmgr
100021 3 tcp 32803 nlockmgr
100021 4 tcp 32803 nlockmgr
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100005 1 udp 892 mountd
100005 1 tcp 892 mountd
100005 2 udp 892 mountd
100005 2 tcp 892 mountd
100005 3 udp 892 mountd
100005 3 tcp 892 mountd
100024 1 udp 662 status
100024 1 tcp 662 status
- add daemons to start up automatically
# for daemons in \
portmap \
nfslock \
nfs ; do
chkconfig $daemons on ; done
NFS Client
# for daemons in ¥
netfs ¥
portmap ; do /etc/init.d/$daemons start ; done
# mount -o tcp -t nfs 192.168.100.196:/usr/local/src/ /usr/local/src/
# mount | grep '/usr/local/src'
192.168.100.196:/usr/local/src/ on /usr/local/src type nfs (rw,tcp,addr=192.168.100.196)
192.168.100.196:/usr/local/src /usr/local/src nfs defaults,tcp 0 0
# mount -a
# mount | grep '/usr/local/src'
192.168.100.196:/usr/local/src on /usr/local/src type nfs (rw,tcp,addr=192.168.100.196)
- add daemon to start up automatically
# for daemons in ¥
portmap ¥
netfs ; do chkconfig $daemons on ; done
NFSv4
- install nfs-utils on NFS server and Client
# yum -y install nfs-utils nfs-ntils-lib
NFS Server
/usr/local/src 192.168.100.0/24(rw,no_root_squash,sync,fsid=0)
Note: use the same configuration(idamapd.conf) on both NFS Server and Client.
[General]
Verbosity = 1
Pipefs-Directory = /var/lib/nfs/rpc_pipefs
Domain = localdomain
[Mapping]
Nobody-User = nobody
Nobody-Group = nobody
[Translation]
Method = nsswitch
- /etc/sysconfig/nfs, specify available NFS version
Note: it will fail to start up NFS mountd, when disabling NFS version 1 to 3(MOUNTD_NFS_V3=no).
It is necessary to disable version 1 and 2 only.
MOUNTD_NFS_V1=no ; disable NFSv1
MOUNTD_NFS_V2=no ; disable NFSv2
RQUOTAD=no ; disable rpc.rquotad
RPCNFSDARGS='-N 2 -N 3 -U' ; disable NFSv2/v3 for rpc.nfsd, use tcp as the listening port
-A INPUT -i eth1 -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT
# /etc/init.d/iptables start
# for daemons in \
rpcidmapd \
portmap \
nfs ; do
/etc/init.d/$daemons start ; done
RPC idmapd を起動中: [ OK ]
portmap を起動中: [ OK ]
NFS サービスを起動中: [ OK ]
NFS デーモンを起動中: [ OK ]
NFS mountd を起動中: [ OK ]
# exportfs -v
/usr/local/src 192.168.100.0/24(rw,wdelay,no_root_squash,no_subtree_check,fsid=0,anonuid=65534,anongid=65534
- verify the RPC program running
# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 662 status
100024 1 tcp 662 status
100011 1 udp 978 rquotad
100011 2 udp 978 rquotad
100011 1 tcp 981 rquotad
100011 2 tcp 981 rquotad
100003 4 tcp 2049 nfs
100021 1 udp 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32803 nlockmgr
100021 3 tcp 32803 nlockmgr
100021 4 tcp 32803 nlockmgr
100005 3 udp 646 mountd
100005 3 tcp 649 mountd
- add daemon to start up automatically
# for daemons in \
rpcidmapd \
portmap \
nfs ; do
chkconfg $daemons on ; done
NFS Client
- start up netfs, rpcidmapd
# for daemons in ¥
netfs ¥
rpcidmapd ; do /etc/init.d/$daemons start ; done
# mount -vv -t nfs4 192.168.100.196:/ /usr/local/src/
mount: pinging: prog 100003 vers 4 prot tcp port 2049
# mount | grep '/usr/local/src'
ha-mgr01.forschooner.net:/ on /usr/local/src type nfs4 (rw,addr=192.168.100.196)
- verify reading, writing and deleting files on mount point
# echo "test" > /usr/local/src/test.txt
# cat /usr/local/src/test.txt
test
# rm -f /usr/local/src/test.txt
192.168.100.196:/ /usr/local/src nfs4 defaults 0 0
# mount -a
# mount | grep '/usr/local/src'
192.168.100.196:/ on /usr/local/src type nfs4 (rw,addr=192.168.100.196)
- add daemon to start up automatically
# for daemons in \
netfs ¥
rpcidmapd \
portmap ; do chkconfig $daemons on ; done
Next, I'm showing the examples of NFSv3/v4 server and client with nagios-plugins.
No comments:
Post a Comment