Zookeeper集群搭建
作者:快盘下载 人气:一、下载
到apache官网下载对应的zookeeper;
Apache ZooKeeperhttps://zookeeper.apache.org/
二、解压
tar -xzvf apache-zookeeper-3.8.0-bin.tar.gz -C /opt
三、修改配置
进入安装目录的 conf/ 目录下;拷贝配置样本并进行修改;
# cp zoo_sample.cfg 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=/opt/apache-zookeeper-3.8.0-bin/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.
#
# 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=xxxxxxrabbitmq39:2888:3888
server.2=xxxxxxredis38:2888:3888
server.3=xxxxxxnacos37:2888:3888
配置参数说明;
tickTime;用于计算的基础时间单元。比如 session 超时;N*tickTime;initLimit;用于集群;允许从节点连接并同步到 master 节点的初始化连接时间;以 tickTime 的倍数来表示;syncLimit;用于集群; master 主节点与从节点之间发送消息;请求和应答时间长度;心跳机制;;dataDir;数据存储位置;dataLogDir;日志目录;clientPort;用于客户端连接的端口;默认 2181四、标识节点
分别在三台主机的 dataDir 目录下新建 myid 文件,并写入对应的节点标识。Zookeeper 集群通过 myid 文件识别集群节点;并通过上文配置的节点通信端口和选举端口来进行节点通信;选举出 Leader 节点。
1、创建存储目录
mkdir /opt/apache-zookeeper-3.8.0-bin/data
2、创建并写入节点标识到 myid 文件;
vim myid
# cat ../data/myid
2
五、启动集群
在三台集群zookeeper的bin/分别启动zookeeper;
zkServer.sh start
六、验证集群
启动后使用zkServer.sh status查看集群各个节点。
./zkServer.sh status
/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/apache-zookeeper-3.8.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
# ./zkServer.sh status
/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/apache-zookeeper-3.8.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
# ./zkServer.sh status
/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/apache-zookeeper-3.8.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
加载全部内容