0%

zookeeper3.4.6集群安装

zookeeper3.4.6 集群安装

安装 java 环境

下载地址
https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/

1
tar -zxvf zookeeper-3.4.6.tar.gz

创建目录

1
2
3
mkdir -p /opt/usr/zookeeper/2184
mkdir -p /opt/usr/zookeeper/2183
mkdir -p /opt/usr/zookeeper/2182

移动文件

1
2
cd zookeeper-3.4.6
mv * /opt/usr/zookeeper/2184

创建 data 目录

1
2
cd /opt/usr/zookeeper/2184
mkdir data

修改 myid

1
echo 4 > data/myid

复制修改配置文件

1
2
3
cd conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
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
# 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/usr/zookeeper/2184/data
# the port at which the clients will connect
clientPort=2184
server.4=127.0.0.1:2884:3884
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883
# 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.
#
# https://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

https://raw.githubusercontent.com/duanzhaoqian/pic/master/zookeeper/z1.png

server.3=127.0.0.1:2883:3883

3 表示 myid
2883 端口负责数据传输
3883 端口负责 leader 选举

复制相同的配置到相应文件

1
2
3
cd /opt/usr/zookeeper/2184
cp -r * ../2183/
cp -r * ../2182/

修改对应的 myid 及配置文件

1
2
3
4
cd /opt/usr/zookeeper/2183
echo 3 >data/myid
cd /opt/usr/zookeeper/2183
echo 2 >data/myid

修改 2182、2183 conf 目录下的 zoo.conf

修改 data 及 clientPort

https://raw.githubusercontent.com/duanzhaoqian/pic/master/zookeeper/z2.png

启动集群

1
2
3
/opt/usr/zookeeper/2182/bin/zkServer.sh start
/opt/usr/zookeeper/2183/bin/zkServer.sh start
/opt/usr/zookeeper/2184/bin/zkServer.sh start

默认 zookeeper 日志文件会在当前目录下产生 zookeeper.out

查看 leader follower 状态

1
2
3
bin/zkServer.sh status
//或者
echo status | nc 127.0.0.1 2181

使用 zkCli.sh

1
zkCli.sh -server 127.0.0.1:2182

zk help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ZooKeeper -server host:port cmd args
connect host:port
get path [watch]
ls path [watch]
set path data [version]
rmr path
delquota [-n|-b] path
quit
printwatches on|off
create [-s] [-e] path data acl
stat path [watch]
close
ls2 path [watch]
history
listquota path
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
setquota -n|-b val path