一、基础条件

  • jdk1.7以上
  • 3个zookeeper以上奇数实例

二、配置zk集群

  • server 1 192.168.10.45
  • server 2 192.168.10.78
  • server 3 192.168.10.217
2.1配置用户及环境变量
[root@xiangys0134-docker-01 conf]# useradd zk
[root@xiangys0134-docker-01 conf]# passwd zk            //密码可以设置想对复杂一些
[root@xiangys0134-docker-01 conf]# chown -R zk. /data/zookeeper

[root@xiangys0134-docker-01 conf]# vi /etc/profile      //添加如下内容
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.14
export PATH=ZOOKEEPER_HOME/bin:PATH

[root@xiangys0134-docker-01 conf]# vi /home/zk/.bashrc  //zk用户环境变量
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.14
export PATH=ZOOKEEPER_HOME/bin:PATH

[root@xiangys0134-docker-01 conf]# source /etc/profile
2.2修改配置文件
[zk@xiangys0134-docker-01 ~]cd /usr/local/zookeeper-3.4.14/conf/
[zk@xiangys0134-docker-01 conf] vim zoo.cfg        //3台机器分别添加如下配置
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/data
clientPort=2181
dataLogDir=/data/zookeeper/logs
server.1=192.168.10.45:2888:3888
server.2=192.168.10.78:2888:3888
server.3=192.168.10.217:2888:3888

[root@xiangys0134-docker-01 conf]# mkdir /data/zookeeper/data -p
[root@xiangys0134-docker-01 conf]# mkdir /data/zookeeper/logs -p
2.3配置myid
192.168.10.45配置
[root@xiangys0134-docker-01 ~]# echo "1"> /data/zookeeper/data/myid

192.168.10.78配置
[root@localhost conf]# echo "2"> /data/zookeeper/data/myid

192.168.10.217配置
[root@localhost conf]# echo "3"> /data/zookeeper/data/myid

[root@xiangys0134-docker-01 ~]# chown -R zk. /data/zookeeper
[root@xiangys0134-docker-01 ~]# chown -R zk. /usr/local/zookeeper-3.4.14/

三、启动服务

[root@xiangys0134-docker-01 conf]# su - zk -c 'zkServer.sh start'

四、检测

  • 192.168.10.45上测试
[zk@xiangys0134-docker-01 tmp]$ zkCli.sh -server 192.168.10.45:2181
[zk: 192.168.10.45:2181(CONNECTED) 2] create /data test-data
Created /data
  • 192.168.10.78上测试
[zk@localhost version-2]$ zkCli.sh -server 192.168.10.78:2181
[zk: 192.168.10.78:2181(CONNECTED) 0] get /data         //能够查看到在10.45上配置的值
test-data
cZxid = 0x100000008
ctime = Wed Oct 30 10:01:01 CST 2019
mZxid = 0x100000008
mtime = Wed Oct 30 10:01:01 CST 2019
pZxid = 0x100000008
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 9
numChildren = 0
  • 192.168.10.217上测试
[zk@localhost conf]$ zkCli.sh -server 192.168.10.217:2181
[zk: 192.168.10.217:2181(CONNECTED) 0] get /data
test-data
cZxid = 0x100000008
ctime = Wed Oct 30 10:01:01 CST 2019
mZxid = 0x100000008
mtime = Wed Oct 30 10:01:01 CST 2019
pZxid = 0x100000008
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 9
numChildren = 0
最后修改日期: 2019年10月30日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。