- 論壇徽章:
- 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的正式子項目,它是一個針對大型分布式系統(tǒng)的可靠協(xié)調(diào)系統(tǒng),提供的功能包括:配置維護、名字服務、分布式同步、組服務等。ZooKeeper的目標就是封裝好復雜易出錯的關鍵服務,將簡單易用的接口和性能高效、功能穩(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一個開源的實現(xiàn).是高有效和可靠的協(xié)同工作系統(tǒng).Zookeeper能夠用來leader選舉,配置信息維護等.在一個分布式的環(huán)境中,我們需要一個Master實例或存儲一些配置信息,確保文件寫入的一致性等.</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正常運行.</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é)點間通信超時的單位時長,單位是毫秒,initLimit是指follower服務器初始化連接到leader服務器時可以忍受的超時時間,時長以initLimit*tickTime表示,syncLimit指leader與follower之間通信的超時時長,以</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é)點編號,"hadoop1"表示這臺服務器的主機名,也可以直接指定ip地址,"2888"是ZooKeeper服務間通信的端口,"3888"是ZooKeeper服務與其他服務通信的端口</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>在其中新建一個空白文件,名為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兩個目錄復制到所有服務器節(jié)點</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.啟動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>在所有機器上分別啟懂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>在啟動過程中,被選舉為leader的服務器,會因為其他服務器連不上而報錯,所有服務器都啟動以后,報錯就會消失</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.查看服務器狀態(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>輸出最后一行會指出當前服務器所在集群的角色,不是follower就是leader,否則說明服務有問題</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.停止服務器</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,算法的詳細過程見:</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> |
|