Zookeeper ipv6的坑

問題

zookeeper拋這樣的錯誤:

 [main-SendThread(localhost:2000)] ERROR org.apache.zookeeper.ClientCnxn  - Unable to open socket to localhost/0:0:0:0:0:0:0:1:2181
4549 [main-SendThread(localhost:2000)] WARN  org.apache.zookeeper.ClientCnxn  - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.SocketException: Address family not supported by protocol family: connect
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:532)
    at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1071)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1104)

注意到

localhost/0:0:0:0:0:0:0:1

localhost被翻譯成了0:0:0:0:0:0:0:1。

打開/etc/hosts,可以看到127.0.0.1和::1都有localhost的配置:
這裏寫圖片描述

顯然在打開ipv6的情況下,localhost的值被後者覆蓋了,所以zk拋錯了。

解決

兩個簡單的解決方案:
1. 關閉ipv6。
2. 在hosts裏,把::1對應的localhost改個別名,比如localhost-ipv6。

全文完 :)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章