今天在本機安裝了三個zookeeper,分別爲server1,server2,server3。html
tickTime=2000 initLimit=5 syncLimit=2 dataDir=/Users/google/Work/Program/zookeeper/server1/zookeeper-3.4.6/data dataLogDir=/Users/google/Work/Program/zookeeper/server1/zookeeper-3.4.6/logs clientPort=4080 server.1=127.0.0.1:9991:7770 server.2=127.0.0.1:9992:7771 server.3=127.0.0.1:9993:7772
而後啓動了server3的zkServer.sh,用server1的zkCli.sh去鏈接,結果報了以下錯誤:java
2015-05-25 18:06:21,667 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:4083. Will not attempt to authenticate using SASL (java.lang.SecurityException: ????λ??¼????) JLine support is enabled 2015-05-25 18:06:21,678 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:4083, initiating session 2015-05-25 18:06:21,690 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@1098] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect [zk: 127.0.0.1:4083(CONNECTING) 0] 2015-05-25 18:06:23,045 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:4083. Will not attempt to authenticate using SASL (java.lang.SecurityException: ????λ??¼????) 2015-05-25 18:06:23,047 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:4083, initiating session 2015-05-25 18:06:23,048 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@1098] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2015-05-25 18:06:24,521 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:4083. Will not attempt to authenticate using SASL (java.lang.SecurityException: ????λ??¼????) 2015-05-25 18:06:24,522 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:4083, initiating session 2015-05-25 18:06:24,523 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@1098] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2015-05-25 18:06:25,942 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:4083. Will not attempt to authenticate using SASL (java.lang.SecurityException: ????λ??¼????) 2015-05-25 18:06:25,943 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:4083, initiating session 2015-05-25 18:06:25,944 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@1098] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2015-05-25 18:06:27,717 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:4083. Will not attempt to authenticate using SASL (java.lang.SecurityException: ????λ??¼????) 2015-05-25 18:06:27,717 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:4083, initiating session 2015-05-25 18:06:27,718 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@1098] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2015-05-25 18:06:29,608 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:4083. Will not attempt to authenticate using SASL (java.lang.SecurityException: ????λ??¼????) 2015-05-25 18:06:29,609 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:4083, initiating session 2015-05-25 18:06:29,610 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@1098] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect 2015-05-25 18:06:31,561 [myid:] - INFO [main-SendThread(127.0.0.1:4083):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:4083. Will not attempt to authenticate using SASL (java.lang.SecurityException: ????λ??¼????)
後來才搞明白,因爲我在zoo.cfg中配置了3臺機器,可是隻啓動了1臺,zookeeper就會認爲服務處於不可用狀態。算法
zookeeper有個選舉算法,當整個集羣超過半數機器宕機,zookeeper會認爲集羣處於不可用狀態。session
全部,3臺機器只啓動一臺沒法鏈接,若是啓動2臺及以上就能夠鏈接了。socket