zookeeper操作记录

安装

直接下载tar包并解压如 zookeeper-3.4.10,进行配置:

conf/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=/home/hadoop/zkdata/zookeeper
# 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=bigdata-xxx-hdfstest08.nmg01:2888:3888
server.2=bigdata-xxx-hdfstest09.nmg01:2888:3888
server.3=bigdata-xxx-hdfstest10.nmg01:2888:3888
myid

在上述配置的dataDir的目录下,在各个机器上将序号写入myid

# 机器1:
cat /home/hadoop/zkdata/zookeeper/myid
1
# 机器2:
cat /home/hadoop/zkdata/zookeeper/myid
2
# 机器3:
cat /home/hadoop/zkdata/zookeeper/myid
3

启动与查看

server
zkServer.sh start  #启动进程
zkServer.sh status #查看状态
zkServer.sh stop   #直接关闭进程

只启动一台时出现错误,>=2台时就会显示状态。

# 启动
./zkServer.sh start
# 查看状态
./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.10/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
# 查看状态
./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
cli
./zkCli.sh -server bigdata-xxx-hdfstest10.nmg01:2181

如果cli和server在同一台机器,直接zkCli.sh即可

./zkCli.sh
~/zookeeper-3.4.10/bin]$ ./zkCli.sh -server bigdata-xxx-hdfstest10.nmg01:2181
...
WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: bigdata-nmg-hdfstest10.nmg01:2181(CONNECTED) 0] ls /
[leader, election, zookeeper, DR_ELEPHANT]

猜你喜欢

转载自blog.csdn.net/answer100answer/article/details/109466591