概述
zookeeper官网:https://zookeeper.apache.org/
安装环境
部署ip | 部署软件 | 开放端口 |
---|---|---|
192.168.199.10 | jdk1.8、zookeeper-3.5.8 | 2181/2182/2183 |
192.168.199.11 | jdk1.8、zookeeper-3.5.8 | 2181/2182/2183 |
192.168.199.12 | jdk1.8、zookeeper-3.5.8 | 2181/2182/2183 |
安装部署
三台机器做相同操作,同一机器安装集群端口需要不相同
依赖环境安装
tar -zxvf jdk-8u211-linux-x64.tar.gz
mv jdk1.8.0_211 /opt/
vi /etc/profile
#根据实际情况修改JAVA_HOME
export JAVA_HOME=/opt/jdk1.8.0_211
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
#测试
java -version
zookeeper安装
mkdir -p /data/zookeeper
tar zxvf apache-zookeeper-3.5.8-bin.tar.gz
mv apache-zookeeper-3.5.8-bin /data/zookeeper/zookeeper-3.5.8
mkdir -p /data/zookeeper/zookeeper-3.5.8/{data,logs}
基础配置
vim /data/zookeeper/zookeeper-3.5.8/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/zookeeper-3.5.8/data
dataLogDir=/data/zookeeper/zookeeper-3.5.8/logs
clientPort=2181
server.1=192.168.199.10:2182:2183
server.2=192.168.199.11:2182:2183
server.3=192.168.199.12:2182:2183
<!-- 192.168.199.10 -->
echo 1 > /data/zookeeper/zookeeper-3.5.8/data/myid
<!-- 192.168.199.11 -->
echo 2 > /data/zookeeper/zookeeper-3.5.8/data/myid
<!-- 192.168.199.12 -->
echo 3 > /data/zookeeper/zookeeper-3.5.8/data/myid
配置启动脚本
vim /usr/lib/systemd/system/zookeeper.service
[Unit]
Description=zookeeper
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/data/zookeeper/zookeeper-3.5.8/bin/zkServer.sh start
ExecReload=/data/zookeeper/zookeeper-3.5.8/bin/zkServer.sh restart
ExecStop=/data/zookeeper/zookeeper-3.5.8/bin/zkServer.sh stop
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
开机自启动设置
# 加入开机启动
systemctl daemon-reload
systemctl enable zookeeper
# 查看开机是否启动成功
systemctl is-enabled zookeeper
# 启动服务
systemctl start zookeeper
# 停止服务
systemctl stop zookeeper
防火墙开放端口(三台机器都放行端口)
firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --zone=public --add-port=2182/tcp --permanent
firewall-cmd --zone=public --add-port=2183/tcp --permanent
firewall-cmd --reload
setenforce 0