前几天学习了下 NFS 服务配置,但之前没有使用固定 NFS 端口的方法,之后只能关闭防火墙实现NFS 配置,今天学习了下 NFS 服务固定端口的方法。
一 环境信息
NFS SERVER 192.168.1.26
NFS CLIENT 192.168.1.25
二 配置 NFS 服务端
2.1 修改 /etc/exports
1
  
 | 
/database/pgdata1/shared     192.168.1.25(rw,anonuid=500,anongid=500)
  
 | 
 
2.2 显示共享目录信息
1 2 3
  
 | 
[root@pgb sysconfig]# exportfs -v /database/pgdata1/shared                 192.168.1.25(rw,wdelay,root_squash,no_subtree_check,anonuid=500,anongid=500)
  
 | 
 
2.3 修改 /etc/sysconfig/nfs 文件
1 2 3 4
  
 | 
MOUNTD_PORT="4002" STATD_PORT="4003" LOCKD_TCPPORT="4004" LOCKD_UDPPORT="4004"
  
 | 
 
备注:NFS 服务配置过程中,其中 mountd, statd 和 lockd 进程可以使用固定端口号。
2.4 显示RPC信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  
 | 
[root@pgb sysconfig]    program vers proto   port     100000    2   tcp    111  portmapper     100000    2   udp    111  portmapper     100024    1   udp    923  status     100024    1   tcp    926  status     100011    1   udp    927  rquotad     100011    2   udp    927  rquotad     100011    1   tcp    930  rquotad     100011    2   tcp    930  rquotad     100003    2   udp   2049  nfs     100003    3   udp   2049  nfs     100003    4   udp   2049  nfs     100021    1   udp   4004  nlockmgr     100021    3   udp   4004  nlockmgr     100021    4   udp   4004  nlockmgr     100021    1   tcp   4004  nlockmgr     100021    3   tcp   4004  nlockmgr     100021    4   tcp   4004  nlockmgr     100003    2   tcp   2049  nfs     100003    3   tcp   2049  nfs     100003    4   tcp   2049  nfs     100005    1   udp   4002  mountd     100005    1   tcp   4002  mountd     100005    2   udp   4002  mountd     100005    2   tcp   4002  mountd     100005    3   udp   4002  mountd     100005    3   tcp   4002  mountd
  
 | 
 
2.5 修改防火墙,iptables 后面部分如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  
 | 
NFS:portmapper -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 111 -j ACCEPT NFS:nfsd -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 2049 -j ACCEPT NFS:mountd -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 4002 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 4002 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 4003 -j ACCEPT NFS:nlockmgr -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 4004 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 4004 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 781 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 778 -j ACCEPT -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT
  
 | 
 
2.6 重启防火墙
1 2 3 4 5 6
  
 | 
[root@pgb sysconfig]# service iptables restart Flushing firewall rules: [  OK  ] Setting chains to policy ACCEPT: filter [  OK  ] Unloading iptables modules: [  OK  ] Applying iptables firewall rules: [  OK  ] Loading additional iptables modules: ip_conntrack_netbios_ns [  OK  ]
  
 | 
 
三 配置 NFS 客户端
3.1 测试:mount 目录
1 2
  
 | 
[root@pg1 ~]# mkdir -p /mnt/pgb/shared [root@pg1 /]# mount -t nfs 192.168.1.26:/database/shared /mnt/pgb/shared/
  
 | 
 
3.2 查看目录信息
1 2 3 4 5 6 7 8
  
 | 
[postgres@pg1 pgb]$ df -hv Filesystem            Size  Used Avail Use% Mounted on /dev/hda1              14G   11G  2.1G  85% / tmpfs                 217M     0  217M   0% /dev/shm /dev/hdb3             1.9G   35M  1.8G   2% /archive/pga none                  217M  104K  217M   1% /var/lib/xenstored 192.168.1.26:/database/pgdata1/shared                       2.0G   34M  1.9G   2% /mnt/pgb/shared
  
 | 
 
 备注:NFS 配置成功。         
 3.3 设置开机自动挂载
修改 /etc/fstab 文件,增加以下行
1
  
 | 
192.168.1.26:/database/pgdata1/shared /mnt/pgb/shared   nfs     defaults,rw   0 0
  
 | 
 
                                                        原创文章,作者:1402239773,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/237832.html