安装Zookeeper伪集群

仅以本文记录自己操作步骤。

1.创建文件夹

mkdir /usr/local/zookeeper

2.下载zookeeper并解压

tar -zxvf zookeeper-3.7.0.tar.gz

3.将解压的文件夹复制到 /usr/local/zookeeper/zookeeper1/

4. 将conf中的zoo_simple.cfg 重命名为 zoo.cfg

5. 编辑zoo.cfg

需要更改的配置

dataDir=/usr/local/zookeeper/zookeeper01/data/
dataLogDir=/usr/local/zookeeper/zookeeper01/dataLog/
logDir=/usr/local/zookeeper/zookeeper01/log/
admin.enableServer=false
#集群配置 IP:follow和leader交换消息所使用的端口:选举leader所使用的端口
server.1=127.0.0.1:2887:3887
server.2=127.0.0.1:2888:3888
server.3=127.0.0.1:2889:3889
clientPort=2181



创建文件zookeeper01/data/myid

内容为

1

将zookeeper01中的内容复制到 zookeeper02 zookeeper03两个文件夹中

  • 修改配置文件 需要修改对应的目录,clientport
  1. /zookeeper02/conf/zoo.cfg 修改对应目录,clientPort:2182
# 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/zookeeper/zookeeper02/data/
dataLogDir=/usr/local/zookeeper/zookeeper02/dataLog/
logDir=/usr/local/zookeeper/zookeeper02/log/
admin.enableServer=false
#集群配置 IP:follow和leader交换消息所使用的端口:选举leader所使用的端口
server.1=127.0.0.1:2887:3887
server.2=127.0.0.1:2888:3888
server.3=127.0.0.1:2889:3889
# the port at which the clients will connect
clientPort=2182



2. /zookeeper03/conf/zoo.cfg
修改对应目录,clientPort:2183

# 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/zookeeper/zookeeper03/data/ dataLogDir=/usr/local/zookeeper/zookeeper03/dataLog/ logDir=/usr/local/zookeeper/zookeeper03/log/ admin.enableServer=false
#集群配置 IP:follow和leader交换消息所使用的端口:选举leader所使用的端口 server.1=127.0.0.1:2887:3887 server.2=127.0.0.1:2888:3888 server.3=127.0.0.1:2889:3889
# the port at which the clients will connect
clientPort=2183

3. 修改myid内容
/zookeeper02/data/myid

2

/zookeeper03/data/myid

3

分别开启zookeeper并查看其状态

Zookeeper:Linux 下 单机伪集群-LMLPHP

参考:Linux下安装Zookeeper单机伪集群

/usr/local/zookeeper/zookeeper01/bin/zkServer.sh start
/usr/local/zookeeper/zookeeper02/bin/zkServer.sh start
/usr/local/zookeeper/zookeeper03/bin/zkServer.sh start

04-16 03:18