額,這東西都快把人搞崩潰了,各類排查各類正常。java
最後居然是由於我在客戶端未鏈接上zkserver的時候就進行了create操做形成的錯誤。apache
噗, spa
Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /servers/server at org.apache.zookeeper.KeeperException.create(KeeperException.java:99) at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:778) at com.example.test.zk.DistributeServer.registerServer(DistributeServer.java:44) at com.example.test.zk.DistributeServer.main(DistributeServer.java:66)
上面這樣的錯誤,在我隨便加了一個sleep操做,以後就正常了。code
以下:server
// Thread.sleep(10000); String create = zk.create(parentNode + "/server", hostname.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL); System.out.println(hostname + "is online.." + create);
哎, 賊耽誤工夫。blog