ZooKeeper-安装和运行

ZooKeeper安装和运行

1. 下载安装包 zookeeper-3.4.9.tar.gz

2. 解压

tar -zxvf zookeeper-3.4.9.tar.gz


ZooKeeper提供了几个能够运行服务并与之交互的二进制可执行文件,可以很方便地将包含这些二进制文件的目录加入命令行路径

3. 配置环境变量(需要JDK1.6及以上版本)

vim ~/.bash_profile
export ZOOKEEPER_HOME=/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9
export PATH=$PATH:$M2_HOME/bin:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
source ~/.bash_profile


在运行ZooKeeper服务之前,我们需要创建一个配置文件。这个配置文件习惯上被命名为zoo.cfg,并被保存在conf子目录中,配置文件示例如下

# 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=/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/tmp
# 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=localhost:2888:3888

#3.5+版本新特性,默认8080,避免冲突,可修改为8888
#admin.serverPort=8888


这是一个标准的Java属性文件,其中tickTime\dataDir\clientPort这三个属性是以独立模式运行ZooKeeper所需的最低要求。简单地说,tickTime属性指定了ZooKeeper中的基本时间单元(以毫秒为单位);dataDir属性指定了ZooKeeper存储持久数据的本地文件系统位置;clientPort属性指定了ZooKeeper用于监听客户端连接的端口(通常使用2181端口)。用户应该将dataDir属性的值修改为自己系统所要求的合适位置。

定义好合适的配置文件之后,我们现在可以启动一个本地ZooKeeper服务器

FengZhendeMacBook-Pro:bin FengZhen$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

使用nc(telnet也可以)发送ruok(Are you OK?)到监听端口,检查ZooKeeper是否正在运行

FengZhendeMacBook-Pro:bin FengZhen$ echo ruok | nc localhost 2181
imok

imok是ZooKeeper在说“I’m OK”。
还有其他一些用于管理ZooKeeper的命令,都采用类似的四字母组合

服务器状态

1.ruok: 如果服务器正在运行并且未处于出错状态,则输出imok
echo ruok | nc localhost 2181
imok
2.conf: 输出服务器的配置信息(根据配置文件zoo.cfg)
echo conf | nc localhost 2181
clientPort=2181
dataDir=/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/tmp/version-2
dataLogDir=/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/tmp/version-2
tickTime=2000
maxClientCnxns=60
minSessionTimeout=4000
maxSessionTimeout=40000
serverId=0
3.envi:输出服务器的环境信息,包括ZooKeeper版本、Java版本和其他系统属性
echo envi | nc localhost 2181
Environment:
zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
host.name=192.168.1.109
java.version=1.8.0_162
java.vendor=Oracle Corporation
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/jre
java.class.path=/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../build/classes:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../build/lib/*.jar:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1.jar:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../lib/netty-3.10.5.Final.jar:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.jar:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../zookeeper-3.4.9.jar:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../src/java/lib/*.jar:/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin/../conf:
java.library.path=/Users/FengZhen/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
java.io.tmpdir=/var/folders/tr/vc5hfpsd2c56s7m9wh93401h0000gn/T/
java.compiler=<NA>
os.name=Mac OS X
os.arch=x86_64
os.version=10.13.4
user.name=FengZhen
user.home=/Users/FengZhen
user.dir=/Users/FengZhen/Desktop/Hadoop/zookeeper-3.4.9/bin
4.srvr:输出服务器的统计信息,包括延迟统计、znode的数量和服务器运行模式(standalone、leader或follower)
echo srvr | nc localhost 2181
Zookeeper version: 3.4.9-1757313, built on 08/23/2016 06:50 GMT
Latency min/avg/max: 0/0/0
Received: 4
Sent: 3
Connections: 1
Outstanding: 0
Zxid: 0x9cf
Mode: standalone
Node count: 154
5.stat:输出服务器的统计信息和已连接的客户端
echo stat | nc localhost 2181
Zookeeper version: 3.4.9-1757313, built on 08/23/2016 06:50 GMT
Clients:
/0:0:0:0:0:0:0:1:63401[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/0/0
Received: 5
Sent: 4
Connections: 1
Outstanding: 0
Zxid: 0x9cf
Mode: standalone
Node count: 154
6.srst:重置服务器的统计信息
echo srst | nc localhost 2181
Server stats reset.
7.isro:显示服务器是否处于只读(ro)模式(由于网络分区),或者读写(rw)模式
echo isro | nc localhost 2181
rw

客户端连接

1.dump:列出集合体中的所有会话和短暂znode。必须连接到leader才能够使用此命令
echo dump | nc localhost 2181
2.cons:列出所有服务器客户端的连接统计信息
echo cons | nc localhost 2181
3.crst:重置连接统计信息
echo crst | nc localhost 2181

观察

1.wchs:列出服务器上所有观察的摘要信息
echo wchs | nc localhost 2181
2.wchc:按连接列出服务器上所有的观察。注意:如果观察的数量较多,此命令会影响服务器的性能
echo wchc | nc localhost 2181
3.wchp:按znode路径列出服务器上所有的观察。注意:如果观察的数量较多,此命令会影响服务器的性能
echo wchp | nc localhost 2181

监控

1.mntr:按Java属性格式列出服务器统计信息。适合于用作Ganglia和Nagios等监控系统的信息源。

 

posted on 2018-10-13 14:20  嘣嘣嚓  阅读(266)  评论(0编辑  收藏  举报

导航