- 安装包准备
jdk-8u212-linux-x64.tar.gz、apache-zookeeper-3.5.5-bin.tar.gz(3.5.3以上的版本最好)
主机名 | IP |
---|---|
master | 192.168.80.132 |
worker1 | 192.168.80.133 |
worker2 | 192.168.80.134 |
-
配置节点的免密通讯
参考:https://blog.csdn.net/admin_15082037343/article/details/88721542 -
关闭防火墙,三个节点都需要
systemctl stop firewalld
systemctl disable firewalld
-
配置jdk
参考:https://blog.csdn.net/admin_15082037343/article/details/91598052 -
配置zookeeper
- master解压zookeeper
tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz
- master copy zoo_sample.cfg生成zoo.cfg
在${ZOOKEEPER_HOME}/conf目录下,执行以下命令
cp zoo_sample.cfg zoo.cfg
- master更改zoo.cfg配置
#更新文件存放路径
dataDir=/opt/tools/data/zookeeper/data
#以下配置需要新增
reconfigEnabled=true
standaloneEnabled=false
server.1=master:2888:3888
server.2=worker1:2888:3888
server.3=worker2:2888:3888
- master复制到worker1和worker2
scp -r apache-zookeeper-3.5.5-bin root@worker1:/opt/tools/apache-zookeeper-3.5.5-bin
scp -r apache-zookeeper-3.5.5-bin root@worker2:/opt/tools/apache-zookeeper-3.5.5-bin
- 三个节点新增myid文件,文件路径为${dataDir},文件内容为server.x的"x"
#master
echo "1" >> /opt/tools/data/zookeeper/data/myid
#worker1
echo "2" >> /opt/tools/data/zookeeper/data/myid
#worker2
echo "3" >> /opt/tools/data/zookeeper/data/myid
- 三个节点启动zookeeper
在${ZOOKEEPER_HOME}/conf目录下,执行以下命令
./zkServer.sh start
- 查看状态
一个leader,两个follower,代表集群启动成功
送你一个脚本,一次性启动三个节点的zookeeper
#!/bin/bash
ZOOKEEPER_HOME=/opt/tools/apache-zookeeper-3.5.5-bin
cd $ZOOKEEPER_HOME/bin
./zkServer.sh start
ssh -T root@worker1 <<EOF
cd $ZOOKEEPER_HOME/bin
./zkServer.sh start
EOF
ssh -T root@worker2 <<EOF
cd $ZOOKEEPER_HOME/bin
./zkServer.sh start
EOF