zookeeper 集群安装
Last updated on January 17, 2025 am
🧙 Questions
安装zookeeper集群
3.8.1
版本
部署环境 centOS 7.9
64位
服务器个数最好是奇数
hostname | 公网ip | 内网ip | CPU | 内存 |
---|---|---|---|---|
isxcode-main1 | 39.98.65.13 | 172.16.215.101 | 8C | 16GB |
isxcode-main2 | 47.92.252.139 | 172.16.215.100 | 8C | 16GB |
isxcode-node1 | 39.98.76.185 | 172.16.215.97 | 4C | 8GB |
isxcode-node2 | 39.98.77.191 | 172.16.215.96 | 4C | 8GB |
isxcode-node3 | 47.92.217.66 | 172.16.215.95 | 4C | 8GB |
☄️ Ideas
前提
安装java环境(每台都要装)
sudo yum install -y java-1.8.0-openjdk-devel java-1.8.0-openjdk
下载zookeeper (一台加载即可)
cd /tmp
nohup wget https://archive.apache.org/dist/zookeeper/zookeeper-3.8.1/apache-zookeeper-3.8.1-bin.tar.gz >> download_zookeeper.log 2>&1 &
tail -f download_zookeeper.log
分发安装包
scp /tmp/apache-zookeeper-3.8.1-bin.tar.gz ispong@isxcode-main2:/tmp/
scp /tmp/apache-zookeeper-3.8.1-bin.tar.gz ispong@isxcode-node1:/tmp/
scp /tmp/apache-zookeeper-3.8.1-bin.tar.gz ispong@isxcode-node2:/tmp/
scp /tmp/apache-zookeeper-3.8.1-bin.tar.gz ispong@isxcode-node3:/tmp/
创建安装目录 (每台都要创建)
sudo mkdir -p /data/zookeeper
sudo chown -R ispong:ispong /data/zookeeper
解压并创建软连接 (每台都要执行)
tar -vzxf /tmp/apache-zookeeper-3.8.1-bin.tar.gz -C /data/zookeeper
sudo ln -s /data/zookeeper/apache-zookeeper-3.8.1-bin /opt/zookeeper
配置环境变量 (每台都要执行)
sudo tee -a /etc/profile <<-'EOF'
export ZOOKEEPER_HOME=/opt/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
EOF
source /etc/profile
修改zookeeper配置文件 (每台都要执行)
mkdir -p /data/zookeeper/data
mkdir -p /data/zookeeper/logs
touch /data/zookeeper/data/zookeeper_server.pid
cp /opt/zookeeper/conf/zoo_sample.cfg /opt/zookeeper/conf/zoo.cfg
vim /opt/zookeeper/conf/zoo.cfg
注意:将当前服务器配置中的ip改为0.0.0.0
# 修改数据存储位置
# 直接新增
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
# 修改zk端口号,默认2181
clientPort=2181
# ... other config
# 服务器信息
server.1=0.0.0.0:2888:3888
server.2=isxcode-main2:2888:3888
server.3=isxcode-node1:2888:3888
server.4=isxcode-node2:2888:3888
server.5=isxcode-node3:2888:3888
# 如果是isxcode-main2,则是以下配置,依次类推
# server.1=isxcode-main1:2888:3888
# server.2=0.0.0.0:2888:3888
# server.3=isxcode-node1:2888:3888
# server.4=isxcode-node2:2888:3888
# server.5=isxcode-node3:2888:3888
添加myid文件 (每台都要添加)
注意: 和配置zoo.cfg中的server.${number}保持一致
vim /data/zookeeper/data/myid
1
配置zookeeper自启 (每台都要创建)
注意:要修改用户和用户组
sudo vim /usr/lib/systemd/system/zookeeper.service
[Unit]
Description=Zookeeper Service
After=network.target
[Service]
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
Type=forking
WorkingDirectory=/data/zookeeper
PermissionsStartOnly=true
ExecStart=/opt/zookeeper/bin/zkServer.sh start
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
ExecReload=/opt/zookeeper/bin/zkServer.sh restart
PIDFile=/data/zookeeper/data/zookeeper_server.pid
KillMode=none
Restart=always
User=ispong
Group=ispong
[Install]
WantedBy=multi-user.target
启动开机自启 (每台都要执行)
sudo systemctl daemon-reload
sudo systemctl enable zookeeper
# sudo systemctl disable zookeeper
提前测试是否命令可以启动
zkServer.sh start
# 查看日志
cat /opt/zookeeper/logs/zookeeper-*.out
# 查看端口是否启动
ps -ef | grep org.apache.zookeeper.server.quorum.QuorumPeerMain
sudo netstat -nap | grep 31669
zkServer.sh status
启动命令
sudo systemctl stop zookeeper
sudo systemctl restart zookeeper
sudo systemctl start zookeeper
查看运行状态
sudo systemctl status zookeeper
查看日志
tail -f /data/zookeeper/apache-zookeeper-3.8.1-bin/logs/zookeeper-isxcode-server-main1.out
查看进程
sudo ps aux | grep zookeeper
查看节点状态
zkServer.sh status
🔗 Links
zookeeper 集群安装
https://ispong.isxcode.com/hadoop/zookeeper/zookeeper 集群安装/