Mac安装Apache Zookeeper-3.4.12

Mac安装Apache Zookeeper-3.4.12教程

安装

安装方式1-brew安装

1
$ brew install zookeeper

安装方式2-下载压缩包

从此地址下载http://mirrors.hust.edu.cn/apache/zookeeper/stable/

解压配置文件

1
2
3
4
$ tar -zxvf zookeeper-3.4.12.tar.gz // 解压
$ cd zookeeper-3.4.12/conf // 切换到配置目录下
$ mv zoo_sample.cfg zoo.cfg // 更改默认配置文件名称
$ vi zoo.cfg // 编辑配置文件,自定义dataDir

启动

启动sever端

切换到bin目录

1
2
3
4
5
6
7
8
9
10
11
$ pwd
/user/local/Celler/zookeeper/3.4.12/bin

$ ls
README.txt zkCli.cmd zkEnv.cmd zkServer.cmd zookeeper.out
zkCleanup.sh zkCli.sh zkEnv.sh zkServer.sh

$ ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /user/local/Celler/zookeeper/3.4.12/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

启动client端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
./zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2019-10-20 12:17:25,861 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.12-e5259e437540f349646870ea94dc2658c4e44b3b, built on 03/27/2018 03:55 GMT
2019-10-20 12:17:25,864 [myid:] - INFO [main:Environment@100] - Client environment:host.name=localhost
2019-10-20 12:17:25,864 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_191
2019-10-20 12:17:25,866 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2019-10-20 12:17:25,866 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre
2019-10-20 12:17:25,868 [myid:] - INFO [main:ZooKeeper@441] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@799f7e29
Welcome to ZooKeeper!
2019-10-20 12:17:25,896 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1028] - 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
2019-10-20 12:17:25,959 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@878] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
2019-10-20 12:17:25,966 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1302] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x10000112e160008, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0] ls /
[zookeeper, hbase]

停止server端

1
2
3
4
> ./zkServer.sh stop //停止后,如果CLi没有关闭,将报错
ZooKeeper JMX enabled by default
Using config: zookeeper-3.4.12/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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.
# 内存数据快照的保存目录;如果没有自定义Log也使用该目录
dataDir=/tmp/zookeeper
# the port at which the clients will connect
# zookeeper服务端的端口,客户端启动时需要连接的端口
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