这几天遇到linux开启iptabable,挂载nfs出现拒绝情况,查看网上都说的挺繁琐,先归类总结一下。
一、配置nfs需要安装的软件包:
nfs-utils-lib-1.0.8-7.9.el5 nfs-utils-1.0.9-60.el5 nfs-utils-lib-devel-1.0.8-7.9.el5 portmap-4.0-65.2.2.1 (安装的时候可以用yum库来安装,会智能安装所需的依赖包)二、配置nfs共享文件:
1、开启portmap服务:service portmap start; 2、修改配置文件/etc/sysconfig/nfs:删除MOUNTD_PORT=892前面的#号 3、添加需要的共享文件/etc/exports: 例如:/first *(rw,sync,no_root_squash) 4、启动nfs服务:service nfs start; 5、命令查看nfs使用的端口:netstat -nultp portmap(111端口),nfs(2049端口),nfs挂载端口(892端口),其中111和892是tcp,udp都用。 6、添加防火墙策略: iptables -I INPUT -p tcp -m multiport --dports 111,892,2049 -j ACCEPT iptables -I INPUT -p udp -m multiport --dports 111,892 -j ACCEPT (当然,防火墙出口也需要添加这些策略)三、客户端挂在nfs共享:
1、查看服务器共享目录:showmount -e 服务器ip; 2、挂载服务器共享目录:mount -t nfs server-ip:/first 本地目录四、相关问题以及解决方案:
1、NFS服务启动失败:Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refusedrpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).[FAILED] 解决方法:没有启动portmap,将portmap启动即可。 2、客户端showmount报错: mount clntudp_create: RPC: Port mapper failure - RPC: Unable to receive 解决方法:没有打开配置文件中的892端口或者是防火墙禁止了tcp协议的892端口,修改配置文件,启用892端口并且防火墙允许tcp端口892通过。 3、可以showmount看到共享,可是mount的时候报错: mount: mount to NFS server 'server-ip' failed: timed out (retrying). 解决方法:没有将892或者111端口的udp协议允许。添加iptables策略允许相应端口通过。 4、可以showmount看到共享,可是mount的时候报错: mount: mount to NFS server 'server-ip' failed: System Error: Connection refused. 解决方法:没有允许tcp协议2094或者111端口通过,添加iptables策略允许响应端口通过。