【NFS】NFS设置固定端口,添加防火墙规则

NFS server启动时会随机启动多个端口并向RPC注册,这样如果使用iptables对NFS sever 端口进行限制就会有点麻烦,可以更改配置文件固定NFS服务相关端口。

以前配置的nfs端口一直是通过rpcinfo xx.xx.xx.xx 这个命令查找到需要放行的端口,然后在防火墙中放行这个端口,每次f服务器断电重启之后,都需要重新设置防火墙,我们可以设置固定端口,这样设置固定端口以后即便重启机器也很方便挂载,如果不设置固定端口,机器或服务重启后之前添加的iptables规则就失效了!

6624809-6cc4646502aa5bb6.png

下面的是没有设置固定端口时的情况:

# rpcinfo  -p

# rpcinfo nfs_sever_ip


12979420-a513fb5ccb797366.png

设置固定端口:

编辑 /etc/sysconfig/nfs 文件:

#  vim    /etc/sysconfig/nfs

添加如下内容:

###################

扫描二维码关注公众号,回复: 5207026 查看本文章

RQUOTAD_PORT=30001

LOCKD_TCPPORT=30002

LOCKD_UDPPORT=30002

MOUNTD_PORT=30003

STATD_PORT=30004

###################


12979420-085d4948538cc330.png

如果 nlockmgr Port 仍然无法修改,则要修改 /etc/sysctl.conf

# cp /etc/sysctl.conf /etc/sysctl.conf.$(date +%F)

fs.nfs.nlm_tcpport=30002

fs.nfs.nlm_udpport=30002

# sed -i '$a fs.nfs.nlm_tcpport=30002\nfs.nfs.nlm_udpport=30002' /etc/sysctl.conf

刷新配置生效:

# sysctl -p

# systemctl restart rpcbind 

# systemctl restart nfs-server 

# systemctl restart nfs-lock 

# systemctl restart nfs-idmap

重启服务后再查看端口:


12979420-80969f571ea03c33.png

添加iptables规则:

# yum -y install iptables iptables-services

命令行添加:

# iptables  -A INPUT -p tcp -m tcp  --dport 111 -j ACCEPT

# iptables  -A INPUT -p udp -m udp  --dport 111 -j ACCEPT

# iptables  -A INPUT -p tcp -m tcp  --dport 2049 -j ACCEPT

# iptables  -A INPUT -p udp -m udp  --dport 2049 -j ACCEPT

# iptables  -A INPUT -p tcp -m tcp    --dport 30001:30004 -j ACCEPT

# iptables  -A INPUT -p udp -m udp  --dport 30001:30004 -j ACCEPT

配置文件添加:

# vim /etc/iptables.rules

6624809-0467bdd652fc8834.png


保存防火墙规则:

# systemctl  restart    iptables

查看防火墙规则:

# iptables -nvL --line

6624809-b18cd8961f2901bc.png

Red Hat Enterprise Linux7/Storage Administration/Network File System (NFS)

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/ch-nfs#s2-nfs-how-daemons

6624809-6405919da79d37e7.png

实际测试中发现,上述操作需要reboot才能生效!

###################################################

用nfs来存储文件,在客户端节点遇到了问题,用df -h的时候系统直接就卡住了。

搜索发现,网上好多遇到这种问题的。

原来是nfs的server其实已经挂了,但是客户端还存在。所以会出现这种情况!

以前开发时就碰到过nfs客户端卡住的情况,umount -f /mnt umount -l /mnt 提示device is busy,并且尝试访问挂载目录、df -h等操作都会使终端卡住,ctrl+c也不能强行退出。

造成这种现象的原因是nfs服务器/网络挂了,nfs客户端默认采用hard-mount选项,而不是soft-mount。

两者的区别是:

soft-mount: 当客户端加载NFS不成功时,重试retrans设定的次数.如果retrans次都不成功,则放弃此操作,返回错误信息 "Connect time out"

hard-mount: 当客户端加载NFS不成功时,一直重试,直到NFS服务器有响应。hard-mount 是系统的缺省值。在选定hard-mount 时,最好同时选 intr , 允许中断系统的调用请求,避免引起系统的挂起。当NFS服务器不能响应NFS客户端的 hard-mount请求时, NFS客户端会显示:"NFS server hostname not responding, still trying"

参考

NFS/Troubleshooting (简体中文)

https://wiki.archlinux.org/index.php/NFS/Troubleshooting_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

运维安全之NFS安全

http://drops.xmd5.com/static/drops/tips-1423.html

NFSv3 NFSv3针对防火墙端口开通策略

http://blog.51cto.com/limaomao/1963933

NFS设置固定端口并添加防火墙规则

https://www.centos.bz/2017/12/nfs%E8%AE%BE%E7%BD%AE%E5%9B%BA%E5%AE%9A%E7%AB%AF%E5%8F%A3%E5%B9%B6%E6%B7%BB%E5%8A%A0%E9%98%B2%E7%81%AB%E5%A2%99%E8%A7%84%E5%88%99/

运维安全之NFS安全

http://drops.xmd5.com/static/drops/tips-1423.html

猜你喜欢

转载自blog.csdn.net/weixin_33769125/article/details/87230946