zookeeper是構建分佈式系統的重要組件,今天嘗試了使用homebrew在mac上安裝zookeeper,本文是安裝過程的完整記錄.php
使用命令$ brew info zookeeper
查看可用版本信息:css
zookeeper: stable 3.4.8, HEAD Centralized server for distributed coordination of services https://zookeeper.apache.org/ Not installed From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zookeeper.rb ==> Options --with-perl Build Perl bindings --with-python Build with python support --HEAD Install HEAD version ==> 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
可見homebrew提供的最新穩定版是3.4.8,zookeeper官網上最新的穩定版是3.4.11.html
使用命令$ brew install zookeeper
安裝:python
Error: The following formula: zookeeper cannot be installed as a binary package and must be built from source. To continue, you must install Xcode from the App Store, or the CLT by running: xcode-select --install
結果報錯了,提示先安裝xcode-select,使用命令$ xcode-select --install
安裝,輸出git
xcode-select: note: install requested for command line developer tools
安裝好之後再次執行$ brew install zookeeper
:github
Warning: You are using OS X 10.13. We do not provide support for this pre-release version. You may encounter build failures or other breakages. Please create pull-requests instead of filing issues. ==> Downloading https://www.apache.org/dyn/closer.cgi?path=zookeeper/zookeeper-3 ==> Best Mirror http://mirrors.shu.edu.cn/apache/zookeeper/zookeeper-3.4.8/zooke curl: (22) The requested URL returned error: 404 Not Found Trying a mirror... ==> Downloading https://archive.apache.org/dist/zookeeper/zookeeper-3.4.8/zookee ######################################################################## 100.0% ==> ./configure --prefix=/usr/local/Cellar/zookeeper/3.4.8 --without-cppunit ==> make install ==> 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 ==> Summary 🍺 /usr/local/Cellar/zookeeper/3.4.8: 237 files, 17.6M, built in 52 seconds
此時使用$ ls /usr/local/etc
再次查看配置文件目錄:redis
bash_completion.d mongod.conf redis-sentinel.conf zookeeper dump.rdb openssl redis.conf
發現多了zookeeper,執行$ cd /usr/local/etc/zookeeper
進入zookeeper,執行$ ls
查看:apache
defaults log4j.properties zoo.cfg zoo_sample.cfg
發現有zoo.cfg和zoo_sample.cfg這2個配置文件.使用$ cat zoo.cfg
查看zoo.cfg的內容:xcode
# 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
使用命令$ zkServer
,結果啓動失敗:ruby
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 start
:
ZooKeeper JMX enabled by default Using config: /usr/local/etc/zookeeper/zoo.cfg Starting zookeeper ... STARTED
可見啓動成功,而且使用了/usr/local/etc/zookeeper/
下的配置文件zoo.cfg
執行命令$ 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
就像在這裏卡住了同樣,隨便輸入ls
,而後終端變成了
ls [zk: localhost:2181(CONNECTED) 1] ls [zk: localhost:2181(CONNECTED) 2] ls / [zookeeper] [zk: localhost:2181(CONNECTED) 3] ls /zookeeper [quota] [zk: localhost:2181(CONNECTED) 4]
其實這是JLine交互控制檯,會開啓一個和zookeeper服務器之間的session.另外,關於jline參考http://ningg.top/zookeeper-getting-started/.能夠經過執行quit命令,即[zk: localhost:2181(CONNECTED) 4] quit
退出交互控制檯.
執行$ zkServer status
:
ZooKeeper JMX enabled by default Using config: /usr/local/etc/zookeeper/zoo.cfg Mode: standalone
這裏的standalone指的是單機模式
執行$ zkServer stop
:
ZooKeeper JMX enabled by default Using config: /usr/local/etc/zookeeper/zoo.cfg Stopping zookeeper ... STOPPED