zookeeper 也是apache的頂級(jí)項(xiàng)目囊颅,所以他的項(xiàng)目官網(wǎng):http://zookeeper.apache.org/
zookeeper是什么
以下是官網(wǎng)的解釋
Apache ZooKeeper is an effort to develop and maintain an open-source server which enables highly reliable distributed coordination.
ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.
以下是百度百科的說(shuō)明
ZooKeeper是一個(gè)分布式的卫袒,開(kāi)放源碼的分布式應(yīng)用程序協(xié)調(diào)服務(wù)漠其。是Google的Chubby一個(gè)開(kāi)源的實(shí)現(xiàn)帐萎,是Hadoop和Hbase的重要組件。它是一個(gè)為分布式應(yīng)用提供一致性服務(wù)的軟件,提供的功能包括:配置維護(hù)、域名服務(wù)颤诀、分布式同步、組服務(wù)等对湃。它是集群的管理者崖叫,監(jiān)視著集群中各個(gè)節(jié)點(diǎn)的狀態(tài)根據(jù)節(jié)點(diǎn)提交的反饋進(jìn)行下一步合理操作。最終拍柒,將簡(jiǎn)單易用的接口和性能高效心傀、功能穩(wěn)定的系統(tǒng)提供給用戶(hù)
剛接觸zookeeper,那么先總安裝開(kāi)始說(shuō)起吧
下載
https://www.apache.org/dyn/closer.cgi/zookeeper/
從這里選擇一個(gè)鏡像下載
我選的這個(gè)
是Zookeeper-3.4.12
安裝
將剛才下載zookeeper-3.4.12.tar.gz 解壓
tar -zxvf zookeeper-3.4.12.tar.gz
移動(dòng)
mv zookeeper-3.4.12 /usr/local/zookeeper
這個(gè)時(shí)候拆讯,可以打開(kāi)/usr/local/zookeeper/docs/index.html
或者進(jìn)入這里http://zookeeper.apache.org/doc/current/index.html脂男,
在頁(yè)面上點(diǎn)擊“Getting Started”,就進(jìn)入http://zookeeper.apache.org/doc/current/zookeeperStarted.html
這個(gè)頁(yè)面和剛才docs里的文件內(nèi)容一致
新建data目錄
mkdir -p /var/lib/zookeeper/data
這個(gè)路徑會(huì)寫(xiě)入到zoo.cfg文件中
準(zhǔn)備配置文件
cd /usr/local/zookeeper/conf
mv zoo_sample.cfg zoo.cfg
vi zoo.cfg
編輯zoo.cfg种呐,GettingStarted中也有相關(guān)內(nèi)容,主要修改以下內(nèi)容
tickTime=2000
dataDir=/var/lib/zookeeper/data
clientPort=2181
還有一個(gè)dataLogDir參數(shù)宰翅,如果不設(shè)置,日志默認(rèn)使用dataDir的目錄
啟動(dòng)zookeeper
cd /usr/local/zookeeper
bin/zkServer.sh start
連接到zookeeper
bin/zkCli.sh -server 127.0.0.1:2181
如果連接成功:
Connecting to localhost:2181
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
Welcome to ZooKeeper!
JLine support is enabled
[zkshell: 0]
輸入一個(gè)命令爽室,試試
[zkshell: 0] help
ZooKeeper host:port cmd args
get path [watch]
ls path [watch]
set path data [version]
delquota [-n|-b] path
quit
printwatches on|off
createpath data acl
stat path [watch]
listquota path
history
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
setquota -n|-b val path
后面的驗(yàn)證汁讼,按照官網(wǎng)文檔,增加一個(gè)znode阔墩,set一個(gè)數(shù)據(jù)嘿架,再get一個(gè)數(shù)據(jù)
停止zookeeper
剛才進(jìn)入到zookeeper 的shell中,輸入命令:quit 就退出啸箫。
bing/zkServer.sh stop