1. 程式人生 > >ipv6禁用導致rpcbind服務啟動失敗實例

ipv6禁用導致rpcbind服務啟動失敗實例

evel bsp oot 參考 cal .so systemd 開始 實例

ipv6禁用導致rpcbind服務啟動失敗實例

昨天在做服務器磁盤分區擴容的時候出現過一個服務啟動的問題,在此記錄。
情景再現:前天晚上申請做磁盤擴容,得到批準後,昨天早上5點開始做停機調整維護,歷經2個多小時的折騰,擴充完畢,有關這部分內容請參考上篇博文 ( https://blog.51cto.com/hld1992/2054837) 而後重啟機器,檢查服務,nginx,php-fpm,redis,svn,nfs(?)都啟動正常。然後,去另一臺機器上掛載nfs,問題出現了,nfs無響應。回來檢查nfs服務:
技術分享圖片
好嘛,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裏面了。

ipv6禁用導致rpcbind服務啟動失敗實例