ZooKeeper伪集群环境搭建

Posted llguanli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZooKeeper伪集群环境搭建相关的知识,希望对你有一定的参考价值。

1.从官网下载程序包。


2.解压。

[[email protected] software]$ tar xzvf zookeeper-3.4.6.tar.gz

3.进入zookeeper文件夹后创建data文件夹。

[[email protected] software]$ cd zookeeper-3.4.6
[[email protected] software]$ mkdir data
[[email protected] software]$ cd data
[[email protected] software]$ touch myid





??????? myid这个文件必须创建。不然启动的时候会跑出以下的异常。

[[email protected] bin]$ ./zkServer.sh start-foreground
JMX enabled by default
Using config: /home/dev/zookeeper/zookeeper1/bin/../conf/zoo.cfg
2015-03-12 16:06:38,155 [myid:] - INFO  [main:[email protected]] - Reading configuration from: /home/dev/zookeeper/zookeeper1/bin/../conf/zoo.cfg
2015-03-12 16:06:38,159 [myid:] - INFO  [main:[email protected]] - Defaulting to majority quorums
2015-03-12 16:06:38,161 [myid:] - ERROR [main:[email protected]] - Invalid config, exiting abnormally
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /home/dev/zookeeper/zookeeper1/bin/../conf/zoo.cfg
     at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:121)
     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: /home/dev/zookeeper/zookeeper1/data/myid file is missing
     at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:344)
     at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:117)
     ... 2 more
Invalid config, exiting abnormally

??????? myid文件中必需要有内容,其值相应zoo.cfg中server的id。有点绕,我也是试了好多次才配好的。也就说,假如集群的配置例如以下,那问题来了,怎么区分当前启动的zookeeper是哪一个呢?就是通过myid文件来区分的。第1个zookeeper服务的myid文件的内容就是1。其他就以此类推了。假设myid配错了,后果非常严重——zookeeper服务起不来。O(∩_∩)O哈哈~,而且报以下的异常。


server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
[[email protected] bin]$  ./zkServer.sh start-foreground
JMX enabled by default
Using config: /home/dev/zookeeper/zookeeper2/bin/../conf/zoo.cfg
2015-03-12 16:09:35,422 [myid:] - INFO  [main:[email protected]] - Reading configuration from: /home/dev/zookeeper/zookeeper2/bin/../conf/zoo.cfg
2015-03-12 16:09:35,426 [myid:] - INFO  [main:[email protected]] - Defaulting to majority quorums
2015-03-12 16:09:35,434 [myid:0] - INFO  [main:[email protected]] - autopurge.snapRetainCount set to 3
2015-03-12 16:09:35,434 [myid:0] - INFO  [main:[email protected]] - autopurge.purgeInterval set to 0
2015-03-12 16:09:35,435 [myid:0] - INFO  [main:[email protected]] - Purge task is not scheduled.
2015-03-12 16:09:35,455 [myid:0] - INFO  [main:[email protected]] - Starting quorum peer
2015-03-12 16:09:35,472 [myid:0] - INFO  [main:[email protected]] - binding to port 0.0.0.0/0.0.0.0:2182
2015-03-12 16:09:35,500 [myid:0] - INFO  [main:[email protected]] - tickTime set to 2000
2015-03-12 16:09:35,501 [myid:0] - INFO  [main:[email protected]] - minSessionTimeout set to -1
2015-03-12 16:09:35,501 [myid:0] - INFO  [main:[email protected]] - maxSessionTimeout set to -1
2015-03-12 16:09:35,502 [myid:0] - INFO  [main:[email protected]] - initLimit set to 10
2015-03-12 16:09:35,519 [myid:0] - ERROR [main:[email protected]] - Setting LearnerType to PARTICIPANT but 0 not in QuorumPeers.
2015-03-12 16:09:35,530 [myid:0] - INFO  [main:[email protected]] - currentEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation
2015-03-12 16:09:35,591 [myid:0] - INFO  [main:[email protected]] - acceptedEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation
2015-03-12 16:09:35,598 [myid:0] - ERROR [main:[email protected]] - Unexpected exception, exiting abnormally
java.lang.RuntimeException: My id 0 not in the peer list
     at org.apache.zookeeper.server.quorum.QuorumPeer.startLeaderElection(QuorumPeer.java:479)
     at org.apache.zookeeper.server.quorum.QuorumPeer.start(QuorumPeer.java:411)
     at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:151)
     at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:111)
     at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)


4.改动zoo.cfg文件。

在zookeeper/conf/zoo.cfg改动dataDir的文件夹,就是我们在第2步中创建的data文件夹。

在文件最后加入zookeeper集群节点地址。

server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

5.其他节点配置。

好了,上面已经配置好了1个zookeeper服务。然后直接copy刚才配好的zookeeper文件夹两份。改动data/myid文件中的id,zoo.cfg的dataDir。clientPort。


6.然后分别启动zookeeper。


ZooKeeper伪集群环境搭建好了,不然让它静静地在那里跑着,继续捣鼓它。

。。。。



以上是关于ZooKeeper伪集群环境搭建的主要内容,如果未能解决你的问题,请参考以下文章

ZooKeeper伪集群环境搭建

centos7环境下zookeeper的搭建步骤之单机伪集群

zookeeper初探二 windows环境搭建伪集群

zookeeper伪分布式集群环境搭建

ZooKeeper 3.6.2 Windows环境搭建(伪集群详)

Zookeeper搭建环境