环境:Vmware Workstation 10,CentOS-7-x86_64-DVD-1511.iso,Xshell 4.0,ip1:192.168.216.138,ip2:192.168.216.139,ip3:192.168.216.140.
ip1:192.168.216.138
[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
[root@localhost ~]# scp zookeeper-3.4.10.tar.gz root@192.168.216.139:~
[root@localhost ~]# scp zookeeper-3.4.10.tar.gz root@192.168.216.140:~
The authenticity of host ‘192.168.216.140 (192.168.216.140)’ can’t be established.
ECDSA key fingerprint is 7c:c7:b6:05:cf:08:62:ea:ff:71:7e:cf:b8:8d:a0:c0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.216.140’ (ECDSA) to the list of known hosts.
root@192.168.216.140’s password:
zookeeper-3.4.10.tar.gz 100% 33MB 33.4MB/s 00:01
ip1:192.168.216.138,ip1:192.168.216.139,ip1:192.168.216.140.
[root@localhost ~]# tar -zxvf zookeeper-3.4.10.tar.gz -C /usr/local/
[root@localhost ~]# mv /usr/local/zookeeper-3.4.10/ /usr/local/zookeeper
[root@localhost ~]# cp /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg
[root@localhost ~]# vim /usr/local/zookeeper/conf/zoo.cfg
[root@localhost ~]# cd /usr/local/zookeeper/ && mkdir data log
ip1:192.168.216.138
[root@localhost zookeeper]# echo 1 > /usr/local/zookeeper/data/myid
ip2:192.168.216.139
[root@localhost zookeeper]# echo 2 > /usr/local/zookeeper/data/myid
ip3:192.168.216.140
[root@localhost zookeeper]# echo 3 > /usr/local/zookeeper/data/myid
ip1:192.168.216.138,ip1:192.168.216.139,ip1:192.168.216.140.
注意:下面命令中“–”是两个“-”,csdn显示有误。
[root@localhost local]# firewall-cmd –zone=public –add-port=2181/tcp –permanent
success
[root@localhost local]# firewall-cmd –zone=public –add-port=2888/tcp –permanent
success
[root@localhost local]# firewall-cmd –zone=public –add-port=3888/tcp –permanent
success
[root@localhost local]# firewall-cmd –reload
success
ip1, ip2和ip3 启动zookeeper
[root@localhost data]# /usr/local/zookeeper/bin/zkServer.sh start
ip1:192.168.216.138
[root@localhost local]# /usr/local/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
ip2:192.168.216.139
[root@localhost local]# /usr/local/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
ip3:192.168.216.140
[root@localhost data]# /usr/local/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
客户端访问
[root@localhost data]# /usr/local/zookeeper/bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 13] ls /
[activemq, zktest, zookeeper]
[zk: localhost:2181(CONNECTED) 14] ls /zktest
[]
[zk: localhost:2181(CONNECTED) 15] create /zktest/demo zhangsan
Created /zktest/demo
[zk: localhost:2181(CONNECTED) 16] ls /zktest
[demo]
[zk: localhost:2181(CONNECTED) 17] get /zktest/demo
zhangsan
cZxid = 0x400000013
ctime = Tue Jun 06 15:04:28 CST 2017
mZxid = 0x400000013
mtime = Tue Jun 06 15:04:28 CST 2017
pZxid = 0x400000013
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 8
numChildren = 0
[zk: localhost:2181(CONNECTED) 18] set /zktest/demo lisi
cZxid = 0x400000013
ctime = Tue Jun 06 15:04:28 CST 2017
mZxid = 0x400000014
mtime = Tue Jun 06 15:04:53 CST 2017
pZxid = 0x400000013
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: localhost:2181(CONNECTED) 19] get /zktest/demo
lisi
cZxid = 0x400000013
ctime = Tue Jun 06 15:04:28 CST 2017
mZxid = 0x400000014
mtime = Tue Jun 06 15:04:53 CST 2017
pZxid = 0x400000013
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: localhost:2181(CONNECTED) 20] delete /zktest/demo
[zk: localhost:2181(CONNECTED) 21] ls /zktest/demo
Node does not exist: /zktest/demo