Zookeeper-3.4.13 win10 配置
ZooKeeper 是什么?
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。
ZooKeeper包含一个简单的原语集,提供Java和C的接口。
ZooKeeper代码版本中,提供了分布式独享锁、选举、队列的接口,代码在zookeeper-3.4.8\src\recipes。其中分布锁和队列有Java和C两个版本,选举只有Java版本。
ZooKeeper 下载地址
link
解压到E:\zookeeper-3.4.13\zookeeper-3.4.13
修改配置文件
复制zoo_sample.cfg 文件名(E:\zookeeper-3.4.13\zookeeper-3.4.13\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=E:\\zookeeper\\data
dataLogDir=E:\\zookeeper\\log
# 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
配置文件简单解析
1、tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
2、dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
3、dataLogDir:顾名思义就是 Zookeeper 保存日志文件的目录
4、clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
打开powershell 查看一下zookeeper的整体目录
PS E:\> cd .\zookeeper-3.4.13\
PS E:\zookeeper-3.4.13> ls
目录: E:\zookeeper-3.4.13
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2018/11/22 7:14 zookeeper-3.4.13
PS E:\zookeeper-3.4.13> cd .\zookeeper-3.4.13\
PS E:\zookeeper-3.4.13\zookeeper-3.4.13> ls
目录: E:\zookeeper-3.4.13\zookeeper-3.4.13
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2018/11/22 7:14 bin
d----- 2018/11/22 7:20 conf
d----- 2018/11/22 7:14 contrib
d----- 2018/11/22 7:14 dist-maven
d----- 2018/11/22 7:14 docs
d----- 2018/11/22 7:14 lib
d----- 2018/11/22 7:14 recipes
d----- 2018/11/22 7:14 src
-a---- 2018/6/30 1:04 91400 build.xml
-a---- 2018/6/30 1:04 8502 ivy.xml
-a---- 2018/6/30 1:04 1709 ivysettings.xml
-a---- 2018/6/30 1:04 11938 LICENSE.txt
-a---- 2018/6/30 1:04 3132 NOTICE.txt
-a---- 2018/6/30 1:04 1585 README.md
-a---- 2018/6/30 1:04 1770 README_packaging.txt
-a---- 2018/6/30 1:05 1508639 zookeeper-3.4.13.jar
-a---- 2018/7/1 7:36 833 zookeeper-3.4.13.jar.asc
-a---- 2018/6/30 1:05 33 zookeeper-3.4.13.jar.md5
-a---- 2018/6/30 1:05 41 zookeeper-3.4.13.jar.sha1
简单介绍连个目录:
bin:可执行脚本
conf:配置文件(刚才已经在conf做了一个简单的配置)
如何启动zookeeper呢?
执行脚本需要进入bin
PS E:\zookeeper-3.4.13\zookeeper-3.4.13> cd bin
PS E:\zookeeper-3.4.13\zookeeper-3.4.13\bin> ls
目录: E:\zookeeper-3.4.13\zookeeper-3.4.13\bin
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2018/6/30 1:04 232 README.txt
-a---- 2018/6/30 1:04 1937 zkCleanup.sh
-a---- 2018/6/30 1:04 1056 zkCli.cmd
-a---- 2018/6/30 1:04 1534 zkCli.sh
-a---- 2018/6/30 1:04 1759 zkEnv.cmd
-a---- 2018/6/30 1:04 2696 zkEnv.sh
-a---- 2018/6/30 1:04 1089 zkServer.cmd
-a---- 2018/6/30 1:04 6773 zkServer.sh
-a---- 2018/6/30 1:04 996 zkTxnLogToolkit.cmd
-a---- 2018/6/30 1:04 1385 zkTxnLogToolkit.sh
可以看到在bin的下面既有sh,又有cmd,说明zookeeper支持linux和win两类系统
启动一下试试:
PS E:\zookeeper-3.4.13\zookeeper-3.4.13\bin> .\zkServer.cmd
使用zkCli.cmd 客户端连接zookeeper报错
PS E:\zookeeper-3.4.13\zookeeper-3.4.13\bin> .\zkCli.cmd 127.0.0.0.1:2181
server error
2018-11-22 07:31:21,668 [myid:] - INFO [main:[email protected]] - binding to port 0.0.0.0/0.0.0.0:2181
2018-11-22 07:34:55,487 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - Accepted socket connection from /127.0.0.1:54509
2018-11-22 07:34:55,533 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - Client attempting to establish new session at /127.0.0.1:54509
2018-11-22 07:34:55,535 [myid:] - INFO [SyncThread:0:[email protected]] - Creating new log file: log.1
2018-11-22 07:34:55,629 [myid:] - INFO [SyncThread:0:[email protected]] - Established session 0x100020bd4340000 with negotiated timeout 30000 for client /127.0.0.1:54509
2018-11-22 07:34:55,643 [myid:] - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - Exception causing close of session 0x100020bd4340000: 远程主机强迫关闭了一个现有的连接。
2018-11-22 07:34:55,644 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - Closed socket connection for client /127.0.0.1:54509 which had sessionid 0x100020bd4340000
2018-11-22 07:35:26,053 [myid:] - INFO [SessionTracker:[email protected]] - Expiring session 0x100020bd4340000, timeout of 30000ms exceeded
2018-11-22 07:35:26,055 [myid:] - INFO [ProcessThread(sid:0 cport:2181)::[email protected]] - Processed session termination for sessionid: 0x100020bd4340000
解决办法:
1、换低版本
2、此版本没有找到很好的解决方案。。。待续
另一种方法:
PS E:\zookeeper-3.4.13\zookeeper-3.4.13\bin> jps -l -v
17828 sun.tools.jps.Jps -Dapplication.home=C:\Program Files\Java\jdk1.8.0_161 -Xms8m
25004 org.apache.zookeeper.server.quorum.QuorumPeerMain -Dzookeeper.log.dir=E:\zookeeper-3.4.13\zookeeper-3.4.13\bin\.. -Dzookeeper.root.logger=INFO,CONSOLE
可以看到QuorumPeerMain的进程
上一篇: 算法数据结构(十五)----暴力递归
下一篇: 结构化数据、半结构化数据和非结构化数据