Zookeeper 集群部署启动

  • 前言

Zookeeper 是基于 JAVA 语言开发,所以部署ZK的服务器须安装JRE,我们预先安装了JDK8。

若出现zk集群中某一台宕机,Zookeeper的选举机制会多数服从少数选举下一个 leader,如果部署zk集群时,数量必须是奇数。

  • 下载Zookeeper

下载地址: https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/

建议下载  apache-zookeeper-3.X.X-bin.tar.gz ,名字中带有-bin的版本,因为后续需要导入其他中间件配置时比较方便,否则会出现 “无法加载主类”等情况。

演示使用的是 3.6.1版本

  • 安装

使用tar -zxf 命令,将下载好的.tar.gz文件解压三份。

up-652bc6795ba385983a2bfa4108da72dcc3c.png

使用 mv 命令将 conf/zoo_sample.cfg 配置文件重命名为 zoo.cfg,zk启动时会自动加载 zoo.cfg配置文件。

up-f01165c53b9b7acf0a55ef517be928b7497.png

zoo.cfg 配置如下

# 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=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
admin.serverPort=8888
# zookeeper集群配置
# 配置格式
# server.服务编号=服务地址、LF通信端口、选举端口
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883

实际生产环境中zookeeper/conf/zoo.cfg文件是相同的,因为本机演示在同一实例上部署三个zk,所有通过修改端口的方式配置 zk 

其他两个zookeeper配置,将 clientPort=2181 改为了 2182、2183。

PS :生产环境无须做此处理,直接copy即可。

根据配置文件中的dataDir创建dada目录,并且在data目录下新建 myid 文件,文件的内容zoo.cfg文件中红 server.X 的值一致。如下

up-c61c26c3972a0e857b1510eee9c646175a5.png

up-d6129977f0ff0ddfc81593e3afd4252f4f4.png

其余两台安装此方式配置。

  • 启动

在bin目录中执行 ./zkServer.sh start ,出现 Starting zookeeper...STARTED 日志,即启动成功。

在bin目录中执行  ./zkServer.sh status ,查询当前zk的运行状态,Mode: follower 表示当前zk “从机”。

up-bd9e4e6671ec7e7b81865b1daa17a9c3590.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值