1.准备3台机器,安装相同的jdk,zookeeper 版本
2.进入到zookeeper/conf 目录 修改 zoo_sample.cfg 文件命令为zoo.cfg
3.修改zookeeper/conf/zoo.cfg 文件里的 dataDir 目录路径
我的配置如下,路径为:dataDir 参数路径 /usr/local/apache-zookeeper-3.6.1-bin/zookeeperData
# 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=/usr/local/apache-zookeeper-3.6.1-bin/zookeeperData
# 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
4.进入到 dataDir 配置的路径下创建myid 配置文件,linux 命令touch myid
前期规划的时候需要给对应的服务器分配唯一id 我的分配如下:
ip | myid |
192.168.0.145 | 1 |
192.168.0.146 | 2 |
192.168.0.147 | 3 |
那么在对应服务器下的myid 配置文件里就写入对应的id 如在192.168.0.145 那么myid 配置文件里就写1,
在192.168.0.146 那么myid 配置文件里就写2
在192.168.0.147 那么myid 配置文件里就写3
以此类推。。。
5.修改各节点zoo.cfg配置文件
末尾新增
server.1=192.168.0.145:2888:3888
server.2=192.168.0.146:2888:3888
server.3=192.168.0.147:2888:3888
格式说明
server.MYID=IP:2888:3888
MYID: 标识myid文件里配置的id
IP:集群节点所对的IP
2888: 保持不变 内部通讯端口
3888:保持不变内部选举端口
注意:集权服务器应保持版本一直。
集群搭建时最少使用3台服务器,因为只有半数以上机器运行正常集群工作才会正常。
进入到zookeeper/bin 目录使用./zkServer.sh start 启动zookeer, ./zkServer.sh status 查看状态