前期准备
安装好JDK
安装 Zookeeper
- 修改conf下的zoo.cfg文件
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/software/zookeeper/zkData
server.1=ifan1:2888:3888
server.2=ifan2:2888:3888
server.3=ifan3:2888:3888
clientPort=2181
创建dataDir指定的目录
mkdir /opt/software/zookeeper/zkData
- 修改dataDir下的myid文件 不存在则创建
echo 1 > myid
- 将zookeeper目录发送到其他节点
scp -r /opt/software/zookeeper ifan2:/opt/software/zookeeper
scp -r /opt/software/zookeeper ifan3:/opt/software/zookeeper
- 修改其他节点的myid文件内容分别为 2 和 3
# 在ifan2机器上
echo 2 > /opt/software/zookeeper/zkData
# 在ifan3机器上
echo 3 > /opt/software/zookeeper/zkData
- 启动各个节点上的zk
# 在 ifan1 ifan2 ifan3 机器上分别执行
bin/zkServer.sh start
bin/zkServer.sh status
查看状态
## 跟随者
ZooKeeper JMX enabled by default
Using config: /opt/software/zookeeper/bin/../conf/zoo.cfg
Mode: follower
## 领导者
ZooKeeper JMX enabled by default
Using config: /opt/software/zookeeper/bin/../conf/zoo.cfg
Mode: leader