单服务器部署 zookeeper 集群

目录

1、环境准备

2、zookeeper集群端口规划

3、下载zookeeper压缩包

4、解压zookeeper

5、移动zookeeper根目录到/usr/local/目录下

6、创建zookeeper各节点配置、数据目录

7、启动各节点

8、查看集群状态


1、环境准备

        IP:172.16.2.71

        系统:centos7.9

        JDK:1.8.0_144(需要配置 JAVA_HOME 环境变量)

2、zookeeper集群端口规划

zk节点 客户端端口 与leader交换信息端口 leader选举通信端口
node1 2181 2661 3661
node2 2182 2662 3662
node3 2183 2663 3663

3、下载zookeeper压缩包

        从官网下载安装包,参考 Zookeeper 官网。

4、解压zookeeper

[root@localhost ~]# tar -xvf apache-zookeeper-3.5.10-bin.tar.gz

5、移动zookeeper根目录到/usr/local/目录下

 [root@localhost ~]# mv ./apache-zookeeper-3.5.10-bin /usr/local/

6、创建zookeeper各节点配置、数据目录

我这里统一将各节点配置放在/data/zookeeper目录下,大家可以自行调整

myid中的1、2、3与zoo.cfg中server.x的x保持一致,若x为4、5、6,则myid中的内容也应分别为4、5、6。

[root@localhost ~]# mkdir -p /data/zookeeper
[root@localhost ~]# cd /data/zookeeper
[root@localhost zookeeper]# mkdir -p node1/conf node1/data
[root@localhost zookeeper]# vi node1/conf/zoo.cfg
tickTime=100000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/node1/data
clientPort=2181

server.1=172.16.2.71:2661:3661
server.2=172.16.2.71:2662:3662
server.3=172.16.2.71:2663:3663
[root@localhost zookeeper]# cp -r ./node1 ./node2
[root@localhost zookeeper]# cp -r ./node1 ./node3
[root@localhost zookeeper]# sed -i 's/node1/node2/g' ./node2/zoo.cfg
[root@localhost zookeeper]# sed -i 's/2181/2182/g' ./node2/zoo.cfg
[root@localhost zookeeper]# sed -i 's/node1/node2/g' ./node3/zoo.cfg
[root@localhost zookeeper]# sed -i 's/2181/2182/g' ./node3/zoo.cfg
[root@localhost zookeeper]# echo 1 > ./node1/data/myid
[root@localhost zookeeper]# echo 2 > ./node2/data/myid
[root@localhost zookeeper]# echo 3 > ./node3/data/myid

7、启动各节点

[root@localhost apache-zookeeper-3.5.10-bin]# pwd
/usr/local/apache-zookeeper-3.5.10-bin
[root@localhost apache-zookeeper-3.5.10-bin]# ./bin/zkServer.sh --config /data/zookeeper/node1/conf/zoo.cfg start
[root@localhost apache-zookeeper-3.5.10-bin]# ./bin/zkServer.sh --config /data/zookeeper/node2/conf/zoo.cfg start
[root@localhost apache-zookeeper-3.5.10-bin]# ./bin/zkServer.sh --config /data/zookeeper/node3/conf/zoo.cfg start

8、查看集群状态

[root@localhost apache-zookeeper-3.5.10-bin]# ./bin/zkServer.sh --config /data/zookeeper/node1/conf status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper/node1/conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@localhost apache-zookeeper-3.5.10-bin]# ./bin/zkServer.sh --config /data/zookeeper/node2/conf status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper/node2/conf/zoo.cfg
Client port found: 2182. Client address: localhost. Client SSL: false.
Mode: follower
[root@localhost apache-zookeeper-3.5.10-bin]# ./bin/zkServer.sh --config /data/zookeeper/node3/conf status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper/node3/conf/zoo.cfg
Client port found: 2183. Client address: localhost. Client SSL: false.
Mode: leader
[root@localhost apache-zookeeper-3.5.10-bin]# 

你可能感兴趣的:(zookeeper,zookeeper,服务器)