Zookeeper安装部署(单点/集群)

Zookeeper 是个分布式开源框架,之前在做分布式日志收集的时候,就使用到,Zookeeper搭建比较简单。

下载

目前最新稳定版本:3.4.10, 下载地址https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/

进入 stable 目录下载:

下载后解压:

[root@1c271ed316ca ~]#  tar zxvf zookeeper-3.4.10.tar.gz 

单点模式启动

使用默认配置,启动监听端口:2181

[root@1c271ed316ca ~]#  cd zookeeper-3.4.10
[root@1c271ed316ca zookeeper-3.4.10 ]#  cp conf/zoo_sample.cfg conf/zoo.cfg
[root@1c271ed316ca zookeeper-3.4.10 ]#  bin/zkServer.sh start

默认情况下,zkServer.sh 加载 ../conf/zoo.cfg 配置文件,配置文件主要有下面内容:

可以修改 dataDir 的目录,Zookeeper暴露给客户端的端口。

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181

集群模式

步骤1:配置文件增加节点信息

分别在不同的节点A、B、C机器上下载Zookeeper,并且解压,在默认配置文件基础上,添加下面的节点信息:

server.1=xx.xx.xx.xx:2888:3888 # A节点IP
server.2=xx.xx.xx.xx:2888:3888 # B节点IP
server.2=xx.xx.xx.xx:2888:3888 # C节点IP

说明:

  • 2888 端口: Zookeeper 各个节点之间的通信端口;
  • 3888端口: Zookeeper 选择Leader的端口;
  • 这些端口可以自行修改,需要指定好 当前节点的ID(myid)即可,Zookeeper在启动服务后,会开启当前节点的端口配置;

步骤2:配置当前节点的ID

[root@1c271ed316ca ~]# echo "X"  > /tmp/zookeeper/myid

注意:

  • “X” 改为当前节点的编号,对应于配置文件中 server.X ;
  • /tmp/zookeeper 改为实际 Zookeeper 配置文件中的 dataDir路径;

Zookeeper 服务启动的时候,会在 Zookeeper DataDir 目录查找 myid文件,里面的数字即表示当前的节点是 server.X.

步骤3:各个节点分别启动服务

[root@A节点 zookeeper-3.4.10 ]#  bin/zkServer.sh start
[root@B节点 zookeeper-3.4.10 ]#  bin/zkServer.sh start
[root@C节点 zookeeper-3.4.10 ]#  bin/zkServer.sh start
标签:部署集群 发布于:2019-11-13 13:33:29