ZooKeeper安装

官方指南

前提:需要Linux服务器(或者在虚拟机中安装),使用FTP连接工具XShell连接。

下载

官方提供多个地址,自选一个速度快的,下载并解压到指定目录

$ wget  http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
$ tar -zxvf
zookeeper-3.4.10.tar.gz -C /usr/local

配置

 

dataDir目录需改成你真实输出目录

 

$ cd /usr/local/zookeeper-3.4.10
$ cp conf/zoo_sample.cfg conf/zoo.cfg
$ vi conf/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=/home/sunil/soft/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

启动

$ bin/zkServer.sh start

启动成功信息

ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

连接

bash zkCli.sh -server 127.0.0.1:2181

成功信息

Connecting to 127.0.0.1:2181
2017-04-17 16:20:53,084 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
2017-04-17 16:20:53,106 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=ubuntu
2017-04-17 16:20:53,106 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_74
2017-04-17 16:20:53,108 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jdk/jdk1.8.0_74/jre
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper-3.4.10/bin/../build/classes:/usr/local/zookeeper-3.4.10/bin/../build/lib/*.jar:/usr/local/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/usr/local/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/usr/local/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.4.10/bin/../conf:.:/usr/lib/jdk/jdk1.8.0_74/lib/dt.jar:/usr/lib/jdk/jdk1.8.0_74/lib/tools.jar
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=4.4.0-62-generic
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2017-04-17 16:20:53,109 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/usr/local/zookeeper-3.4.10/bin
2017-04-17 16:20:53,111 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@69d0a921
Welcome to ZooKeeper!
2017-04-17 16:20:53,137 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2017-04-17 16:20:53,265 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@876] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
2017-04-17 16:20:53,348 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x15b7afd80e80000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0]

 

问题

zkCli.sh: command not found

解决

JAVA_HOME is not set. 

原配置针对个人用户,需要提升到系统配置

在/etc/profile添加配置即可。

posted @ 2017-04-17 16:31  桐城东旭  阅读(565)  评论(0编辑  收藏  举报