ZK集群部署

==作者:YB-Chi==

[toc]

安装包

官网下载,git只有souce code版

https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz

部署

  1. 所有节点上传解压重命名安装包
  2. 修改所有节点zoo.cfg
1
2
3
4
5
6
7
8
cp zookeeper/conf/zoo_sample.cfg zoo.cfg
mkdir -p zookeeper/data

vim zookeeper/conf/zoo.cfg
dataDir=/home/cyb/zookeeper/data/
server.1=192.168.33.128:2888:3888
server.2=192.168.33.129:2888:3888
server.3=192.168.33.130:2888:3888
  1. data目录下生成myid,每个节点不同,如1 2 3
  2. 修改所有节点环境变量
1
2
3
4
5
6
7
vim /etc/profile

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64/jre
ZK_HOME=/home/cyb/zookeeper
PATH=$PATH:$JAVA_HOME/bin:$ZK_HOME/bin

source /etc/profile
  1. 写集群启动脚本
  2. 启动~ ./start-cluster.sh
  3. 每个节点执行zkServer.sh status测试是否成功

image

  1. 加到systemctl的service中

    vim /usr/lib/systemd/system/zookeeper.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[Unit]
# 服务描述
Description=cosmo-bdp zookeeper
# 在网络服务启动后运行
After=network.target

[Service]
Type=forking

#
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64/jre ZOO_LOG_DIR=/home/cyb/zookeeper/logs
# 启动命令
ExecStart=/home/cyb/zookeeper/bin/zkServer.sh start
# 停止命令
ExecStop=/home/cyb/zookeeper/bin/zkServer.sh stop
# 重载命令
ExecReload=/home/cyb/zookeeper/bin/zkServer.sh restart

# [Install]
WantedBy=multi-user.target
1
2
3
4
5
systemctl reload zookeeper.service
​systemctl start zookeeper.service
​systemctl is-enabled zookeeper.service

​zkCli.sh -server node1:2181,node2:2181,node3:2181
文章作者: CYBSKY
文章链接: https://cybsky.top/2022/10/27/cyb-mds/bigdata/Zookeeper/ZK集群部署/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 CYBSKY