zookeeper配置单机伪集群,启动后查看状态没有正常运行。
[root@ZhOu bin]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@ZhOu bin]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/opt/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
打开bin中zookeeper.out,提示错误信息如下:
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /usr/opt/zookeeper1/bin/../conf/zoo.cfg
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:154)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:101)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
Caused by: java.lang.IllegalArgumentException: /usr/opt/zookeeper1/data/myid file is missing
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:406)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:150)
... 2 more
原因:
集群中的每台ZK server都会有一个用于惟一标识自己的id,有两个地方会使用到这个id:myid文件和zoo.cfg文件中。myid文件存储在dataDir目录中,指定了当前server的server id。在zoo.cfg文件中,根据server id,配置了每个server的ip和相应端口。Zookeeper启动的时候,读取myid文件中的server id,然后去zoo.cfg 中查找对应的配置。
解决方案如下:
在zoo.cfg中指定的dataDir目录中创建文件myid,里面只需要填写你设置的server编号即可。如下:
server.1=127.0.0.1:2800:3800
server.2=127.0.0.1:2801:3801
server.3=127.0.0.1:2802:3802
在第一个zookeeper里面,创建myid文件,里面填写个1就可以了,2、3里面同样各自设置,然后重启就可以了。