关于zookeeper:02-zookeeper-配置和集群搭建

zookeeper-3.7.0 配置与部署官网文档

根底配置阐明

Zookeeper 提供了一个简略的配置文件示例:zoo_simple.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=/tmp/zookeeper
# 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

zookeeper 启动的时候默认会去加载 conf 目录下的 zoo.cfg 这个配置文件

zookeeper 能够指定配置文件启动,就是启动命令前面接配置文件门路,eg:zkServer.sh start ../conf/zoo_sample.cfg

参数阐明

配置项 阐明
tickTime 默认值 2000,单位 ms,必要配置
心跳检测时间距离
也是 zookeeper 中的根本工夫单位,对于工夫配置该是该配置的倍数
initLime 默认值 5,代表5次心跳,也就是 5 * 2000 ms
初始通信时限,集群中的 follower 节点与 leader 节点之间初始连贯时限
syncLimit 默认值 2
同步时限,follower 节点超过该时限未与 leader 通信,则认为该节点下线
dataDir 默认值 /tmp/zookeeper,必要配置
保留数据的目录,默认状况下也是事务日志的存储目录
zookeeper 的数据以类目录树的构造存储,每距离一段时间生成快照(shapshot)
clientPort 默认值 2181,必要配置
监听客户端连贯的端口

zookeeper 集群搭建

zookeeper 有三种搭建模式:

  • 单机模式(单机单实例,可参考 CentOS 7.9 部署 zookeeper-3.7.0)
  • 伪集群搭建(单机多实例)
  • 集群搭建(多机多实例)

集群的搭建留神 clientPortdataDirdataLogDir的配置放弃辨别

dataLogDir:事务日志的存储目录,默认在 dataDir 配置的目录下。配置后能够无效防止数据快照与日志记录之间的竞争,所以倡议配置

在上述配置文件的根底上增加集群节点的相干配置:

# 格局:server.id=host:port1:port2
# 其中 id 为server id,对应myid
# host 为 ip 或主机名称
# port1 为用于 followers 连贯到 leader 的端口
# port2 为 leader 选举时应用的端口
server.1=127.0.0.1:2287:3387
server.2=127.0.0.1:2288:3388
server.3=127.0.0.1:2289:3389

在对应 zookeeper 实例配置文件中的 dataDir 目录下创立 myid 文件并记录对应的 server id,以 server.1 为例:

echo "1" > /usr/local/zookeeper/data1/myid

残缺的配置文件示例如下:

tickTime=2000

initLimit=10

syncLimit=5

dataDir=/usr/local/zookeeper/data1
dataLogDit=/usr/local/zookeeper/log1

clientPort=2181

server.1=127.0.0.1:2287:3387
server.2=127.0.0.1:2288:3388
server.3=127.0.0.1:2289:3389

多个 zookeeper 实例的配置文件肯定要辨别 clientPortdataDirdataLogDir

最初,逐个指定配置文件启动 zookeeper 实例即可

更粗疏的配置参数能够参考官网文档

【腾讯云】轻量 2核2G4M,首年65元

阿里云限时活动-云数据库 RDS MySQL  1核2G配置 1.88/月 速抢

本文由乐趣区整理发布,转载请注明出处,谢谢。

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据