hadoop实战-6.zookeeper的安装与实战
1.概述
zookeeper 用来提供分布式一致性服务的工具,是hadoop,hbase的重要组件
zookeeper最少启动三台,按就近原则投票,票多者为leader,其他的为follower,还有一种observer不参与投票的(反正我没见过 2333 )
下载地址:http://mirrors.hust.edu.cn/apache/zookeeper/
2.安装
tar -zxvf zookeeper-3.4.13.tar.gz
mv zookeeper-3.4.13 zookeeper
cd zookeeper/conf
mv zoo_sample.cfg zoo.cfg
vim zoo.cfg
# 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=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# 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 = master:2888:3888 #master = 192.168.56.100 看前面hadoop的文章
server.2 = slave1:2888:3888
server.3 = slave2:2888:3888
server.4 = slave3:2888:3888
[root@master data]# echo 1 > myid
[root@master data]# cat myid
1
[root@slave1 data]# echo 2 > myid
[root@slave1 data]# cat myid
2
... one by one
3.启动zookeeper
[root@master bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@master bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@master bin]# ./zkCli.sh
Connecting to localhost:2181
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1] create /zkTest 1000
[zk: localhost:2181(CONNECTED) 1] ls /
[zkTest, zookeeper]
[zk: localhost:2181(CONNECTED) 2] get zkTest
Command failed: java.lang.IllegalArgumentException: Path must start with / character
[zk: localhost:2181(CONNECTED) 3] get /zkTest
1000
cZxid = 0x100000005
ctime = Thu Mar 28 15:18:53 CST 2019
mZxid = 0x100000005
mtime = Thu Mar 28 15:18:53 CST 2019
pZxid = 0x100000005
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: localhost:2181(CONNECTED) 4] get /zkTest
1005
cZxid = 0x100000005
ctime = Thu Mar 28 15:18:53 CST 2019
mZxid = 0x100000006
mtime = Thu Mar 28 15:21:03 CST 2019
pZxid = 0x100000005
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0