nfs-server 地址
    10.82.100.250 prod-server01
    10.82.100.252 prod-server02

    1. [root@td-stage-app16 ~]# rpm -qa nfs-utils
    2. nfs-utils-1.3.0-0.48.el7.x86_64
    3. [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

    1. cat >> /etc/hosts.allow << EOF
    2. mountd:10.82.100.108
    3. 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)

    1. cat >> /etc/exports << EOF
    2. /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)
    3. EOF

    image.png
    3:刷新nfs-server共享目录

    1. [root@prod-nfs-server02 ~]# exportfs -rv
    2. exporting 10.82.100.108:/data/lttsdata
    3. [root@prod-nfs-server02 ~]# showmount -e 10.82.100.252
    4. Export list for 10.82.100.252:
    5. /data/lttsdata 10.82.100.108
    6. [root@prod-nfs-server02 ~]#

    客户端操作

    4:创建挂载目录和添加开机挂载脚本

    1. mkdir -p /opt/scripts/
    2. mkdir -p /data
    3. echo "mount 10.82.100.250:/data/lttsdata /data" >> /opt/scripts/mount.sh
    4. chmod +x /opt/scripts/mount.sh
    5. echo "/opt/scripts/mount.sh" >> /etc/rc.local
    6. chmod +x /etc/rc.local
    7. chmod +x /etc/rc.d/rc.local
    8. cd /opt/scripts
    9. sh mount.sh
    10. df -TH

    NFS 固定端口
    nfs除了主程序端口2049和rpcbind的端口111是固定,还会使用一些随机端口,以下配置将定义这些端口,以便配置防火墙

    1. [root@rancher-server ~]# rpcinfo -p
    2. program vers proto port service
    3. 100000 4 tcp 111 portmapper
    4. 100000 3 tcp 111 portmapper
    5. 100000 2 tcp 111 portmapper
    6. 100000 4 udp 111 portmapper
    7. 100000 3 udp 111 portmapper
    8. 100000 2 udp 111 portmapper
    9. 100024 1 udp 4002 status
    10. 100024 1 tcp 4002 status
    11. 100005 1 udp 4001 mountd
    12. 100005 1 tcp 4001 mountd
    13. 100005 2 udp 4001 mountd
    14. 100005 2 tcp 4001 mountd
    15. 100005 3 udp 4001 mountd
    16. 100005 3 tcp 4001 mountd
    17. 100003 3 tcp 2049 nfs
    18. 100003 4 tcp 2049 nfs
    19. 100227 3 tcp 2049 nfs_acl
    20. 100003 3 udp 2049 nfs
    21. 100003 4 udp 2049 nfs
    22. 100227 3 udp 2049 nfs_acl
    23. 100021 1 udp 4003 nlockmgr
    24. 100021 3 udp 4003 nlockmgr
    25. 100021 4 udp 4003 nlockmgr
    26. 100021 1 tcp 4003 nlockmgr
    27. 100021 3 tcp 4003 nlockmgr
    28. 100021 4 tcp 4003 nlockmgr
    29. [root@rancher-server ~]#
    1. [root@rancher-server ~]# netstat -lntup
    2. Active Internet connections (only servers)
    3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    4. tcp 0 0 127.0.0.1:1514 0.0.0.0:* LISTEN 2055/docker-proxy
    5. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 636/rpcbind
    6. tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 22116/docker-proxy
    7. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2022/docker-proxy
    8. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 956/sshd
    9. tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1997/docker-proxy
    10. tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
    11. tcp 0 0 0.0.0.0:4001 0.0.0.0:* LISTEN 6764/rpc.mountd
    12. tcp 0 0 0.0.0.0:4002 0.0.0.0:* LISTEN 6762/rpc.statd
    13. tcp 0 0 0.0.0.0:4003 0.0.0.0:* LISTEN -
    14. tcp6 0 0 :::111 :::* LISTEN 636/rpcbind
    15. tcp6 0 0 :::22 :::* LISTEN 956/sshd
    16. tcp6 0 0 :::2049 :::* LISTEN -
    17. tcp6 0 0 :::4001 :::* LISTEN 6764/rpc.mountd
    18. tcp6 0 0 :::4002 :::* LISTEN 6762/rpc.statd
    19. tcp6 0 0 :::4003 :::* LISTEN -
    20. udp 0 0 0.0.0.0:4001 0.0.0.0:* 6764/rpc.mountd
    21. udp 0 0 0.0.0.0:4002 0.0.0.0:* 6762/rpc.statd
    22. udp 0 0 0.0.0.0:4003 0.0.0.0:* -
    23. udp 0 0 0.0.0.0:2049 0.0.0.0:* -
    24. udp 0 0 0.0.0.0:111 0.0.0.0:* 636/rpcbind
    25. udp 0 0 127.0.0.1:323 0.0.0.0:* 666/chronyd
    26. udp 0 0 0.0.0.0:808 0.0.0.0:* 636/rpcbind
    27. udp 0 0 127.0.0.1:1002 0.0.0.0:* 6762/rpc.statd
    28. udp6 0 0 :::4001 :::* 6764/rpc.mountd
    29. udp6 0 0 :::4002 :::* 6762/rpc.statd
    30. udp6 0 0 :::4003 :::* -
    31. udp6 0 0 :::2049 :::* -
    32. udp6 0 0 :::111 :::* 636/rpcbind
    33. udp6 0 0 ::1:323 :::* 666/chronyd
    34. udp6 0 0 :::808 :::* 636/rpcbind
    35. [root@rancher-server ~]#
    1. # cat /etc/sysconfig/nfs
    2. #追加端口配置
    3. MOUNTD_PORT=4001  
    4. STATD_PORT=4002
    5. LOCKD_TCPPORT=4003
    6. LOCKD_UDPPORT=4003
    7. RQUOTAD_PORT=4004
    1. [root@rancher-server ~]# cat /etc/sysconfig/nfs
    2. #
    3. # Note: For new values to take effect the nfs-config service
    4. # has to be restarted with the following command:
    5. # systemctl restart nfs-config
    6. #
    7. # Optional arguments passed to in-kernel lockd
    8. #LOCKDARG=
    9. # TCP port rpc.lockd should listen on.
    10. #LOCKD_TCPPORT=32803
    11. # UDP port rpc.lockd should listen on.
    12. #LOCKD_UDPPORT=32769
    13. #
    14. # Optional arguments passed to rpc.nfsd. See rpc.nfsd(8)
    15. RPCNFSDARGS=""
    16. # Number of nfs server processes to be started.
    17. # The default is 8.
    18. #RPCNFSDCOUNT=16
    19. #
    20. # Set V4 grace period in seconds
    21. #NFSD_V4_GRACE=90
    22. #
    23. # Set V4 lease period in seconds
    24. #NFSD_V4_LEASE=90
    25. #
    26. # Optional arguments passed to rpc.mountd. See rpc.mountd(8)
    27. RPCMOUNTDOPTS=""
    28. # Port rpc.mountd should listen on.
    29. #MOUNTD_PORT=892
    30. #
    31. # Optional arguments passed to rpc.statd. See rpc.statd(8)
    32. STATDARG=""
    33. # Port rpc.statd should listen on.
    34. #STATD_PORT=662
    35. # Outgoing port statd should used. The default is port
    36. # is random
    37. #STATD_OUTGOING_PORT=2020
    38. # Specify callout program
    39. #STATD_HA_CALLOUT="/usr/local/bin/foo"
    40. #
    41. #
    42. # Optional arguments passed to sm-notify. See sm-notify(8)
    43. SMNOTIFYARGS=""
    44. #
    45. # Optional arguments passed to rpc.idmapd. See rpc.idmapd(8)
    46. RPCIDMAPDARGS=""
    47. #
    48. # Optional arguments passed to rpc.gssd. See rpc.gssd(8)
    49. # Note: The rpc-gssd service will not start unless the
    50. # file /etc/krb5.keytab exists. If an alternate
    51. # keytab is needed, that separate keytab file
    52. # location may be defined in the rpc-gssd.service's
    53. # systemd unit file under the ConditionPathExists
    54. # parameter
    55. RPCGSSDARGS=""
    56. #
    57. # Enable usage of gssproxy. See gssproxy-mech(8).
    58. GSS_USE_PROXY="yes"
    59. #
    60. # Optional arguments passed to blkmapd. See blkmapd(8)
    61. BLKMAPDARGS=""
    62. [root@rancher-server ~]#
    1. [root@rancher-server ~]# cp /etc/sysconfig/nfs{,.bak}
    2. [root@rancher-server ~]# cat /etc/sysconfig/nfs.bak|grep -v ^# >> /etc/sysconfig/nfs
    3. [root@rancher-server ~]# cat MOUNTD_PORT=4001  
    4. STATD_PORT=4002
    5. LOCKD_TCPPORT=4003
    6. LOCKD_UDPPORT=4003
    7. RQUOTAD_PORT=4004
    8. RPCNFSDARGS=""
    9. RPCMOUNTDOPTS=""
    10. STATDARG=""
    11. SMNOTIFYARGS=""
    12. RPCIDMAPDARGS=""
    13. RPCGSSDARGS=""
    14. GSS_USE_PROXY="yes"
    15. BLKMAPDARGS=""
    16. [root@rancher-server ~]#
    1. cat >> /etc/sysconfig/nfs << EOF
    2. MOUNTD_PORT=4001  
    3. STATD_PORT=4002
    4. LOCKD_TCPPORT=4003
    5. LOCKD_UDPPORT=4003
    6. RQUOTAD_PORT=4004
    7. EOF

    确认最终配置文件

    1. [root@rancher-server ~]# cat /etc/sysconfig/nfs
    2. RPCNFSDARGS="-N 4"
    3. RPCMOUNTDOPTS=""
    4. STATDARG=""
    5. SMNOTIFYARGS=""
    6. RPCIDMAPDARGS=""
    7. RPCGSSDARGS=""
    8. GSS_USE_PROXY="yes"
    9. BLKMAPDARGS=""
    10. MOUNTD_PORT=4001  
    11. STATD_PORT=4002
    12. LOCKD_TCPPORT=4003
    13. LOCKD_UDPPORT=4003
    14. RQUOTAD_PORT=4004
    15. [root@rancher-server ~]#