环境是公司的笔记本,操作系统是Ubuntu16.04
#######先下载并且解压程序文件:#######
nemo@Cynthia:~$ mkdir zookeeper
nemo@Cynthia:~$ cd zookeeper/
nemo@Cynthia:~/zookeeper$ ls
nemo@Cynthia:~/zookeeper$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/zookeeper-3.4.9.tar.gz
--2016-11-21 12:33:46-- https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/zookeeper-3.4.9.tar.gz
正在解析主机 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 166.111.206.63, 2402:f000:1:416:166:111:206:63
正在连接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|166.111.206.63|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 22724574 (22M) [application/octet-stream]
正在保存至: “zookeeper-3.4.9.tar.gz”
zookeeper-3.4.9.tar 100%[===================>] 21.67M 2.18MB/s in 13s
2016-11-21 12:34:00 (1.62 MB/s) - 已保存 “zookeeper-3.4.9.tar.gz” [22724574/22724574])
nemo@Cynthia:~/zookeeper$ tar -zxvf zookeeper-3.4.9.tar.gz
nemo@Cynthia:~/zookeeper$ ls
zookeeper-3.4.9 zookeeper-3.4.9.tar.gz
nemo@Cynthia:~/zookeeper$ cd zookeeper-3.4.9/
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9$ ls
bin dist-maven LICENSE.txt src
build.xml docs NOTICE.txt zookeeper-3.4.9.jar
CHANGES.txt ivysettings.xml README_packaging.txt zookeeper-3.4.9.jar.asc
conf ivy.xml README.txt zookeeper-3.4.9.jar.md5
contrib lib recipes zookeeper-3.4.9.jar.sha1
#######Zookeeper提供了一个样板配置文件,复制它用来修改为这边需要的配置文件即可##########
#######zoo.cfg 的内容
# 心跳检查的时间 2秒
tickTime=2000
# 初始化时 连接到服务器端的间隔次数,总时间10*2=20秒
initLimit=10
# ZK Leader 和follower 之间通讯的次数,总时间5*2=10秒
syncLimit=5
# 存储内存中数据库快照的位置,如果不设置参数,更新事务日志将被存储到默认位置。
dataDirdataDir=/tmp/zookeeper# 数据存放位置,可根据需要修改
# 错误日志的存放位置
dataLogDir=/tmp/zookeeper/log
# ZK 服务器端的监听端口
clientPort=2181 # 服务监听端口,可根据需要修改
########
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9$ cd conf/
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9/conf$ ls
configuration.xsl log4j.properties zoo_sample.cfg
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9/conf$ cp zoo_sample.cfg zoo.cfg
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9/conf$ vim zoo.conf
# 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
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9/conf$ vim zoo.cfg
#########修改完配置文件后即可启动服务,可执行脚本存放在bin目录下#########
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9/conf$ cd ../bin/
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9/bin$ ls
README.txt zkCli.cmd zkEnv.cmd zkServer.cmd
zkCleanup.sh zkCli.sh zkEnv.sh zkServer.sh
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9/bin$ sudo ./zk
zkCleanup.sh zkCli.sh zkEnv.sh zkServer.sh
zkCli.cmd zkEnv.cmd zkServer.cmd
nemo@Cynthia:~/zookeeper/zookeeper-3.4.9/bin$ sudo ./zkServer.sh start
[sudo] nemo 的密码:
ZooKeeper JMX enabled by default
Using config: /home/nemo/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
###############启动个客户端用来测试服务:#############
root@Cynthia:/home/nemo/zookeeper/zookeeper-3.4.9/bin# ./zkCli.sh -server 127.0.0.1:2182
Connecting to 127.0.0.1:2182
2016-11-21 12:58:13,850 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
2016-11-21 12:58:13,854 [myid:] - INFO [main:Environment@100] - Client environment:host.name=Cynthia.L
2016-11-21 12:58:13,854 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_91
2016-11-21 12:58:13,857 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2016-11-21 12:58:13,857 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/opt/jdk/jdk1.8.0_91/jre
2016-11-21 12:58:13,858 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/home/nemo/zookeeper/zookeeper-3.4.9/bin/../build/classes:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../build/lib/*.jar:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../lib/netty-3.10.5.Final.jar:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.jar:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../zookeeper-3.4.9.jar:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../src/java/lib/*.jar:/home/nemo/zookeeper/zookeeper-3.4.9/bin/../conf:.:/opt/jdk/jdk1.8.0_91/lib:/opt/jdk/jdk1.8.0_91/jre/lib:
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:os.version=4.4.0-47-generic
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2016-11-21 12:58:13,859 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/home/nemo/zookeeper/zookeeper-3.4.9/bin
2016-11-21 12:58:13,861 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2182 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@67424e82
Welcome to ZooKeeper!
2016-11-21 12:58:13,892 [myid:] - INFO [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1032] - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2016-11-21 12:58:13,990 [myid:] - INFO [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@876] - Socket connection established to 127.0.0.1/127.0.0.1:2182, initiating session
[zk: 127.0.0.1:2182(CONNECTING) 0] 2016-11-21 12:58:14,095 [myid:] - INFO [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1299] - Session establishment complete on server 127.0.0.1/127.0.0.1:2182, sessionid = 0x158853f0cfd0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null