ZooKeeper 启动成功但不工作

ZooKeeper start successfully but doesn't work

我正在尝试使用三个节点以完全分布式模式部署 zookeeper 整体。启动服务器后,jps 下没有任何条目。在给出 "zkServer.sh status" 时,输出是:

    JMX enabled by default
    Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
    Error contacting service. It is probably not running

给出命令 "zkCli.sh -server zks1:2181" 是:

Connecting to zks1:2181
2015-05-24 23:02:24,602 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2015-05-24 23:02:24,605 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=mtech2-OptiPlex-7010
2015-05-24 23:02:24,606 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_79
2015-05-24 23:02:24,607 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2015-05-24 23:02:24,607 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-7-openjdk-amd64/jre
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/zookeeper/bin/../conf:
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.75
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=hduser
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/hduser
2015-05-24 23:02:24,608 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/usr/local/zookeeper
2015-05-24 23:02:24,609 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=zks1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@634fd55e
Welcome to ZooKeeper!
2015-05-24 23:02:24,741 [myid:] - INFO  [main-SendThread(zks1:2181):ClientCnxn$SendThread@975] - Opening socket connection to server zks1/192.168.4.60:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2015-05-24 23:02:24,755 [myid:] - WARN  [main-SendThread(zks1:2181):ClientCnxn$SendThread@1102] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
[zk: zks1:2181(CONNECTING) 0]

所有节点的/etc/hosts文件如下:

    192.168.4.60    zks1
    192.168.4.61    zks2
    192.168.4.66    zks3

zoo.cfg文件如下:

    dataDir=/var/zookeeper/                                                                    
    clientPort=2181
    initLimit=5
    syncLimit=2
    server.server1=zks1:2888:3888                                
    server.server2=zks2:2888:3888
    server.server3=zks3:2888:3888

我在所有节点上创建了目录 /var/zookeeper 并将所有权更改为 hduser:hadoop。

导出的环境变量为:

    export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
    export ZK_HOME=/usr/local/zookeeper
    export PATH=$PATH:$ZK_HOME/bin

数据目录(/var/zookeeper/)中的myid分别是server1、server2、server3。

问题请指出

用 server.1 替换 server.server1 并相应地修改每个节点的 myid 文件就成功了。

我也遇到了同样的问题。在我的例子中,问题是关于每个节点的 zookeeper 位置配置不相同,因此 zookeeper 无法提供 Quorum 并且提到的节点不能成为集群的一部分。

请确保每个节点的服务器定义相同。

server.server1=zks1:2888:3888                                
server.server2=zks2:2888:3888
server.server3=zks3:2888:3888

在 first/top 堆栈跟踪中,myid 值有问题。

"2015-05-24 23:02:24,602 [myid:] - 信息 [main:Environment@100] " 在上面一行 myid:* 这里应该是一个 integer/long 。所以你可能没有在 dataDir 文件夹中创建你的 myid 文件,或者你没有输入任何 long/int value.One 更多的东西 myid 应该是类型文件。

第二期,server.server1=machine:port1:port2 因为server1不是long所以org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties()方法会抛出NumberFormatException。 所以 server.1 应该是一个数字,在整体中是唯一的,同样应该在 myid 文件中。