大数据之—Zookeeper环境搭建
前言
参考博客:https://blog.csdn.net/weixin_55008454/article/details/128445784
一、下载
zk仓库地址:https://archive.apache.org/dist/zookeeper/
软件包:https://archive.apache.org/dist/zookeeper/zookeeper-3.8.1/apache-zookeeper-3.8.1-bin.tar.gz
二、安装
mkdir -p /opt/zookeeper && cd /opt/zookeeper
tar zxvf apache-zookeeper-3.8.1-bin.tar.gz
cd /opt/zookeeper/apache-zookeeper-3.8.1-bin/
配置环境变量:vim /etc/profile.d/my_env.sh
# ZOOKEEPER_HOME
export ZOOKEEPER_HOME=/opt/zookeeper/apache-zookeeper-3.8.1-bin
export PATH=$PATH:$ZOOKEEPER_HOME/bin
同步文件:xsync /etc/profile.d/my_env.sh
刷新环境变量
三、集群部署
node1、node2、node3
mkdir -p /opt/zookeeper/zkData
# 此步骤最后处理,注意每个节点的值不一样,分别为2、3、4
vim /opt/zookeeper/zkData/myid
cp /opt/zookeeper/apache-zookeeper-3.8.1-bin/conf/zoo_sample.cfg /opt/zookeeper/apache-zookeeper-3.8.1-bin/conf/zoo.cfg
修改配置文件:vim /opt/zookeeper/apache-zookeeper-3.8.1-bin/conf/zoo.cfg
# 1、修改
dataDir=/opt/zookeeper/zkData
# 2、添加集群配置
####################### cluster ##########################
# 2888为选举端口,3888为心跳端口
server.2=node1:2888:3888
server.3=node2:2888:3888
server.4=node3:2888:3888
集群管理脚本:touch /opt/zookeeper/zk && chmod +x /opt/zookeeper/zk && vim /opt/zookeeper/zk
#!/bin/bash
host_names=(node1 node2 node3)
cmd_bin="/opt/zookeeper/apache-zookeeper-3.8.1-bin/bin/zkServer.sh"
case $1 in "start")
for host in ${host_names[@]}
do
echo ---------- zk $host 启动 ----------
ssh $host "$cmd_bin start"
done
;;
"stop")
for host in ${host_names[@]}
do
echo ---------- zk $host 停止 ----------
ssh $host "$cmd_bin stop"
done
;;
"status")
for host in ${host_names[@]}
do
echo ---------- zk $host 状态 ----------
ssh $host "$cmd_bin status"
done
;;
esac
同步:xsync /opt/zookeeper/
修改权限:sudo chown -R root:root /opt/zookeeper/
修改节点标识:
# 这两个文件的内容要对应
echo 11 > /opt/zookeeper/zkData/myid
echo 12 > /opt/zookeeper/zkData/myid
echo 13 > /opt/zookeeper/zkData/myid
vim /opt/zookeeper/apache-zookeeper-3.8.1-bin/conf/zoo.cfg
server.11=node1:2888:3888
server.12=node2:2888:3888
server.13=node3:2888:3888
四、注意
如果启动不起来,就更换/opt/zookeeper/zkData/myid
的值,多尝试几次应该就可以了