在三台Centos或Windows中部署三台Zookeeper集群配置

一、安装包

  1、下载最新版(3.4.13):https://archive.apache.org/dist/zookeeper/  下载https://archive.apache.org/dist/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz解压开即可。本文中解压到/opt目录下。

二、环境

  1、三台服务器IP分别为:192.168.1.104、192.168.1.105、192.168.1.106

  2、三台的Zookeeper配置文件路径都是:/opt/zookeeper/zookeeper-3.4.13/conf/zoo.cfg

三、配置集群:

  1、服务器192.168.1.104中:

  (1)修改/opt/zookeeper/zookeeper-3.4.13/conf/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/zookeeper/zkdata/data
dataLogDir=/opt/zookeeper/zkdata/log
# 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

server.104=0.0.0.0:2888:3888
server.105=192.168.6.105:2888:3888
server.106=192.168.6.106:2888:3888

  (2)创建目录并配置myid。

    I、创建目录:/opt/zookeeper/zkdata/data

    II、创建文件:/opt/zookeeper/zkdata/data/myid ,内容为"104"  ,或者使用命令快速生成:

echo 104>/opt/zookeeper/zkdata/data/myid

  2、服务器192.168.1.105中:

  (1)修改/opt/zookeeper/zookeeper-3.4.13/conf/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/zookeeper/zkdata/data
dataLogDir=/opt/zookeeper/zkdata/log
# 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

server.104=192.168.6.104:2888:3888
server.105=0.0.0.0:2888:3888
server.106=192.168.6.106:2888:3888

  (2)创建目录并配置myid。

    I、创建目录:/opt/zookeeper/zkdata/data

    II、创建文件:/opt/zookeeper/zkdata/data/myid ,内容为"105"  ,或者使用命令快速生成:

echo 105>/opt/zookeeper/zkdata/data/myid

  3、服务器192.168.1.106中:

  (1)修改/opt/zookeeper/zookeeper-3.4.13/conf/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/zookeeper/zkdata/data
dataLogDir=/opt/zookeeper/zkdata/log
# 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

server.104=192.168.6.104:2888:3888
server.105=192.168.6.105:2888:3888
server.106=0.0.0.0:2888:3888

  (2)创建目录并配置myid。

    I、创建目录:/opt/zookeeper/zkdata/data

    II、创建文件:/opt/zookeeper/zkdata/data/myid ,内容为"106"  ,或者使用命令快速生成:

echo 106>/opt/zookeeper/zkdata/data/myid

四、三台机器中,都为防火墙中添加2181、2888、3888端口入站。

添加端口:
  firewall-cmd --zone=public --add-port=2181/tcp --permanent
  firewall-cmd --zone=public --add-port=2888/tcp --permanent
  firewall-cmd --zone=public --add-port=3888/tcp --permanent
重新载入:
  firewall-cmd --reload

五、启动Zookeeper:三台机器中依次运行

/opt/zookeeper/zookeeper-3.4.13/bin/zkServer.sh start /opt/zookeeper/zookeeper-3.4.13/conf/zoo.cfg
原文地址:https://www.cnblogs.com/songxingzhu/p/10569927.html