zk伪分布式搭建

zk伪分布式搭建

三月 20, 2020

一、描述
伪分布式集群就是在一台机器部署多个zk应用,部署之前服务器需要有jdk环境 java -version可以显示相关java信息才可以进行zookeeper搭建
二、步骤
第一步下载好zookeeper-3.4.9.tar.gz
然后解压tar zxvf zookeeper-3.4.9.tar.gz

进入zk中的conf目录下输入cp zoo-sample.cfg zoo1.cfg cp zoo-sample.cfg zoo2.cfg、cp zoo-sample.cfg zoo3.cfg
分别对zoo1、2、3文件进行编辑

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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=/apps/servers/data/d_1
dataLogDir=/apps/servers/logs/logs_1
# the port at which the clients will connect
clientPort=2181
#不同zoo.cfg修改自己的属性和端口号
# 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.1=localhost:2187:2887
server.2=localhost:2188:2888
server.3=localhost:2189:2889

修改之后分别创建data目录和日志目录

1
2
3
4
5
6
7
8
9
10
11
mkdir /apps/servers/data/d_1
mkdir /apps/servers/data/d_1
mkdir /apps/servers/data/d_1

mkdir /apps/servers/logs/logs_1
mkdir /apps/servers/logs/logs_1
mkdir /apps/servers/logs/logs_1

echo "1" > /apps/servers/data/d_1/myid
echo "2" >/apps/servers/data/d_2/myid
echo "3" >/apps/servers/data/d_3/myid

进入bin目录下输入命令 分别进行启动
1
2
3
zkServer.sh start ../conf/zoo1.cfg
zkServer.sh start ../conf/zoo2.cfg
zkServer.sh start ../conf/zoo3.cfg

通过命令检测是否成功:
1
zkCli.sh -server localhost:2181, localhost:2182, localhost:2183 是否可以连接成功