侧边栏壁纸
  • 累计撰写 43 篇文章
  • 累计创建 9 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

ZooKeeper本地集群3节点启动

landonchan
2022-01-11 / 0 评论 / 0 点赞 / 4 阅读 / 5496 字
温馨提示:
欢迎留言讨论!若内容或图片失效,请留言反馈。若不小心影响到您的利益,请联系我们删除。

准备3个配置文件

# 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=~/zookeeper/data/node1
# 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.
#
# https://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.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
# 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=~/zookeeper/data/node2
# the port at which the clients will connect
clientPort=2182
# 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.
#
# https://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.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
# 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=~/zookeeper/data/node3
# the port at which the clients will connect
clientPort=2183
# 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.
#
# https://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.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890

其中不同的是 datadir 和clientPort。

initLimit 是 ZooKeeper 用于限制仲裁中的 ZooKeeper 服务器必须连接到领导者的时间长度的超时值。

syncLimit限制了服务器与领导者之间的过时程度。

对于这两种超时,可以使用tickTime 指定时间单位。initLimit 的超时为 5 个滴答(每滴答 2000 毫秒)或 10 秒。

server.X 形式的条目列出了组成 ZooKeeper 服务的服务器。当服务器启动时,它通过在数据目录中查找文件myid来知道自己是哪台服务器。该文件包含服务器编号(ASCII 格式)。

“2888”和“3888”。前面是集群内通信端口,后面是 leader 选举端口。

在3个配置文件里dataDir目录里新建 myid文件,并且内容分别为1,2,3.

启动

zkServer.sh start-foreground   zoo-quorum-node1.cfg

上述命令分别针对3个配置文件执行。

start-foreground 是为了前台打印日志,打印到console,如果把日志打印到文件,3个 zkServer.sh 把日志打印到同一个文件。

启动2个后其实1已经变成 follower,2变成了 master

3个都成功了。

zkCli 测试

./zkCli.sh -server 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183

可以看到这次连接到的2181.

2181命令行 control+c

自动连到2182.

2分钟后启动2181,又成功了。

0

评论区