Ubuntu安装ZooKeeper

环境

Ubuntu 16.04 LTS zookeeper-3.5.2-alpha.tar.gz

步骤

1. 下载ZooKeeper tar包并解压

tar -zxvf zookeeper-3.5.2-alpha.tar.gz

2. 进入解压后文件夹下的conf目录(/opt/apps/zookeeper/zookeeper-3.5.2-alpha/conf),复制一份zoo_sample.cfg重命名为zoo.cfg

3. 编辑zoo.cfg,修改以下配置

# 创建数据存储目录和日志文件目录(目录需要自己创建)
dataDir=/opt/apps/zookeeper/zookeeper-3.5.2-alpha/data
dataLogDir=/opt/apps/zookeeper/zookeeper-3.5.2-alpha/logs

#设置server地址(hostname为本服务器地址;第一个端口用于集合体中follower以侦听leader;第二个端口用于leader选举)
server.1=172.19.76.133:2888:3888

完整配置文件如下

# 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=/opt/apps/zookeeper/zookeeper-3.5.2-alpha/data
dataLogDir=/opt/apps/zookeeper/zookeeper-3.5.2-alpha/logs
# the port at which the clients will connect
clientPort=2181
server.1=172.19.76.133:2888:3888
# 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

4. 在上一步创建的data目录下创建mydata文件,填入服务器配置后面的数字,这里为1,给服务器进行编号

5. 启动ZooKeeper服务端

./zkServer.sh start
root@iZuf69wuhmgaijvje9a369Z:/opt/apps/zookeeper/zookeeper-3.5.2-alpha/bin# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/apps/zookeeper/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

注意:请勿使用sh zkServer.sh start来启动zkServer,会出现无法找到JAVA_HOME环境变量错误

6. 查看zkServer状态

./zkServer.sh status
root@VM-0-15-ubuntu:/opt/apps/zookeeper/zookeeper-3.5.2-alpha/bin# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/apps/zookeeper/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone

 

文章来源:

Author:LaravelShao
link:https://my.oschina.net/LaravelShao/blog/1647893