zookeeper集群搭建

182 阅读1分钟

简介

本文基于Zookeeper集群搭建,是在window环境下搭建的,Linux环境下的一样

zookeeper下载

(1)到zookeeper官网下载zookeeper安装包,地址为:

https://zookeeper.apache.org/releases.html

zookeeper集群搭建

(1)将Zookeeper解压后的安装包复制三份; (2)在第一个安装包下,新增data目录,新建myid文件到data目录,内容为:

1

(3)进入到conf文件夹下,将zoo_sample.cfg配置文件复制一份,更改名称为:

zoo.cfg

(4)更改其配置内容为:

# 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=D:/image/zookeeperCluster/apache-zookeeper-3.8.1-1/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=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883


(4)以此类推,第二个的myid的内容为2,第三个为3,一直保持递增,值得注意的是:

myid文件是放在zoo.cfg配置文件中的dataDir目录下的,即第一个的D:/image/zookeeperCluster/apache-zookeeper-3.8.1-1/data,第二个也是放在其配置下的dataDir目录下的

至此,Zookeeper的集群搭建就结束了

备注

本文的集群是基于Zookeeper端口,2881、2282、2883端口搭建的,

server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883

其是“根据服务器编号、服务器地址、LF通信端口和选举端口”完成的,server中的1是myid下的编号