- 論壇徽章:
- 0
|
<span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: 20px; ">ZooKeeper是Hadoop的正式子項(xiàng)目,它是一個(gè)針對(duì)大型分布式系統(tǒng)的可靠協(xié)調(diào)系統(tǒng),提供的功能包括:配置維護(hù)、名字服務(wù)、分布式同步、組服務(wù)等。ZooKeeper的目標(biāo)就是封裝好復(fù)雜易出錯(cuò)的關(guān)鍵服務(wù),將簡(jiǎn)單易用的接口和性能高效、功能穩(wěn)定的系統(tǒng)提供給用戶。</span><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: 20px; ">Zookeeper是Google的Chubby一個(gè)開源的實(shí)現(xiàn).是高有效和可靠的協(xié)同工作系統(tǒng).Zookeeper能夠用來(lái)leader選舉,配置信息維護(hù)等.在一個(gè)分布式的環(huán)境中,我們需要一個(gè)Master實(shí)例或存儲(chǔ)一些配置信息,確保文件寫入的一致性等.</span></div><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: 20px; ">ZooKeeper目前是安裝HBase 0.90.2的必要前提,所以在安裝HBase之前,先要確保ZooKeeper正常運(yùn)行.</span></div><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: 20px; "><br></span></div><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: 20px; ">1.下載安裝包</span></div><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: 20px; ">2.將安裝包解壓到hadoop同一子目錄,如/home/grid/zookeeper-3.3.3,編輯conf/zoo.cfg文件:</span></div><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: 20px; "><div id="codeText" class="codeText"><ol style="margin:0 1px 0 0;padding:5px 0;" start="1" class="dp-css"><li>The number of milliseconds of each tick</li><li>
</li><li>
tickTime=2000</li><li>
</li><li>
# The number of ticks that the initial</li><li>
</li><li>
# synchronization phase can take</li><li>
</li><li>
initLimit=10</li><li>
</li><li>
# The number of ticks that can pass between</li><li>
</li><li>
# sending a request and getting an acknowledgement</li><li>
</li><li>
syncLimit=5</li><li>
</li><li>
# the directory where the snapshot is stored.</li><li>
</li><li>
dataDir=/home/grid/zookeeper</li><li>#dataLogDir=/hadoop/zookeeper/logs</li><li>
# the port at which the clients will connect</li><li>
</li><li>
clientPort=3355</li><li>
</li><li>
# 2888,3888 are election port</li><li>
</li><li>
server.1=hadoop1:2888:3888</li><li>
server.2=hadoop2:2888:3888</li><li>
server.3=hadoop3:2888:3888</li><li>
server.4=hadoop4:2888:3888</li></ol></div></span></div><div><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Verdana, Simsun, sans-serif; font-size: 13px; line-height: 20px; "><span class="Apple-tab-span" style="white-space:pre"> </span>其中tickTime表示節(jié)點(diǎn)間通信超時(shí)的單位時(shí)長(zhǎng),單位是毫秒,initLimit是指follower服務(wù)器初始化連接到leader服務(wù)器時(shí)可以忍受的超時(shí)時(shí)間,時(shí)長(zhǎng)以initLimit*tickTime表示,syncLimit指leader與follower之間通信的超時(shí)時(shí)長(zhǎng),以</span><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">syncLimit*tickTime表示,這里是5*2000=10秒</span></div><div><font class="Apple-style-span" color="#333333" face="Verdana, Simsun, sans-serif" size="2"><span class="Apple-style-span" style="line-height: 20px;"><span class="Apple-tab-span" style="white-space:pre"> </span>"</span></font><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">server.1=hadoop1:2888:3888"這一句中的server.1表示節(jié)點(diǎn)編號(hào),"hadoop1"表示這臺(tái)服務(wù)器的主機(jī)名,也可以直接指定ip地址,"2888"是ZooKeeper服務(wù)間通信的端口,"3888"是ZooKeeper服務(wù)與其他服務(wù)通信的端口</span></div><div><font class="Apple-style-span" color="#5c5c5c" face="Consolas, monospace"><span class="Apple-style-span" style="font-size: 12px; line-height: 15px;"><span class="Apple-tab-span" style="white-space:pre"> </span>dataDir指定ZooKeeper的數(shù)據(jù)目錄</span></font></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; "><br></span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">2.建立</span><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">/home/grid/zookeeper目錄</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; "><span class="Apple-tab-span" style="white-space:pre"> </span>在其中新建一個(gè)空白文件,名為myid</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">3.把/home/grid/zookeeper-3.3.3和/home/grid/zookeeper兩個(gè)目錄復(fù)制到所有服務(wù)器節(jié)點(diǎn)</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">4.修改</span><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">/home/grid/zookeeper/myid,比如:hadoop1上,修改myid內(nèi)容為1,hadoop2上,修改為2</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">5.啟動(dòng)ZooKeeper</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; "><span class="Apple-tab-span" style="white-space:pre"> </span>在所有機(jī)器上分別啟懂ZooKeeper:</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; "><span class="Apple-tab-span" style="white-space:pre"> </span>/home/grid/zookeeper-3.3.3/bin/zkServer.sh start</span></div><div><font class="Apple-style-span" color="#5c5c5c" face="Consolas, monospace"><span class="Apple-style-span" style="font-size: 12px; line-height: 15px;"><span class="Apple-tab-span" style="white-space:pre"> </span>在啟動(dòng)過程中,被選舉為leader的服務(wù)器,會(huì)因?yàn)槠渌⻊?wù)器連不上而報(bào)錯(cuò),所有服務(wù)器都啟動(dòng)以后,報(bào)錯(cuò)就會(huì)消失</span></font></div><div><font class="Apple-style-span" color="#5c5c5c" face="Consolas, monospace"><span class="Apple-style-span" style="font-size: 12px; line-height: 15px;">6.查看服務(wù)器狀態(tài)</span></font></div><div><font class="Apple-style-span" color="#5c5c5c" face="Consolas, monospace"><span class="Apple-style-span" style="font-size: 12px; line-height: 15px;"><span class="Apple-tab-span" style="white-space:pre"> </span></span></font><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">/home/grid/zookeeper-3.3.3/bin/zkServer.sh status</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; "><span class="Apple-tab-span" style="white-space:pre"> </span>輸出最后一行會(huì)指出當(dāng)前服務(wù)器所在集群的角色,不是follower就是leader,否則說明服務(wù)有問題</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">7.停止服務(wù)器</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; "><span class="Apple-tab-span" style="white-space:pre"> </span></span><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; ">/home/grid/zookeeper-3.3.3/bin/zkServer.sh stop</span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; "><br></span></div><div><span class="Apple-style-span" style="color: rgb(92, 92, 92); font-family: Consolas, monospace; font-size: 12px; line-height: 15px; "><br></span></div><div><font class="Apple-style-span" color="#5c5c5c" face="Consolas, monospace"><span class="Apple-style-span" style="font-size: 12px; line-height: 15px;">ZooKeeper的選舉算法使用的是Paxos,算法的詳細(xì)過程見:</span></font></div><div><font class="Apple-style-span" color="#5c5c5c" face="Consolas, monospace"><span class="Apple-style-span" style="font-size: 12px; line-height: 15px;"><a href="http://hi.baidu.com/jrckkyy/blog/item/326a2c51d1ce182c43a75b0d.html" target="_blank" target="_blank">http://hi.baidu.com/jrckkyy/blog/item/326a2c51d1ce182c43a75b0d.html</a></span></font></div> |
|