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。
全文完 :)
原文地址:http://blog.csdn.net/pelick/article/details/45968941