昨天在做服务器磁盘分区扩容的时候出现过一个服务启动的问题,在此记录。
情景再现:前天晚上申请做磁盘扩容,得到批准后,昨天早上5点开始做停机调整维护,历经2个多小时的折腾,扩充完毕,有关这部分内容请参考上篇博文 ( https://blog.51cto.com/hld1992/2054837) 而后重启机器,检查服务,nginx,php-fpm,redis,svn,nfs(?)都启动正常。然后,去另一台机器上挂载nfs,问题出现了,nfs无响应。回来检查nfs服务:
ipv6禁用导致rpcbind服务启动失败实例
好嘛,rpcbind服务没有启动,赶紧启动服务。

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

报错了,根据提示使用journalctl -xe看一下日志:

[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.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

果然ipv6被禁用了。由于当时情况紧急,我采取了一个比较不好的方法,把ipv6启用了(后面还有其他方法介绍)。

[root@BZ ~]# sed -i 's@net.ipv6.conf.all.disable_ipv6 = 1@net.ipv6.conf.all.disable_ipv6 = 0@g' /etc/sysctl.conf
[root@BZ ~]# sysctl -p 
...
net.ipv6.conf.all.disable_ipv6 = 0

再次启动rpcbind

[root@BZ ~]# systemctl start rpcbind 
[root@BZ ~]# systemctl status rpcbind 
● rpcbind.service - RPC bind service
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; indirect; vendor preset: enabled)
   Active: active (running) since Tue 2017-12-26 21:48:22 EST; 7s ago
  Process: 2734 ExecStart=/sbin/rpcbind -w $RPCBIND_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 2735 (rpcbind)
   CGroup: /system.slice/rpcbind.service
           └─2735 /sbin/rpcbind -w

Dec 26 21:48:22 BZ systemd[1]: Starting RPC bind service...
Dec 26 21:48:22 BZ systemd[1]: Started RPC bind service.

启动成功。再启动nfs

[root@BZ ~]# systemctl start  nfs 
[root@BZ ~]# systemctl status nfs 
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: active (exited) since Tue 2017-12-26 21:50:05 EST; 996ms ago
  Process: 2761 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 2756 ExecStartPre=/bin/sh -c /bin/kill -HUP `cat /run/gssproxy.pid` (code=exited, status=0/SUCCESS)
  Process: 2755 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 2761 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

Dec 26 21:50:05 BZ systemd[1]: Starting NFS server and services...
Dec 26 21:50:05 BZ systemd[1]: Started NFS server and services.

再次去客户端挂载nfs就可以成功了。

========================================================================
刚才说了,启动ipv6当然不是一个好的方法,下面来继续说明下。
从前面的报错日志中我们可以看到,rpcbind.service依赖rpcbind.socket

    -- Unit rpcbind.socket has failed.

既然rpcbind.socket启动失败,那应该在它的配置文件中会有关于ipv6的配置,我来找一下:

    [root@BZ ~]# find /etc/ -name '*rpcbind.socket*'
  /etc/systemd/system/sockets.target.wants/rpcbind.socket

进去看下:

[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

将关于ipv6的相关配置注释后,重启rpcbind.socket

[root@BZ ~]# systemctl restart rpcbind.socket
Warning: rpcbind.socket changed on disk. Run 'systemctl daemon-reload' to reload units.

systemd发现配置文件有改动,需要重载一下。

[root@BZ ~]# systemctl daemon-reload

再次重启

[root@BZ ~]# systemctl restart rpcbind.socket
[root@BZ ~]# systemctl status rpcbind.socket
● rpcbind.socket - RPCbind Server Activation Socket
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.socket; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-12-26 22:01:45 EST; 9s ago
   Listen: /var/run/rpcbind.sock (Stream)
           0.0.0.0:111 (Stream)            #只监听了ipv4的111端口

后记

在谷歌的过程中,发现还有一种方法来解决这个问题。具体就是使用dracut -v -f 命令重建下initramfs,然后重启机器即可。
还有一个问题就是rpcbind设置开机自启动失败

[root@BZ ~]# systemctl enable rpcbind.service
[root@BZ ~]# systemctl is-enabled rpcbind.service
indirect

不知道是什么原因,希望有大神可以帮我解答啊,万分感谢,我现在是把它放到了/etc/rc.d/rc.local里面了。