更新时间:2024-04-23 GMT+08:00
Zookeeper部署
前置条件
安装JDK
3台机器2888和3888端口能互通
安装目录约定
- 安装目录:/opt/zookeeper-3.6.1
- 配置文件:/opt/zookeeper-3.6.1/conf/zoo.cfg
- 数据目录:/data/zookeeper-3.6.1/data
- 日志目录:/data/zookeeper-3.6.1/logs
安装配置
三台zookeeper配置,解压并创建目录
上传安装apache-zookeeper-3.6.1-bin.tar.gz包到3台服务器,分别都解压并创建目录
# cd /soft/zookeeper/ # tar -vxf apache-zookeeper-3.6.1-bin.tar.gz # mv apache-zookeeper-3.6.1-bin /opt/zookeeper-3.6.1 # mkdir -p /data/zookeeper-3.6.1/{data,logs}
- Zookeeper节点一配置
添加集群节点身份标识
# echo "1" >/data/zookeeper-3.6.1/data/myid
新增配置集群信息
# vim /opt/zookeeper-3.6.1/conf/zoo.cfg clientPort=2181 tickTime=2000 initLimit=20 syncLimit=10 dataDir=/data/zookeeper-3.6.1/data dataLogDir=/data/zookeeper-3.6.1/logs #2888是leader与flower之间的访问端口(心跳端口),3888是投票选举leader端口(数据端口) #配置3个zookeeper节点地址 server.1=192.168.0.190:2888:3888 server.2=192.168.0.228:2888:3888 server.3=10.201.0.168:2888:3888 #开启四字命令 4lw.commands.whitelist=*
配置日志目录
# sed -i 's/ZOO_LOG_DIR\=\"\$ZOOKEEPER_PREFIX\/logs\"/ZOO_LOG_DIR\=\"\/data\/zookeeper-3.6.1\/logs\"/g' /opt/zookeeper-3.6.1/bin/zkEnv.sh
- Zookeeper节点二配置
添加集群节点身份标识
# echo "2" >/data/zookeeper-3.6.1/data/myid
新增配置集群信息
# vim /opt/zookeeper-3.6.1/conf/zoo.cfg clientPort=2181 tickTime=2000 initLimit=20 syncLimit=10 dataDir=/data/zookeeper-3.6.1/data dataLogDir=/data/zookeeper-3.6.1/logs #2888是leader与flower之间的访问端口(心跳端口),3888是投票选举leader端口(数据端口) #配置3个zookeeper节点地址 server.1=192.168.0.190:2888:3888 server.2=192.168.0.228:2888:3888 server.3=10.201.0.168:2888:3888 #开启四字命令 4lw.commands.whitelist=*
配置日志目录
# sed -i 's/ZOO_LOG_DIR\=\"\$ZOOKEEPER_PREFIX\/logs\"/ZOO_LOG_DIR\=\"\/data\/zookeeper-3.6.1\/logs\"/g' /opt/zookeeper-3.6.1/bin/zkEnv.sh
- Zookeeper节点三配置
添加集群节点身份标识
# echo "3" >/data/zookeeper-3.6.1/data/myid
新增配置集群信息
# vim /opt/zookeeper-3.6.1/conf/zoo.cfg clientPort=2181 tickTime=2000 initLimit=20 syncLimit=10 dataDir=/data/zookeeper-3.6.1/data dataLogDir=/data/zookeeper-3.6.1/logs #2888是leader与flower之间的访问端口(心跳端口),3888是投票选举leader端口(数据端口) #配置3个zookeeper节点地址 server.1=192.168.0.190:2888:3888 server.2=192.168.0.228:2888:3888 server.3=10.201.0.168:2888:3888 #开启四字命令 4lw.commands.whitelist=*
配置日志目录
# sed -i 's/ZOO_LOG_DIR\=\"\$ZOOKEEPER_PREFIX\/logs\"/ZOO_LOG_DIR\=\"\/data\/zookeeper-3.6.1\/logs\"/g' /opt/zookeeper-3.6.1/bin/zkEnv.sh
启动zookeeper
- 3个节点分别创建zookeeper系统启动文件
# vim /etc/systemd/system/zookeeper.service [Unit] Description=zkServer After=network.target remote-fs.target nss-lookup.target ConditionPathExists=/opt/zookeeper-3.6.1/conf/zoo.cfg [Service] Type=forking Environment=JAVA_HOME=/opt/jdk1.8.0_131 ExecStart=/opt/zookeeper-3.6.1/bin/zkServer.sh start ExecStop=/opt/zookeeper-3.6.1/bin/zkServer.sh stop PrivateTmp=true [Install] WantedBy=multi-user.target
- 重新加载systemctl配置
# systemctl daemon-reload
- 设置跟随linux启动,并启动zookeeper
# systemctl start zookeeper && systemctl enable zookeeper
图1 启动 - 查看状态
# /opt/zookeeper-3.6.1/bin/zkServer.sh status
主节点
图2 启动从节点
图3 启动
父主题: 实施步骤