集群模式
节点规划
主机 | ip | 说明 |
---|
yfm04 | 192.168.199.104 | 节点1 |
yfm05 | 192.168.199.105 | 节点2 |
yfm06 | 192.168.199.106 | 节点3 |
CentOS | CentOS Linux release 7.9.2009 (Core) | |
获取安装包
mkdir -p /data/zookeeper && cd /data/zookeeper
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
tar -zxvf apache-zookeeper-3.6.2-bin.tar.gz
创建相关目录
mkdir -p /data/zookeeper/data
mkdir -p /data/zookeeper/logs
配置环境变量
echo "export ZOOKEEPER_HOME=/data/zookeeper/apache-zookeeper-3.6.2-bin" >> /etc/profile
echo "export PATH=\$ZOOKEEPER_HOME/bin:\$PATH" >> /etc/profile
source /etc/profile
编辑配置文件
cd $ZOOKEEPER_HOME/conf && vi zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
clientPort=2181
server.1=192.168.199.104:2888:3888
server.2=192.168.199.105:2888:3888
server.3=192.168.199.106:2888:3888
配置节点标识
echo "1" > /data/zookeeper/data/myid
启动zookeeper
$ZOOKEEPER_HOME/bin/zkServer.sh start
查看节点状态
$ZOOKEEPER_HOME/bin/zkServer.sh status
客户端连接测试
$ZOOKEEPER_HOME/bin/zkCli.sh -server 192.168.199.104:2181
退出:quit
创建zookeeper服务
cd /etc/rc.d/init.d && touch zookeeper
chmod +x zookeeper
vi zookeeper输入以下内容
#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
case $1 in
start)su root /data/zookeeper/apache-zookeeper-3.6.2-bin/bin/zkServer.sh start;;
stop)su root /data/zookeeper/apache-zookeeper-3.6.2-bin/bin/zkServer.sh stop;;
status)su root /data/zookeeper/apache-zookeeper-3.6.2-bin/bin/zkServer.sh status;;
restart)su root /data/zookeeper/apache-zookeeper-3.6.2-bin/bin/zkServer.sh restart;;
*) echo "require start|stop|status|restart";;
esac
设置开启自启
chkconfig zookeeper on
检查自启服务列表
chkconfig --list