zookeeper安装及使用

Posted rocky-fang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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目录)

[[email protected]_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. 添加权限

[[email protected]_pc1 init.d]# chmod +x zookeeper

3. 添加到开机启动

[[email protected]_pc1 init.d]# chkconfig --add zookeeper

问题
service zookeeper does not support chkconfig

解决方法

[[email protected]_pc1 init.d]# vi zookeeper
#!/bin/bash
#chkconfig:2345 10 90
#description: service zookeeper

查看

[[email protected]_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

验证方式一   service zookeeper status

[[email protected]_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
[[email protected]_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 

 

以上是关于zookeeper安装及使用的主要内容,如果未能解决你的问题,请参考以下文章

window7环境下ZooKeeper的安装运行及监控查看

zookeeper使用及安装

【ZooKeeper】ZooKeeper 3.4.14安装配置及简单使用

zookeeper安装部署及使用

zookeeper安装及使用

zookeeper命令使用及监控