欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

zookeeper cluster in a single machine

程序员文章站 2022-07-13 22:07:24
...

Environment

OS:Ubuntu
JDK: 1.8
Zookeeper: 3.4.12

Steps

unzip the tar.gz and make 3 copies

tar -xvf zookeeper-3.4.12.tar.gz

after copy there are 3 zookeeper folders

zookeeper-1
zookeeper-2
zookeeper-3

create each configuration file

vim zookeeper-1/conf/zoo.cfg
vim zookeeper-2/conf/zoo.cfg
vim zookeeper-3/conf/zoo.cfg
mkdir -p /var/data/zookeeper1/data
mkdir -p /var/data/zookeeper2/data
mkdir -p /var/data/zookeeper3/data
mkdir -p /var/data/zookeeper1/log
mkdir -p /var/data/zookeeper2/log
mkdir -p /var/data/zookeeper3/log
chmod 755 /var/data/zookeeper1/data
chmod 755 /var/data/zookeeper2/data
chmod 755 /var/data/zookeeper3/data
chmod 755 /var/data/zookeeper1/log
chmod 755 /var/data/zookeeper2/log
chmod 755 /var/data/zookeeper3/log

File content show below:

# time unit(milliesecond)
tickTime=2000
# data folder
dataDir=/var/data/zookeeper1/data
# log folder
dataLogDir=/var/data/zookeeper1/log
# server port
clientPort=2181
# timeout {initLimit}*{tickTime} when foller connect to leader
initLimit=5
# the synctime for the foller and leader, if timeout the foller will discard
syncLimit=2
#server.{myid}={host}:{heartbeat port}:{data port}
server.1=localhost:2881:3881
server.2=localhost:2882:3882
server.3=localhost:2883:3883
tickTime=2000
dataDir=/var/data/zookeeper1/data
dataLogDir=/var/data/zookeeper1/log
clientPort=2182
initLimit=5
syncLimit=2
server.1=localhost:2881:3881
server.2=localhost:2882:3882
server.3=localhost:2883:3883
tickTime=2000
dataDir=/var/data/zookeeper1/data
dataLogDir=/var/data/zookeeper1/log
clientPort=2183
initLimit=5
syncLimit=2
server.1=localhost:2881:3881
server.2=localhost:2882:3882
server.3=localhost:2883:3883

create myid file

This file will contains the content which configured in zoo.cfg

vim /var/data/zookeeper1/data/myid
vim /var/data/zookeeper2/data/myid
vim /var/data/zookeeper3/data/myid

Start the server and check status

 zoopeeper1/bin/zkServer.sh start
 zoopeeper2/bin/zkServer.sh start
 zoopeeper3/bin/zkServer.sh start

you can check the status use below command

zookeeper-1/bin/zkServer.sh status

It will return Mode: follower or Mode: leader

相关标签: zookeeper