nfs-server 地址
10.82.100.250 prod-server01
10.82.100.252 prod-server02
[root@td-stage-app16 ~]# rpm -qa nfs-utils
nfs-utils-1.3.0-0.48.el7.x86_64
[root@td-stage-app16 ~]#
任务:10.82.100.108 /data 挂载到 10.82.100.252:/data/lttsdata
客户端地址:10.82.100.108
1:在nfs服务器端/etc/hosts.allow追加客户端连接地址IP
cat >> /etc/hosts.allow << EOF
mountd:10.82.100.108
EOF
2:编写共享挂载点 固定用户ID和组ID
/data/lttsdata 10.82.100.217(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=310,anongid=310)
cat >> /etc/exports << EOF
/data/lttsdata 10.82.100.108(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=310,anongid=310)
EOF
3:刷新nfs-server共享目录
[root@prod-nfs-server02 ~]# exportfs -rv
exporting 10.82.100.108:/data/lttsdata
[root@prod-nfs-server02 ~]# showmount -e 10.82.100.252
Export list for 10.82.100.252:
/data/lttsdata 10.82.100.108
[root@prod-nfs-server02 ~]#
客户端操作
4:创建挂载目录和添加开机挂载脚本
mkdir -p /opt/scripts/
mkdir -p /data
echo "mount 10.82.100.250:/data/lttsdata /data" >> /opt/scripts/mount.sh
chmod +x /opt/scripts/mount.sh
echo "/opt/scripts/mount.sh" >> /etc/rc.local
chmod +x /etc/rc.local
chmod +x /etc/rc.d/rc.local
cd /opt/scripts
sh mount.sh
df -TH
NFS 固定端口
nfs除了主程序端口2049和rpcbind的端口111是固定,还会使用一些随机端口,以下配置将定义这些端口,以便配置防火墙
[root@rancher-server ~]# rpcinfo -p
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 4002 status
100024 1 tcp 4002 status
100005 1 udp 4001 mountd
100005 1 tcp 4001 mountd
100005 2 udp 4001 mountd
100005 2 tcp 4001 mountd
100005 3 udp 4001 mountd
100005 3 tcp 4001 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 4003 nlockmgr
100021 3 udp 4003 nlockmgr
100021 4 udp 4003 nlockmgr
100021 1 tcp 4003 nlockmgr
100021 3 tcp 4003 nlockmgr
100021 4 tcp 4003 nlockmgr
[root@rancher-server ~]#
[root@rancher-server ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:1514 0.0.0.0:* LISTEN 2055/docker-proxy
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 636/rpcbind
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 22116/docker-proxy
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2022/docker-proxy
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 956/sshd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1997/docker-proxy
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:4001 0.0.0.0:* LISTEN 6764/rpc.mountd
tcp 0 0 0.0.0.0:4002 0.0.0.0:* LISTEN 6762/rpc.statd
tcp 0 0 0.0.0.0:4003 0.0.0.0:* LISTEN -
tcp6 0 0 :::111 :::* LISTEN 636/rpcbind
tcp6 0 0 :::22 :::* LISTEN 956/sshd
tcp6 0 0 :::2049 :::* LISTEN -
tcp6 0 0 :::4001 :::* LISTEN 6764/rpc.mountd
tcp6 0 0 :::4002 :::* LISTEN 6762/rpc.statd
tcp6 0 0 :::4003 :::* LISTEN -
udp 0 0 0.0.0.0:4001 0.0.0.0:* 6764/rpc.mountd
udp 0 0 0.0.0.0:4002 0.0.0.0:* 6762/rpc.statd
udp 0 0 0.0.0.0:4003 0.0.0.0:* -
udp 0 0 0.0.0.0:2049 0.0.0.0:* -
udp 0 0 0.0.0.0:111 0.0.0.0:* 636/rpcbind
udp 0 0 127.0.0.1:323 0.0.0.0:* 666/chronyd
udp 0 0 0.0.0.0:808 0.0.0.0:* 636/rpcbind
udp 0 0 127.0.0.1:1002 0.0.0.0:* 6762/rpc.statd
udp6 0 0 :::4001 :::* 6764/rpc.mountd
udp6 0 0 :::4002 :::* 6762/rpc.statd
udp6 0 0 :::4003 :::* -
udp6 0 0 :::2049 :::* -
udp6 0 0 :::111 :::* 636/rpcbind
udp6 0 0 ::1:323 :::* 666/chronyd
udp6 0 0 :::808 :::* 636/rpcbind
[root@rancher-server ~]#
# cat /etc/sysconfig/nfs
#追加端口配置
MOUNTD_PORT=4001
STATD_PORT=4002
LOCKD_TCPPORT=4003
LOCKD_UDPPORT=4003
RQUOTAD_PORT=4004
[root@rancher-server ~]# cat /etc/sysconfig/nfs
#
# Note: For new values to take effect the nfs-config service
# has to be restarted with the following command:
# systemctl restart nfs-config
#
# Optional arguments passed to in-kernel lockd
#LOCKDARG=
# TCP port rpc.lockd should listen on.
#LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
#LOCKD_UDPPORT=32769
#
# Optional arguments passed to rpc.nfsd. See rpc.nfsd(8)
RPCNFSDARGS=""
# Number of nfs server processes to be started.
# The default is 8.
#RPCNFSDCOUNT=16
#
# Set V4 grace period in seconds
#NFSD_V4_GRACE=90
#
# Set V4 lease period in seconds
#NFSD_V4_LEASE=90
#
# Optional arguments passed to rpc.mountd. See rpc.mountd(8)
RPCMOUNTDOPTS=""
# Port rpc.mountd should listen on.
#MOUNTD_PORT=892
#
# Optional arguments passed to rpc.statd. See rpc.statd(8)
STATDARG=""
# Port rpc.statd should listen on.
#STATD_PORT=662
# Outgoing port statd should used. The default is port
# is random
#STATD_OUTGOING_PORT=2020
# Specify callout program
#STATD_HA_CALLOUT="/usr/local/bin/foo"
#
#
# Optional arguments passed to sm-notify. See sm-notify(8)
SMNOTIFYARGS=""
#
# Optional arguments passed to rpc.idmapd. See rpc.idmapd(8)
RPCIDMAPDARGS=""
#
# Optional arguments passed to rpc.gssd. See rpc.gssd(8)
# Note: The rpc-gssd service will not start unless the
# file /etc/krb5.keytab exists. If an alternate
# keytab is needed, that separate keytab file
# location may be defined in the rpc-gssd.service's
# systemd unit file under the ConditionPathExists
# parameter
RPCGSSDARGS=""
#
# Enable usage of gssproxy. See gssproxy-mech(8).
GSS_USE_PROXY="yes"
#
# Optional arguments passed to blkmapd. See blkmapd(8)
BLKMAPDARGS=""
[root@rancher-server ~]#
[root@rancher-server ~]# cp /etc/sysconfig/nfs{,.bak}
[root@rancher-server ~]# cat /etc/sysconfig/nfs.bak|grep -v ^# >> /etc/sysconfig/nfs
[root@rancher-server ~]# cat MOUNTD_PORT=4001
STATD_PORT=4002
LOCKD_TCPPORT=4003
LOCKD_UDPPORT=4003
RQUOTAD_PORT=4004
RPCNFSDARGS=""
RPCMOUNTDOPTS=""
STATDARG=""
SMNOTIFYARGS=""
RPCIDMAPDARGS=""
RPCGSSDARGS=""
GSS_USE_PROXY="yes"
BLKMAPDARGS=""
[root@rancher-server ~]#
cat >> /etc/sysconfig/nfs << EOF
MOUNTD_PORT=4001
STATD_PORT=4002
LOCKD_TCPPORT=4003
LOCKD_UDPPORT=4003
RQUOTAD_PORT=4004
EOF
确认最终配置文件
[root@rancher-server ~]# cat /etc/sysconfig/nfs
RPCNFSDARGS="-N 4"
RPCMOUNTDOPTS=""
STATDARG=""
SMNOTIFYARGS=""
RPCIDMAPDARGS=""
RPCGSSDARGS=""
GSS_USE_PROXY="yes"
BLKMAPDARGS=""
MOUNTD_PORT=4001
STATD_PORT=4002
LOCKD_TCPPORT=4003
LOCKD_UDPPORT=4003
RQUOTAD_PORT=4004
[root@rancher-server ~]#