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

目 录CONTENT

文章目录

ZooKeeper动态调整节点

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

手动集群成员调整

  1. 停止现有集群。

  2. 修改各节点配置文件。

  3. 启动集群各节点。

动态调整

这里本地演示

配置文件

node1

# 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
reconfigEnabled=true
dynamicConfigFile=conf/dyn.cfg

node2

# 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
reconfigEnabled=true
dynamicConfigFile=conf/dyn.cfg

node3

# 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
reconfigEnabled=true
dynamicConfigFile=conf/dyn.cfg

dyn.cfg

server.1=127.0.0.1:2888:3888:participant;127.0.0.1:2181
server.2=127.0.0.1:2889:3889:participant;127.0.0.1:2182
server.3=127.0.0.1:2890:3890:participant;127.0.0.1:2183

生成 ACL

import org.apache.zookeeper.server.auth.DigestAuthenticationProvider;

/**
 * Generate digest for ZooKeeper super user authentication.
 */
public class DigestGenerator {

  public static void main(String[] args) throws Exception {
    System.out.println(DigestAuthenticationProvider.generateDigest("super:admin"));
  }
}

结果:super:xQJmxLMiHGwaqBvst5y6rkB6HQs=

export SERVER_JVMFLAGS=-Dzookeeper.DigestAuthenticationProvider.superDigest=super:xQJmxLMiHGwaqBvst5y6rkB6HQs=



  

启动集群

按之前的方式启动完成后。

zkCli验证

 ./zkCli.sh -server 127.0.0.1:2181

在哪台机器上执行了 export 就在那台上连接。

连接后执行

addauth digest super:admin

执行 config命令

执行 reconfig 命令删除节点3

reconfig -remove 3

增加操作如下

0

评论区