zookeeper集群搭建以及批量启动
2020-11-12 本文已影响0人
Captain_Gu
集群所用版本
linux版本:Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-52-generic x86_64)
zookeeper版本:zookeeper-3.4.10
java版本:java version "1.8.0_231"
- 集群机器规划
192.168.100.130 ubuntu01
192.168.100.131 ubuntu02
192.168.100.132 ubuntu03 - 设置集群机器免密登陆
a.各台机器上执行ssh-keygen -t rsa
b.分别在三台机器上执行ssh-copy-id root@ubuntu01
ssh-copy-id root@ubuntu02
ssh-copy-id root@ubuntu03
- 上传解压zookeeper-3.4.10到目录/opt/zookeeper-3.4.10 修改配置文件zoo.cfg如下
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper-3.4.10/data
dataLogDir=/opt/zookeeper-3.4.10/datalog
clientPort=2181
autopurge.purgeInterval=1
#以下是集群节点配置,格式为“机器名.myid:数据通信端口:ZooKeeper Leader选举端口”
server.0=ubuntu01:2888:3888
server.1=ubuntu02:2888:3888
server.2=ubuntu03:2888:3888
- 修改data目录下的myid文件
ubuntu01
0
ubuntu02
1
ubuntu03
2
- 在/opt/zookeeper-3.4.10/bin下修改文件zkEnv.sh 增加一句JAVA_HOME
export JAVA_HOME=/opt/jdk1.8.0_231
- zookeeper集群启动脚本start-zookeeper.sh放置在/opt目录下
#!/bin/bash
case $1 in
start)
echo -n "Starting zookeeper ... "
for i in ubuntu01 ubuntu02 ubuntu03; do
ssh $i "/opt/zookeeper-3.4.10/bin/zkServer.sh start"
done
;;
stop)
echo -n "Stopping zookeeper ... "
for i in ubuntu01 ubuntu02 ubuntu03; do
ssh root@$i "/opt/zookeeper-3.4.10/bin/zkServer.sh stop"
done
;;
status)
echo "Status of zookeepers ... "
for i in ubuntu01 ubuntu02 ubuntu03; do
echo $i
ssh root@$i "/opt/zookeeper-3.4.10/bin/zkServer.sh status"
done
;;
time)
echo "update time ... "
for i in ubuntu01 ubuntu02 ubuntu03; do
echo $i
ssh root@$i "ntpdate ntp2.aliyun.com"
done
;;
*)
echo -n "Invalid Command ..."
;;
esac
- 集群启动
赋予执行权限chomd -R 777 /opt/start-zookeeper.sh
进入目录/opt 执行命令
启动./start-start-zookeeper.sh start
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
停止./start-start-zookeeper.sh stop
Stopping zookeeper ... ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
状态./start-start-zookeeper.sh status
Status of zookeepers ...
ubuntu01
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
ubuntu02
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
ubuntu03
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
同步集群时间./start-start-zookeeper.sh time
update time ...
ubuntu01
12 Nov 22:34:37 ntpdate[6827]: step time server 203.107.6.88 offset 18428.676547 sec
ubuntu02
12 Nov 22:34:44 ntpdate[3541]: step time server 203.107.6.88 offset 21061.548954 sec
ubuntu03
12 Nov 22:34:50 ntpdate[3136]: step time server 203.107.6.88 offset 21061.090135 sec
- zookeeper启动脚本zkServer.sh分析