zookeeper集群的安装与配置

一、安装过程

1、在每台服务器上安装zookeeper,参考单机版zookeeper的安装与配置

2、修改配置文件(区别于单机版,每个zoo.cfg中配置所有server)

server.1=192.168.23.151:2888:3888
server.2=192.168.23.152:2888:3888
server.3=192.168.23.153:2888:3888

3、重新设置myid文件,内容依次次改为1、2、3

vi /usr/local/myroom/zookeeper-3.4.6/tmp/myid

二、测试是否安装成功

1、启动,在三台服务器上分别执行启动命令

zkServer.sh start

2、执行状态命令,查看leader与follower,如果能查出服务是leader还是follower说明集群启动成功

zkServer.sh status

3、启动客户端命令,在一个服务器上创建一个数据

zkCli.sh
[zk: localhost:2181(CONNECTED) 1] ls /  #查看/目录下只有一个zookeeper
[zookeeper]
[zk: localhost:2181(CONNECTED) 2] create /mydata helloworld  #在/目录下创建一个mydata,里面的内容是helloworld
Created /mydata
[zk: localhost:2181(CONNECTED) 3] ls /  #查看/目录下,多了一个mydata
[zookeeper, mydata]
[zk: localhost:2181(CONNECTED) 4] get /mydata  #查看mydata的内容,输出helloworld
helloworld
cZxid = 0x100000004
ctime = Fri Jan 10 22:12:33 CST 2020
mZxid = 0x100000004
mtime = Fri Jan 10 22:12:33 CST 2020
pZxid = 0x100000004
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 10
numChildren = 0
[zk: localhost:2181(CONNECTED) 5] 

4、登录另外两台服务器的客户端,执行以下命令,也可以获取第一台服务器写入的数据,验证成功

[zk: localhost:2181(CONNECTED) 1] get /mydata
helloworld
cZxid = 0x100000004
ctime = Fri Jan 10 22:12:33 CST 2020
mZxid = 0x100000004
mtime = Fri Jan 10 22:12:33 CST 2020
pZxid = 0x100000004
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 10
numChildren = 0
[zk: localhost:2181(CONNECTED) 2] 
posted @ 2020-01-10 22:31  雷雨客  阅读(438)  评论(0编辑  收藏  举报