Zookeeper ipv6 pitfalls
Problem
Zookeeper throws the following error:
[main-SendThread(localhost:2000)] ERROR org.apache.zookeeper.ClientCnxn - Unable to open socket to localhost/0:0:0:0:0:0:0:1:21814549 [main-SendThread(localhost:2000)] WARN org.apache.zookeeper.ClientCnxn - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnectjava.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)
Notes
localhost/0:0:0:0:0:0:0:1
Localhost is translated into 0: 0: 0: 0: 0: 0: 0: 1.
Open/etc/hosts and you can see that both 127.0.0.1 and: 1 have the localhost Configuration:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwPjxjb2RlIGNsYXNzPQ = "hljs avrasm"> Obviously, when ipv6 is enabled, the value of localhost is overwritten by the latter, so zk throws an error.
Solution
Two simple solutions:
1. Disable ipv6.
2. In hosts, change the localhost: 1 to an alias, such as localhost-ipv6.