zookeeper单价伪集群的部署和单机安装区别不大,伪集群就是在一台机器上安装三个zookeeper的应用,然后修改一下三个应用的端口,关联起来,这个在单机安装的时候说过,配置文件中没有集群部署的配置信息,需要自己单独添加。参考单机安装:https://www.wulaoer.org/?p=864
现在已经下载好文件了,我们需要在同一台机器上在安装两个zookeeper,然后联系起来即可。
- [root@wulaoer.org local]# ll
- total 0
- drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
- drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
- drwxr-xr-x. 2 root root 6 Apr 11 2018 games
- drwxr-xr-x. 2 root root 6 Apr 11 2018 include
- drwxr-xr-x. 7 10 143 245 Oct 5 18:13 jdk
- drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
- drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
- drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
- drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
- drwxr-xr-x. 5 root root 49 Feb 3 15:24 share
- drwxr-xr-x. 2 root root 6 Apr 11 2018 src
- drwxr-xr-x. 9 root root 168 Feb 24 14:37 zookeeper1
- drwxr-xr-x. 9 root root 168 Feb 24 14:37 zookeeper2
- drwxr-xr-x. 9 root root 168 Feb 24 14:37 zookeeper3
zookeeper1配置
下面我们针对每一个zookeeper进行针对配置,下面先配置zookeeper1,因为同一个应用,所以需要修改端口和数据路径以及日志路径,至于集群的配置信息不需要修改。
- [root@wulaoer.org local]# vim zookeeper1/conf/zoo.cfg
- # The number of milliseconds of each tick
- tickTime=2000
- # The number of ticks that the initial
- # synchronization phase can take
- initLimit=10
- # The number of ticks that can pass between
- # sending a request and getting an acknowledgement
- syncLimit=5
- # the directory where the snapshot is stored.
- # do not use /tmp for storage, /tmp here is just
- # example sakes.
- dataDir=/usr/local/zookeeper1/data
- dataLogDir=/usr/local/zookeeper1/logs
- # the port at which the clients will connect
- clientPort=2181
- # the maximum number of client connections.
- # increase this if you need to handle more clients
- #maxClientCnxns=60
- #
- # Be sure to read the maintenance section of the
- # administrator guide before turning on autopurge.
- #
- # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
- #
- # The number of snapshots to retain in dataDir
- #autopurge.snapRetainCount=3
- # Purge task interval in hours
- # Set to "0" to disable auto purge feature
- #autopurge.purgeInterval=1
- server.1=127.0.0.1:12888:13888
- server.2=127.0.0.1:14888:15888
- server.3=127.0.0.1:16888:17888
配置好zookeeper文件后需要在data目录下创建一个myid文件,在myid文件中输入zookeeper的编号,以备集群区分。
- [root@wulaoer.org zookeeper1]# mkdir data
- [root@wulaoer.org zookeeper1]# touch data/myid
- [root@wulaoer.org zookeeper1]# echo "1" > data/myid
Zookeeper2配置
- [root@wulaoer.org local]# vim zookeeper2/conf/zoo.cfg
- # The number of milliseconds of each tick
- tickTime=2000
- # The number of ticks that the initial
- # synchronization phase can take
- initLimit=10
- # The number of ticks that can pass between
- # sending a request and getting an acknowledgement
- syncLimit=5
- # the directory where the snapshot is stored.
- # do not use /tmp for storage, /tmp here is just
- # example sakes.
- dataDir=/usr/local/zookeeper2/data
- dataLogDir=/usr/local/zookeeper2/logs
- # the port at which the clients will connect
- clientPort=2182
- # the maximum number of client connections.
- # increase this if you need to handle more clients
- #maxClientCnxns=60
- #
- # Be sure to read the maintenance section of the
- # administrator guide before turning on autopurge.
- #
- # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
- #
- # The number of snapshots to retain in dataDir
- #autopurge.snapRetainCount=3
- # Purge task interval in hours
- # Set to "0" to disable auto purge feature
- #autopurge.purgeInterval=1
- server.1=127.0.0.1:12888:13888
- server.2=127.0.0.1:14888:15888
- server.3=127.0.0.1:16888:17888
- [root@wulaoer.org zookeeper2]# mkdir data
- [root@wulaoer.org zookeeper2]# touch data/myid
- [root@wulaoer.org zookeeper2]# echo "2" > data/myid
Zookeeper3配置
- [root@wulaoer.org local]# vim zookeeper3/conf/zoo.cfg
- # The number of milliseconds of each tick
- tickTime=2000
- # The number of ticks that the initial
- # synchronization phase can take
- initLimit=10
- # The number of ticks that can pass between
- # sending a request and getting an acknowledgement
- syncLimit=5
- # the directory where the snapshot is stored.
- # do not use /tmp for storage, /tmp here is just
- # example sakes.
- dataDir=/usr/local/zookeeper3/data
- dataLogDir=/usr/local/zookeeper3/logs
- # the port at which the clients will connect
- clientPort=2183
- # the maximum number of client connections.
- # increase this if you need to handle more clients
- #maxClientCnxns=60
- #
- # Be sure to read the maintenance section of the
- # administrator guide before turning on autopurge.
- #
- # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
- #
- # The number of snapshots to retain in dataDir
- #autopurge.snapRetainCount=3
- # Purge task interval in hours
- # Set to "0" to disable auto purge feature
- #autopurge.purgeInterval=1
- server.1=127.0.0.1:12888:13888
- server.2=127.0.0.1:14888:15888
- server.3=127.0.0.1:16888:17888
- [root@wulaoer.org zookeeper3]# mkdir data
- [root@wulaoer.org zookeeper3]# touch data/myid
- [root@wulaoer.org zookeeper3]# echo "3" > data/myid
现在三个Zookeeper服务已经配置完成,下面我们启动一下三个服务。
- [root@wulaoer.org zookeeper1]# ./bin/zkServer.sh start
- ZooKeeper JMX enabled by default
- Using config: /usr/local/zookeeper1/bin/../conf/zoo.cfg
- Starting zookeeper ... STARTED
- [root@wulaoer.org zookeeper2]# ./bin/zkServer.sh start
- ZooKeeper JMX enabled by default
- Using config: /usr/local/zookeeper2/bin/../conf/zoo.cfg
- Starting zookeeper ... STARTED
- [root@wulaoer.org zookeeper3]# ./bin/zkServer.sh start
- ZooKeeper JMX enabled by default
- Using config: /usr/local/zookeeper3/bin/../conf/zoo.cfg
- Starting zookeeper ... STARTED
查看一下三个服务的状态,这里看到Zookeeper2是集群中的leader了。
- [root@wulaoer.org local]# ./zookeeper1/bin/zkServer.sh status
- ZooKeeper JMX enabled by default
- Using config: /usr/local/zookeeper1/bin/../conf/zoo.cfg
- Client port found: 2181. Client address: wulaoer.org.
- Mode: follower
- [root@wulaoer.org local]# ./zookeeper2/bin/zkServer.sh status
- ZooKeeper JMX enabled by default
- Using config: /usr/local/zookeeper2/bin/../conf/zoo.cfg
- Client port found: 2182. Client address: wulaoer.org.
- Mode: leader
- [root@wulaoer.org local]# ./zookeeper3/bin/zkServer.sh status
- ZooKeeper JMX enabled by default
- Using config: /usr/local/zookeeper3/bin/../conf/zoo.cfg
- Client port found: 2183. Client address: wulaoer.org.
- Mode: follower
zookeeper单机伪集群已经搭建完成,Zookeeper伪集群不建议在生产或者测试环境中使用,一旦机器出现故障整个集群都不可使用,建议分之三台集群中搭建集群。
总结
报错原因是我指定的日志格式的文件名,我指定的是log,但是单机安装的时候会生成一个logs
- java.io.IOException: No snapshot found, but there are log entries. Something is broken!
- at org.apache.zookeeper.server.persistence.FileTxnSnapLog.restore(FileTxnSnapLog.java:240)
- at org.apache.zookeeper.server.ZKDatabase.loadDataBase(ZKDatabase.java:240)
- at org.apache.zookeeper.server.quorum.QuorumPeer.loadDataBase(QuorumPeer.java:901)
- at org.apache.zookeeper.server.quorum.QuorumPeer.start(QuorumPeer.java:887)
- at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:205)
- at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:123)
- at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
- 2020-02-24 16:37:59,779 [myid:1] - ERROR [main:QuorumPeerMain@101] - Unexpected exception, exiting abnormally
- java.lang.RuntimeException: Unable to run quorum server
错误原因是因为没有在data目录下创建myid文件,所以也没有在myid文件中指定Zookeeper集群的编号。
- 2020-02-24 16:19:46,659 [myid:] - ERROR [main:QuorumPeerMain@89] - Invalid config, exiting abnormally
- org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /usr/local/zookeeper1/bin/../conf/zoo.cfg
- at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:156)
- at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:113)
- at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
- Caused by: java.lang.IllegalArgumentException: myid file is missing
- at org.apache.zookeeper.server.quorum.QuorumPeerConfig.checkValidity(QuorumPeerConfig.java:736)
- at org.apache.zookeeper.server.quorum.QuorumPeerConfig.setupQuorumPeerConfig(QuorumPeerConfig.java:607)
- at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:422)
- at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:152)
Zookeeper伪集群已经单间完成。
分享到微信朋友圈
微信扫一下
将本文分享至朋友圈
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏