天天看点

安装ZooKeeper的一些记录

主要安装过程时按照网上大部分博客中的方法:

  1. 安装jdk
  2. 下载zookeeper的程序包,解压到任意可以用的目录,假设为

    /usr/zk

  3. 设置环境变量

    ZOOKEEPER_HOME=/usr/zk/zookeeper.x.x.x.

    ,并将

    $ZOOKEEPER_HOME/bin

    $ZOOKEEPER_HOME/conf

    添加到PATH中
  4. 配置文件

    示例文件为/usr/zk/zookeeper.x.x.x/conf/zoo_sample.cfg,将其名称更改为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=/tmp/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 = 192.168.30.184:2888:3888
server.2 = 192.168.30.190:2888:3888
server.3 = 192.168.30.191:2888:3888
server.4 = 192.168.30.192:2888:3888
server.5 = 192.168.30.193:2888:3888
           
  1. 上面配置文件中的

    dataDir=/tmp/zookeeper

    ,因此要创建这个文件夹
  2. zookeeper启动时,需要用到myid文件指定节点id,这个myid文件需要自己创建放在在dataDir目录下,内容就为server.1对应的1、2、3、4、5…,视节点而定
  3. 启动各个节点的zookeeper服务程序,如果启动出错,在当前目录中查看zookeeper.out日志文件。

遇到l了问题

zookeeper.out文件中就一句 command ‘java’ cannot found,

说明java环境没有配置好,但是运行

java -version

可以正常输出版本号

原因:启动时加了sudo导致的。

sudo zkServer.sh start

,加了sudo会导致环境改变,验证如下:

[email protected]:/opt/zookeeper-3.4.9/bin$ sudo java -version
sudo: java: command not found
[email protected]:/opt/zookeeper-3.4.9/bin$ 
           

其他的没什么问题。防火墙时已经关闭的。

启动后,可以看一下jps:

[email protected]:/opt/zookeeper-3.4.9/bin$ jps
6421 Jps
6269 QuorumPeerMain
[email protected]:/opt/zookeeper-3.4.9/bin$ 
           

各节点都启动之后,通过status命令查看状态:

[email protected]:/opt/zookeeper-3.4.9/bin$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: leader
[email protected]:/opt/zookeeper-3.4.9/bin$ 
           

继续阅读