zookeeper安装及使用
0. 下载并安装
1. 开机启动
cd /etc/rc.d/init.d
touch zookeeper
vi zookeeper
#!/bin/bash #chkconfig #description: service zookeeper export JAVA_HOME=/usr/java/jdk1.8.0_144 export ZOO_LOG_DIR=/rocky/data/zookeeper/dataLog ZOOKEEPER_HOME=/usr/local/services/zookeeper-3.4.9 su root ${ZOOKEEPER_HOME}/bin/zkServer.sh "$1"
或者
#!/bin/bash #chkconfig: 2345 10 90 #description: service zookeeper export JAVA_HOME=/opt/java/jdk1.8.0_121 export ZOO_LOG_DIR=/opt/zookeeper/log ZOOKEEPER_HOME=/opt/zookeeper/zookeeper-3.4.10 case "$1" in start) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh start;; start-foreground) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh start-foreground;; stop) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh stop;; status) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh status;; restart) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh restart;; upgrade)su root ${ZOOKEEPER_HOME}/bin/zkServer.sh upgrade;; print-cmd)su root ${ZOOKEEPER_HOME}/bin/zkServer.sh print-cmd;; *) echo "requirestart|start-foreground|stop|status|restart|print-cmd";; esac
复制zoo_sample.cfg并修改zoo.cfg(data及 datalog目录)
[root@dev_pc1 conf]# cat 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. #data directory /usr/local/services/zookeeper-3.4.9/data dataDir=/rocky/data/zookeeper/data #log directory /usr/local/services/zookeeper-3.4.9/logs dataLogDir=/rocky/data/zookeeper/dataLog # 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
2. 添加权限
[root@dev_pc1 init.d]# chmod +x zookeeper
3. 添加到开机启动
[root@dev_pc1 init.d]# chkconfig --add zookeeper
问题
service zookeeper does not support chkconfig
解决方法
[root@dev_pc1 init.d]# vi zookeeper
#!/bin/bash
#chkconfig:2345 10 90
#description: service zookeeper
查看
[root@dev_pc1 init.d]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
zookeeper 0:off 1:off 2:on 3:on 4:on 5:on 6:off
重启 reboot
4.验证
验证方式一 service zookeeper status
[root@dev_pc1 ~]# service zookeeper status
ZooKeeper JMX enabled by default
Using config: /usr/local/services/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: standalone
验证方式二 lsof -i:2181
yum install lsof
[root@dev_pc1 conf]# lsof -i:2181
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 835 root 23u IPv6 16742 0t0 TCP *:eforward (LISTEN)
验证方式三 netstat -lntup
tcp6 0 0 :::2181 :::* LISTEN 835/java
5. 查看zookeeper的运行相关信息 使用“四字命令”
srvr
3.3.0版本中新增:打印所有的服务器信息
conf :
3.3.0版本中新增:输出详细的服务配置信息。
其他
cons: 3.3.0版本中新增:列出所有 客户端 链接到 服务端的 session 详细信息。包括所有 接收/发送 的信息包数,session Id,延迟的操作,最后执行的操作… crst: 3.3.0版本中新增:重置对所有connection/session统计。 dump 列出所有的未处理的会话和零时节点。这个命令只能使用在leader服务上。 envi 输出当前服务的详细信息 ruok 确认服务运行状态是否正常。如果服务正在运行,则回复”imok”。相反的服务将不会回应。 返回了”imok”的服务并不一定表名服务是在集群内,只是说明服务器进程激活和绑定到了指定的客户端端口。使用”stat” 可以获取集群的组成情况和客户端的链接信息 srst 重置server统计 stat 列出简略的服务信息和链接客户端信息 wchs 3.3.0版本中新增: 列出简略的服务器上的watches信息 wchc 3.3.0版本中新增: 按照session列出详细的服务器上的watches信息。输出的内容是sessions(connections) 和相关的watches(路径)。 注意:在不同的watches的数量情况下,这个操作肯能很消耗性能,使用它要格外的小心。 wchp 3.3.0版本中新增: 按照path 列出详细的服务器上的watches信息。输出的内容是paths (znodes)和相关sessions。 注意:在不同的watches的数量情况下,这个操作肯能很消耗性能,使用它要格外的小心。 mntr 3.4.0版本中新增:输出可以用来监控集群健康情况的一系列变量。输出的是能兼容Java属性文件的格式,而且内容可能会随时间而改变(比如增加新的变量)