ZooKeeper偽集群環境搭建
阿新 • • 發佈:2018-02-14
val exp war spa statistic style cal post server
4.改動zoo.cfg文件。
5.其他節點配置。
1.從官網下載程序包。
2.解壓。
[dev@localhost software]$ tar xzvf zookeeper-3.4.6.tar.gz
3.進入zookeeper文件夾後創建data文件夾。
[dev@localhost software]$ cd zookeeper-3.4.6 [dev@localhost software]$ mkdir data
[dev@localhost software]$ cd data [dev@localhost software]$ touch myid
??????? myid這個文件必須創建。不然啟動的時候會跑出以下的異常。
[dev@localhost 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:QuorumPeerConfig@101] - Reading configuration from: /home/dev/zookeeper/zookeeper1/bin/../conf/zoo.cfg 2015-03-12 16:06:38,159 [myid:] - INFO [main:QuorumPeerConfig@334] - Defaulting to majority quorums 2015-03-12 16:06:38,161 [myid:] - ERROR [main:QuorumPeerMain@85] - 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
[dev@localhost 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:QuorumPeerConfig@101] - Reading configuration from: /home/dev/zookeeper/zookeeper2/bin/../conf/zoo.cfg 2015-03-12 16:09:35,426 [myid:] - INFO [main:QuorumPeerConfig@334] - Defaulting to majority quorums 2015-03-12 16:09:35,434 [myid:0] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3 2015-03-12 16:09:35,434 [myid:0] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0 2015-03-12 16:09:35,435 [myid:0] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled. 2015-03-12 16:09:35,455 [myid:0] - INFO [main:QuorumPeerMain@127] - Starting quorum peer 2015-03-12 16:09:35,472 [myid:0] - INFO [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:2182 2015-03-12 16:09:35,500 [myid:0] - INFO [main:QuorumPeer@913] - tickTime set to 2000 2015-03-12 16:09:35,501 [myid:0] - INFO [main:QuorumPeer@933] - minSessionTimeout set to -1 2015-03-12 16:09:35,501 [myid:0] - INFO [main:QuorumPeer@944] - maxSessionTimeout set to -1 2015-03-12 16:09:35,502 [myid:0] - INFO [main:QuorumPeer@959] - initLimit set to 10 2015-03-12 16:09:35,519 [myid:0] - ERROR [main:QuorumPeer@171] - Setting LearnerType to PARTICIPANT but 0 not in QuorumPeers. 2015-03-12 16:09:35,530 [myid:0] - INFO [main:QuorumPeer@429] - 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:QuorumPeer@444] - 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:QuorumPeerMain@89] - 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偽集群環境搭建