ZooKeeper单机集群的安装

下载地址

https://dlcdn.apache.org/zookeeper/zookeeper-3.8.4/

解压到指定目录

tar -zxf /mnt/d/software/apache-zookeeper-3.8.4-bin.tar.gz -C /mnt/d/apps
mv /mnt/d/apps/apache-zookeeper-3.8.4-bin  /mnt/d/apps/zookeeper

配置脚本

# 假设Zookeeper解压到以下目录
ZK_HOME=/mnt/d/apps/zookeeper
 
# 创建三个不同的配置和数据目录
for i in {1..3}; do
    mkdir -p $ZK_HOME/server$i/data
    mkdir -p $ZK_HOME/server$i/logs
    mkdir -p $ZK_HOME/server$i/conf
    touch $ZK_HOME/server$i/conf/zoo.cfg
    touch $ZK_HOME/server$i/data/myid
    echo $i > $ZK_HOME/server$i/data/myid

    cat > $ZK_HOME/server$i/conf/zoo.cfg <<EOF
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/mnt/d/apps/zookeeper/server$i/data
dataLogDir=/mnt/d/apps/zookeeper/server$i/logs
clientPort=218$i
server.1=localhost:2287:3001
server.2=localhost:2288:3002
server.3=localhost:2289:3003
EOF

cat > /mnt/d/apps/zookeeper/start.sh <<EOF
/mnt/d/apps/zookeeper/bin/zkServer.sh start /mnt/d/apps/zookeeper/server1/conf/zoo.cfg
/mnt/d/apps/zookeeper/bin/zkServer.sh start /mnt/d/apps/zookeeper/server2/conf/zoo.cfg
/mnt/d/apps/zookeeper/bin/zkServer.sh start /mnt/d/apps/zookeeper/server3/conf/zoo.cfg
EOF

cat > /mnt/d/apps/zookeeper/stop.sh <<EOF
/mnt/d/apps/zookeeper/bin/zkServer.sh stop /mnt/d/apps/zookeeper/server1/conf/zoo.cfg
/mnt/d/apps/zookeeper/bin/zkServer.sh stop /mnt/d/apps/zookeeper/server2/conf/zoo.cfg
/mnt/d/apps/zookeeper/bin/zkServer.sh stop /mnt/d/apps/zookeeper/server3/conf/zoo.cfg
EOF

done

启动

/mnt/d/apps/zookeeper/start.sh

测试验证

/mnt/d/apps/zookeeper/bin/zkCli.sh

# 查看根节点的所有节点
ls /

# 创建节点
create /bsmn "welcome to bsmn space"

# 查看节点信息
get -s /bsmn

posted on 2024-12-02 15:25  白首码农  阅读(8)  评论(0编辑  收藏  举报