前提:准备3台linux虚机
下面是实操命令步骤
一、下载zk
[[email protected] ~]$ mkdir zookeeper
[[email protected] ~]$ cd zookeeper
[[email protected] zookeeper]$ mkdir zkdata
[[email protected] zookeeper]$ mkdir zkdatalog
[[email protected] zookeeper]$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz
二、解压zk
[[email protected] zookeeper]$ tar -xzvf zookeeper-3.4.13.tar.gz
[[email protected] zookeeper]$ cd zookeeper-3.4.13/
[[email protected] zookeeper-3.4.13]$ cd conf
[[email protected] conf]$ cp zoo_sample.cfg zoo.cfg
三、配置zoo.cfg
[[email protected] conf]$ vim zoo.cfg
dataDir=/home/app/zookeeper/zkdata
dataLogDir=/home/app/zookeeper/zkdatalog
server.1=10.10.30.238:12888:13888
server.2=10.10.30.239:12888:13888
server.3=10.10.30.240:12888:13888
以上ip需配置实际地址
node2和node3重复以上步骤
四、配置myid
[[email protected] ~]$ echo "1" > /home/app/zookeeper/zkdata/myid
[[email protected] ~]$ echo "2" > /home/app/zookeeper/zkdata/myid
[[email protected] ~]$ echo "3" > /home/app/zookeeper/zkdata/myid
五、编辑zookeeper.out输出路径
在zkEnv.sh
修改ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs"
六、启动zk
启动node01
[[email protected] ~]$ /home/app/zookeeper/zookeeper-3.4.13/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/app/zookeeper/zookeeper-3.4.13/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[[email protected] ~]$
启动node02
[[email protected] conf]$ /home/app/zookeeper/zookeeper-3.4.13/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/app/zookeeper/zookeeper-3.4.13/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
启动node03
[[email protected] conf]$ /home/app/zookeeper/zookeeper-3.4.13/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/app/zookeeper/zookeeper-3.4.13/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
查看node1状态
[[email protected] ~]$ /home/app/zookeeper/zookeeper-3.4.13/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/app/zookeeper/zookeeper-3.4.13/bin/../conf/zoo.cfg
Mode: follower
[[email protected] ~]$
查看node2状态
[[email protected] conf]$ /home/app/zookeeper/zookeeper-3.4.13/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/app/zookeeper/zookeeper-3.4.13/bin/../conf/zoo.cfg
Mode: leader
[[email protected] conf]$
查看node3状态
[[email protected] conf]$ /home/app/zookeeper/zookeeper-3.4.13/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/app/zookeeper/zookeeper-3.4.13/bin/../conf/zoo.cfg
Mode: follower
[[email protected] conf]$
zk集群搭建完毕。
原文地址:https://www.cnblogs.com/xingxin666/p/11623435.html