概述
zookeeper 安装比较简单,只需要在zoo.cfg中加入集群信息即可,需要注意的地方是zkData/myid不要忘了配置,三台机器id不能相同
zookeeper
集群规划
server110 | server111 | server112 | |
---|---|---|---|
zookeeper | zk.1 | zk.2 | zk.3 |
安装
#直接解压
[root@server110 software]# tar -xzvf apache-zookeeper-3.5.8-bin.tar.gz -C /opt/modules/
[root@server110 software]# cd ../modules/
#修改文件夹名称
[root@server110 modules]# mv apache-zookeeper-3.5.8-bin/ zookeeper-3.5.8/
配置
1、修改存储目录dataDir
2、设置myid,唯一标识,用来做leader选举
3、添加集群信息
[root@server110 modules]# cd zookeeper-3.5.8/
[root@server110 zookeeper-3.5.8]# mkdir zkData
[root@server110 zkData]# vim myid #设置集群节点标识
1
[root@server110 conf]# mv zoo_sample.cfg zoo.cfg
[root@server110 conf]# vim zoo.cfg
#修改默认数据存储位置
dataDir=/opt/modules/zookeeper-3.5.8/zkData
#最后添加集群节点信息
server.1=server110:2888:3888
server.2=server111:2888:3888
server.3=server112:2888:3888
同步其他机器
同步文件
[root@server110 modules]# scp -r zookeeper-3.5.8/ server111:/opt/modules/
[root@server110 modules]# scp -r zookeeper-3.5.8/ server112:/opt/modules/
修改另外两台myid
[root@server111 zkData]# vim myid
2
[root@server112 zkData]# vim myid
3
测试
注意,集群启动半数以上,才能选出leader,才能使用
bin/zkServer.sh status
查看状态
server110
[root@server110 zookeeper-3.5.8]# bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.8/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@server110 zookeeper-3.5.8]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.8/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
server111
[root@server111 zookeeper-3.5.8]# bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.8/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@server111 zookeeper-3.5.8]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.8/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
server112
[root@server112 zookeeper-3.5.8]# bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.8/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@server112 zookeeper-3.5.8]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/modules/zookeeper-3.5.8/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower