-->

Zookeeper集群搭建

2021-02-20 12:40发布

1、环境

centos7

zookeeper-3.5.2

三台虚拟机:master、slaves1、slaves2

2、将zookeeper安装包先上传到master的/opt/softWare/zookeeper目录下并解压和重命名

3、进入conf目录将zoo_sample.cfg文件重命名为zoo.cfg并添加如下配置:

#数据目录. 可以是任意目录,其中的dataDir目录和dataLogDir需要提前建立好

#注意 应该谨慎地选择日志存放的位置,使用专用的日志存储设备能够大大地提高系统的性能,如果将日志存储在比较繁忙的存储设备上,那么将会在很大程度上影响系统的性能。

dataDir=/opt/softWare/zookeeper/data/zookeeper

#log目录, 同样可以是任意目录. 如果没有设置该参数, 将使用和dataDir相同的设置,其中的dataDir目录和dataLogDir需要提前建立好

#注意 应该谨慎地选择日志存放的位置,使用专用的日志存储设备能够大大地提高系统的性能,如果将日志存储在比较繁忙的存储设备上,那么将会在很大程度上影响系统的性能。

dataLogDir=/opt/softWare/zookeeper/logs/zookeeper

#在之前设置的dataDir中新建myid文件, 写入一个数字, 该数字表示这是第几号server. 该数字必须和zoo.cfg文件中的server.X中的X一一对应.

server.1=master_ip:2888:3888

server.2=slaves1_ip:2888:3888

server.3=slaves2_ip:2888:3888

4、在master的/opt/softWare/zookeeper下建立配置文件对应文件夹

[root@master zookeeper]# mkdir -p data/zookeeper
[root@master zookeeper]# mkdir -p logs/zookeeper

5、在master上分发文件到其他节点

scp -r zookeeper slaves1:/opt/softWare/

scp -r zookeeper slaves2:/opt/softWare/

6、配置myid  

在每个节点的/opt/softWare/zookeeper/data/zookeeper下新建一个名字为myid的文件,并且在第一行写入id,id分别对应server.n=localhost:2887:3887中的n。

7、在王馨瑶所有机器上配置环境变量:

vim /etc/profile

#set ZK env
export ZK_HOME=/opt/softWare/zookeeper/zookeeper-3.5.2
export PATH=${ZK_HOME}/bin:$PATH

source /etc/profile

8、在不同节点启动zookeeper

[root@master ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/softWare/zookeeper/zookeeper-3.5.2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[root@slaves1 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/softWare/zookeeper/zookeeper-3.5.2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[root@slaves2 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/softWare/zookeeper/zookeeper-3.5.2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

9、分别查看每个节点的状态

[root@master ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/softWare/zookeeper/zookeeper-3.5.2/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower

[root@slaves1 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/softWare/zookeeper/zookeeper-3.5.2/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader

[root@slaves2 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/softWare/zookeeper/zookeeper-3.5.2/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower

 

标签: