Mac OS X(Lion)にHomebrewでZooKeeperを構築する

要件

  • ZooKeeperをインストールする

環境

  • Mac Book Air(Lion)

新規インストール手順

zookeeperをインストールする

$ brew install zookeeper
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/zookeeper-3.4.6
####################################################################### 100.0%
==> Pouring zookeeper-3.4.6.lion.bottle.tar.gz
==> Caveats
To have launchd start zookeeper at login:
    ln -sfv /usr/local/opt/zookeeper/*.plist ~/Library/LaunchAgents
Then to load zookeeper now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.zookeeper.plist
Or, if you don't want/need launchctl, you can just run:
    zkServer start
==> Summary
/usr/local/Cellar/zookeeper/3.4.6: 194 files, 13M

Serverを起動する

$ zkServer start
JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Starting zookeeper ... STARTED

Clientから接続する

$ zkCli
Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is enabled
[zk: localhost:2181(CONNECTING) 0]
WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: localhost:2181(CONNECTED) 0]

コマンドを実行してみる

[zk: localhost:2181(CONNECTED) 0] ls
[zk: localhost:2181(CONNECTED) 1] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 2] create /roots "hello"
Created /roots
[zk: localhost:2181(CONNECTED) 3] get /roots
"hello"
cZxid = 0x2
ctime = Tue Jul 01 23:19:20 JST 2014
mZxid = 0x2
mtime = Tue Jul 01 23:19:20 JST 2014
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
[zk: localhost:2181(CONNECTED) 4]

詳細は右記サイトからどうぞ。ZooKeeper スタートガイド