安装
zookeeper支持brew安装。
查看zookeeper 信息
$ brew info zookeeper
安装zookeeper
$ brew install zookeeper
安装后,在/usr/local/etc/zookeeper/
目录下,已经有了缺省的配置文件
。
$ ls /usr/local/etc/zookeeper
defaults log4j.properties zoo.cfg zoo_sample.cfg
打开配置文件
$ less -N /usr/local/etc/zookeeper/zoo.cfg
1 # The number of milliseconds of each tick
2 tickTime=2000
3 # The number of ticks that the initial
4 # synchronization phase can take
5 initLimit=10
6 # The number of ticks that can pass between
7 # sending a request and getting an acknowledgement
8 syncLimit=5
9 # the directory where the snapshot is stored.
10 # do not use /tmp for storage, /tmp here is just
11 # example sakes.
12 dataDir=/usr/local/var/run/zookeeper/data
13 # the port at which the clients will connect
14 clientPort=2181
15 # the maximum number of client connections.
16 # increase this if you need to handle more clients
17 #maxClientCnxns=60
18 #
19 # Be sure to read the maintenance section of the
20 # administrator guide before turning on autopurge.
21 #
22 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
23 #
24 # The number of snapshots to retain in dataDir
25 #autopurge.snapRetainCount=3
26 # Purge task interval in hours
27 # Set to "0" to disable auto purge feature
28 #autopurge.purgeInterval=1
主要配置
2 tickTime=2000
5 initLimit=10
8 syncLimit=5
12 dataDir=/usr/local/var/run/zookeeper/data
14 clientPort=2181
启动zookeeper
$ which zkServer
/usr/local/bin/zkServer
$ cd /usr/local/bin
$ ls | grep zk
zkCleanup
zkCli
zkServer
$ zkServer start
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Starting zookeeper ... STARTED
连接ZooKeeper服务器
ZooKeeper命令行界面(CLI)用于与ZooKeeper集合进行交互以进行开发。它有助于调试和解决不同的选项。使用如下命令:
$ zkCli
Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is enabled
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
一旦客户端启动,就可以使用命令与zookeeper服务器进行交互了。
最后使用 Ctrl + c
即可退出zkCli。
停止zookeeper服务器
$ zkServer stop
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Stopping zookeeper ... STOPPED
来源:CSDN
作者:zhangbinHn
链接:https://blog.csdn.net/zhangbinHn/article/details/103958185