1.官网下载zookeeper
https://archive.apache.org/dist/zookeeper/
版本:zookeeper-3.4.10.tar.gz
2.上传到指定目录并解压
目录:/opt/
解压:
[root@localhost opt]# tar -zxvf zookeeper-3.4.10.tar.gz
3.目录
[root@localhost opt]# cd zookeeper-3.4.10/
[root@localhost zookeeper-3.4.10]# pwd
/opt/zookeeper-3.4.10
[root@localhost zookeeper-3.4.10]# ls -la
total 1572
drwxr-xr-x. 10 elk elk 4096 Mar 23 2017 .
drwxr-xr-x. 19 root root 4096 Jun 7 18:47 ..
drwxr-xr-x. 2 elk elk 149 Mar 23 2017 bin
-rw-rw-r--. 1 elk elk 84725 Mar 23 2017 build.xml
drwxr-xr-x. 2 elk elk 77 Mar 23 2017 conf
drwxr-xr-x. 10 elk elk 130 Mar 23 2017 contrib
drwxr-xr-x. 2 elk elk 4096 Mar 23 2017 dist-maven
drwxr-xr-x. 6 elk elk 4096 Mar 23 2017 docs
-rw-rw-r--. 1 elk elk 1709 Mar 23 2017 ivysettings.xml
-rw-rw-r--. 1 elk elk 5691 Mar 23 2017 ivy.xml
drwxr-xr-x. 4 elk elk 267 Mar 23 2017 lib
-rw-rw-r--. 1 elk elk 11938 Mar 23 2017 LICENSE.txt
-rw-rw-r--. 1 elk elk 3132 Mar 23 2017 NOTICE.txt
-rw-rw-r--. 1 elk elk 1770 Mar 23 2017 README_packaging.txt
-rw-rw-r--. 1 elk elk 1585 Mar 23 2017 README.txt
drwxr-xr-x. 5 elk elk 47 Mar 23 2017 recipes
drwxr-xr-x. 8 elk elk 211 Mar 23 2017 src
-rw-rw-r--. 1 elk elk 1456729 Mar 23 2017 zookeeper-3.4.10.jar
-rw-rw-r--. 1 elk elk 819 Mar 23 2017 zookeeper-3.4.10.jar.asc
-rw-rw-r--. 1 elk elk 33 Mar 23 2017 zookeeper-3.4.10.jar.md5
-rw-rw-r--. 1 elk elk 41 Mar 23 2017 zookeeper-3.4.10.jar.sha1
[root@localhost zookeeper-3.4.10]#
目录介绍
bin目录
zk的可执行脚本目录,包括zk服务进程,zk客户端,等脚本。其中,.sh是Linux环境下的脚本,.cmd是Windows环境下的脚本。
conf目录
配置文件目录。zoo_sample.cfg为样例配置文件,需要修改为自己的名称,一般为zoo.cfg。log4j.properties为日志配置文件。
lib
zk依赖的包。
contrib目录
一些用于操作zk的工具包。
recipes目录
zk某些用法的代码示例
4.进入conf文件夹对配置的样例zoo_sample.cfg进行复制
[root@localhost conf]# pwd
/opt/zookeeper-3.4.10/conf
[root@localhost conf]# ls -la
total 16
drwxr-xr-x. 2 elk elk 77 Mar 23 2017 .
drwxr-xr-x. 10 elk elk 4096 Mar 23 2017 ..
-rw-rw-r--. 1 elk elk 535 Mar 23 2017 configuration.xsl
-rw-rw-r--. 1 elk elk 2161 Mar 23 2017 log4j.properties
-rw-rw-r--. 1 elk elk 922 Mar 23 2017 zoo_sample.cfg
[root@localhost conf]# cp zoo_sample.cfg zoo.cfg
[root@localhost conf]# ls -la
total 20
drwxr-xr-x. 2 elk elk 92 Jun 7 18:54 .
drwxr-xr-x. 10 elk elk 4096 Mar 23 2017 ..
-rw-rw-r--. 1 elk elk 535 Mar 23 2017 configuration.xsl
-rw-rw-r--. 1 elk elk 2161 Mar 23 2017 log4j.properties
-rw-r--r--. 1 root root 922 Jun 7 18:54 zoo.cfg
-rw-rw-r--. 1 elk elk 922 Mar 23 2017 zoo_sample.cfg
[root@localhost conf]#
zoo_sample.cfg样例
[root@localhost 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.
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
样例节点说明
tickTime
时长单位为毫秒,为zk使用的基本时间度量单位。
例如,
1 * tickTime是客户端与zk服务端的心跳时间,
2 * tickTime是客户端会话的超时时间。
tickTime的默认值为2000毫秒,更低的tickTime值可以更快地发现超时问题,
但也会导致更高的网络流量(心跳消息)和更高的CPU使用率(会话的跟踪处理)。
clientPort
zk服务进程监听的TCP端口,默认情况下,服务端会监听2181端口。
dataDir
无默认配置,必须配置,用于配置存储快照文件的目录。
如果没有配置dataLogDir,那么事务日志也会存储在此目录。
5.启动:
[root@localhost bin]# pwd
/opt/zookeeper-3.4.10/bin
[root@localhost bin]# ls -la
total 40
drwxr-xr-x. 2 elk elk 149 Mar 23 2017 .
drwxr-xr-x. 10 elk elk 4096 Mar 23 2017 ..
-rwxr-xr-x. 1 elk elk 232 Mar 23 2017 README.txt
-rwxr-xr-x. 1 elk elk 1937 Mar 23 2017 zkCleanup.sh
-rwxr-xr-x. 1 elk elk 1056 Mar 23 2017 zkCli.cmd
-rwxr-xr-x. 1 elk elk 1534 Mar 23 2017 zkCli.sh
-rwxr-xr-x. 1 elk elk 1628 Mar 23 2017 zkEnv.cmd
-rwxr-xr-x. 1 elk elk 2696 Mar 23 2017 zkEnv.sh
-rwxr-xr-x. 1 elk elk 1089 Mar 23 2017 zkServer.cmd
-rwxr-xr-x. 1 elk elk 6773 Mar 23 2017 zkServer.sh
[root@localhost bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
[root@localhost bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost bin]#
上面显示started 表示启动成功
6…通过zkCli.sh命令连接服务端
[weblogic@localhost bin]$ pwd
/opt/zookeeper-3.4.10/bin
[weblogic@localhost bin]$ ./zkCl
zkCleanup.sh zkCli.cmd zkCli.sh
[weblogic@localhost bin]$ ./zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2018-06-07 19:03:11,809 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
2018-06-07 19:03:11,811 [myid:] - INFO [main:Environment@100] - Client environment:host.name=localhost
2018-06-07 19:03:11,812 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_172
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/java/jdk1.8.0_172/jre
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/zookeeper-3.4.10/bin/../build/classes:/opt/zookeeper-3.4.10/bin/../build/lib/*.jar:/opt/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/opt/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/opt/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/opt/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/opt/zookeeper-3.4.10/bin/../conf:.:/usr/local/java/jdk1.8.0_172/lib/dt.jar:/usr/local/java/jdk1.8.0_172/lib/tools.jar
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-862.3.2.el7.x86_64
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:user.name=weblogic
2018-06-07 19:03:11,817 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/weblogic
2018-06-07 19:03:11,818 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/zookeeper-3.4.10/bin
2018-06-07 19:03:11,819 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@69d0a921
2018-06-07 19:03:11,865 [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)
Welcome to ZooKeeper!
JLine support is enabled
2018-06-07 19:03:12,039 [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
2018-06-07 19:03:12,080 [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 = 0x163dd214b660000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0]