昨天下午有部分生产机器无法启动nfs服务;报错很是奇怪。于是一路顺藤摸瓜发现是rpcbind没能正常启动导致的nfs没能起来。

后来总结了两种办法:主要是ipv6的问题所导致的。

措施一:

报错内容

[root@BZ ~]# systemctl start rpcbind 
    A dependency job for rpcbind.service failed. See 'journalctl -xe' for details.

查看错误
[root@BZ ~]# journalctl -xe
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-3.scope has begun starting up.
Dec 26 21:34:26 BZ chronyd[490]: System clock wrong by -1.090838 seconds, adjustment started
Dec 26 21:35:31 BZ chronyd[490]: Selected source 61.216.153.107
Dec 26 21:35:31 BZ chronyd[490]: System clock wrong by 0.646329 seconds, adjustment started
Dec 26 21:36:24 BZ polkitd[484]: Registered Authentication Agent for unix-process:2701:32282 (system bus name :1.29 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Dec 26 21:36:24 BZ systemd[1]: rpcbind.socket failed to listen on sockets: Address family not supported by protocol                                        #报错显示ip地址协议不支持
Dec 26 21:36:24 BZ systemd[1]: Failed to listen on RPCbind Server Activation Socket.         #端口监听失败
-- Subject: Unit rpcbind.socket has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit rpcbind.socket has failed.
-- 
-- The result is failed
Dec 26 21:36:24 BZ systemd[1]: Dependency failed for RPC bind service.
于是谷歌看了一下;发现是ipv6没开启导致的;修改/etc/sysctl.d/sysctl.conf
[root@BZ ~]# less /etc/sysctl.conf | grep 'net.ipv6'
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
[root@BZ ~]# sysctl -p          #重新加载一下配置;临时生效
[root@BZ ~]# systemctl start rpcbind    #重启rpcbind服务
[root@BZ ~]# systemctl start nfs      #重启nfs服务
再挂载nfs文件就ok了。

措施二:

 

    [root@BZ ~]# find /etc/ -name '*rpcbind.socket*'


找到这个socket文件,并用vim编译器编辑它。
[Unit]
Description=RPCbind Server Activation Socket

[Socket]
ListenStream=/var/run/rpcbind.sock
ListenStream=[::]:111                                #果然监听了ipv6地址,将这一行注释即可
ListenStream=0.0.0.0:111
BindIPv6Only=ipv6-only

[Install]
WantedBy=sockets.target
重载一下再启动
[root@BZ ~]# systemctl daemon-reload
[root@BZ ~]# systemctl restart rpcbind.socket
[root@BZ ~]# systemctl start nfs
再挂载远程nfs即可。


一步到位脚本
a=`find /etc/ -name '*rpcbind.socket*'`
sed -i 's/ListenStream=\[::\]:111/\#ListenStream=[::]:111/g' $a
systemctl daemon-reload
systemctl restart rpcbind.socket
systemctl start nfs