ZooKeeper安装及配置 for Mac

  1. 安装
  • 查看brew info zookeeper
1
2
3
4
$ brew info zookeeper
zookeeper: stable 3.4.12 (bottled), HEAD
Centralized server for distributed coordination of services
https://zookeeper.apache.org/
  • 安装brew install zookeeper
1
2
3
4
5
6
7
8
9
 $ brew install zookeeper
==> Downloading https://homebrew.bintray.com/bottles/zookeeper-3.4.12.high_sierr
###### ################################################################## 100.0%
==> Pouring zookeeper-3.4.12.high_sierra.bottle.tar.gz
==> Caveats
To have launchd start zookeeper now and restart at login:
brew services start zookeeper
Or, if you don't want/need a background service you can just run:
zkServer start
  1. 安装后,在/usr/local/etc/zookeeper/ 中可查看配置
1
$ ls /usr/local/etc/zookeeper/
  • 安装后,在/usr/local/etc/zookeeper/ 已经有了缺省配置

    1
    $ ls /usr/local/etc/zookeeper/
    • 查看配置文件

      1
      $ less -N /usr/local/etc/zookeeper/zoo.cfg
    • 配置文件如下

      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
      # 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=/usr/local/var/run/zookeeper/data
      # 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. 启动服务
  • 执行命令zkServer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ zkServer
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}

$ zkServer status
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Error contacting service. It is probably not running.

$ zkServer start
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Starting zookeeper ... STARTED
  • 查看zookeeper运行及状态

安装后,可以看到zookeeper提供了zkCli等工具进行.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ zkServer status
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Error contacting service. It is probably not running.
192:~ maerfeifei$ zkServer start
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Starting zookeeper ... STARTED
192:~ maerfeifei$ 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]