Zookeeper 單機(jī)環(huán)境和集群環(huán)境搭建
一、單機(jī)環(huán)境搭建#
1.1 下載#
下載對(duì)應(yīng)版本 Zookeeper,這里我下載的版本 3.4.14。官方下載地址:https://archive.apache.org/dist/zookeeper/
# wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
1.2 解壓#
# tar -zxvf zookeeper-3.4.14.tar.gz
1.3 配置環(huán)境變量#
# vim /etc/profile
添加環(huán)境變量:
export ZOOKEEPER_HOME=/usr/app/zookeeper-3.4.14 export PATH=$ZOOKEEPER_HOME/bin:$PATH
使得配置的環(huán)境變量生效:
# source /etc/profile
1.4 修改配置#
進(jìn)入安裝目錄的 conf/ 目錄下,拷貝配置樣本并進(jìn)行修改:
# cp zoo_sample.cfg zoo.cfg
指定數(shù)據(jù)存儲(chǔ)目錄和日志文件目錄(目錄不用預(yù)先創(chuàng)建,程序會(huì)自動(dòng)創(chuàng)建),修改后完整配置如下:
# 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/zookeeper/data dataLogDir=/usr/local/zookeeper/log # 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
配置參數(shù)說(shuō)明:
•tickTime:用于計(jì)算的基礎(chǔ)時(shí)間單元。比如 session 超時(shí):N*tickTime;
•initLimit:用于集群,允許從節(jié)點(diǎn)連接并同步到 master 節(jié)點(diǎn)的初始化連接時(shí)間,以 tickTime 的倍數(shù)來(lái)表示;
•syncLimit:用于集群, master 主節(jié)點(diǎn)與從節(jié)點(diǎn)之間發(fā)送消息,請(qǐng)求和應(yīng)答時(shí)間長(zhǎng)度(心跳機(jī)制);
•dataDir:數(shù)據(jù)存儲(chǔ)位置;
•dataLogDir:日志目錄;
•clientPort:用于客戶端連接的端口,默認(rèn) 2181
1.5 啟動(dòng)#
由于已經(jīng)配置過(guò)環(huán)境變量,直接使用下面命令啟動(dòng)即可:
zkServer.sh start
1.6 驗(yàn)證#
使用 JPS 驗(yàn)證進(jìn)程是否已經(jīng)啟動(dòng),出現(xiàn) QuorumPeerMain 則代表啟動(dòng)成功。
[root@hadoop001 bin]# jps 3814 QuorumPeerMain
二、集群環(huán)境搭建#
為保證集群高可用,Zookeeper 集群的節(jié)點(diǎn)數(shù)最好是奇數(shù),最少有三個(gè)節(jié)點(diǎn),所以這里演示搭建一個(gè)三個(gè)節(jié)點(diǎn)的集群。這里我使用三臺(tái)主機(jī)進(jìn)行搭建,主機(jī)名分別為 hadoop001,hadoop002,hadoop003。
2.1 修改配置#
解壓一份 zookeeper 安裝包,修改其配置文件 zoo.cfg,內(nèi)容如下。之后使用 scp 命令將安裝包分發(fā)到三臺(tái)服務(wù)器上:
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/usr/local/zookeeper-cluster/data/ dataLogDir=/usr/local/zookeeper-cluster/log/ clientPort=2181 # server.1 這個(gè)1是服務(wù)器的標(biāo)識(shí),可以是任意有效數(shù)字,標(biāo)識(shí)這是第幾個(gè)服務(wù)器節(jié)點(diǎn),這個(gè)標(biāo)識(shí)要寫(xiě)到dataDir目錄下面myid文件里 # 指名集群間通訊端口和選舉端口 server.1=hadoop001:2287:3387 server.2=hadoop002:2287:3387 server.3=hadoop003:2287:3387
2.2 標(biāo)識(shí)節(jié)點(diǎn)#
分別在三臺(tái)主機(jī)的 dataDir 目錄下新建 myid 文件,并寫(xiě)入對(duì)應(yīng)的節(jié)點(diǎn)標(biāo)識(shí)。Zookeeper 集群通過(guò) myid 文件識(shí)別集群節(jié)點(diǎn),并通過(guò)上文配置的節(jié)點(diǎn)通信端口和選舉端口來(lái)進(jìn)行節(jié)點(diǎn)通信,選舉出 Leader 節(jié)點(diǎn)。
創(chuàng)建存儲(chǔ)目錄:
# 三臺(tái)主機(jī)均執(zhí)行該命令 mkdir -vp /usr/local/zookeeper-cluster/data/
創(chuàng)建并寫(xiě)入節(jié)點(diǎn)標(biāo)識(shí)到 myid 文件:
# hadoop001主機(jī) echo "1" > /usr/local/zookeeper-cluster/data/myid # hadoop002主機(jī) echo "2" > /usr/local/zookeeper-cluster/data/myid # hadoop003主機(jī) echo "3" > /usr/local/zookeeper-cluster/data/myid
2.3 啟動(dòng)集群#
分別在三臺(tái)主機(jī)上,執(zhí)行如下命令啟動(dòng)服務(wù):
/usr/app/zookeeper-cluster/zookeeper/bin/zkServer.sh start
2.4 集群驗(yàn)證#
啟動(dòng)后使用 zkServer.sh status 查看集群各個(gè)節(jié)點(diǎn)狀態(tài)。如圖所示:三個(gè)節(jié)點(diǎn)進(jìn)程均啟動(dòng)成功,并且 hadoop002 為 leader 節(jié)點(diǎn),hadoop001 和 hadoop003 為 follower 節(jié)點(diǎn)。
更多大數(shù)據(jù)系列文章可以參見(jiàn) GitHub 開(kāi)源項(xiàng)目:大數(shù)據(jù)入門(mén)指南
總結(jié)
以上所述是小編給大家介紹的Zookeeper 單機(jī)環(huán)境和集群環(huán)境搭建,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
Windows遠(yuǎn)程數(shù)據(jù)、文件同步工具cwRsync配置方法
這篇文章主要介紹了Windows遠(yuǎn)程數(shù)據(jù)、文件同步工具cwRsync配置方法,需要的朋友可以參考下2015-10-10URL Rewrite Module 2.1 URL重寫(xiě)模塊規(guī)則寫(xiě)法
URL重寫(xiě)模塊是IIS的擴(kuò)展,可作為獨(dú)立IIS Server的下載下載,并且還預(yù)先安裝在Windows Azure網(wǎng)站(WAWS)上的任何網(wǎng)站上,供您使用,本教程將指導(dǎo)您完成如何為URL重寫(xiě)模塊創(chuàng)建和測(cè)試一組重寫(xiě)規(guī)則2020-12-12Web服務(wù)器和應(yīng)用服務(wù)器之間的區(qū)別詳解
這篇文章主要介紹了Web服務(wù)器和應(yīng)用服務(wù)器之間的區(qū)別詳解,應(yīng)用服務(wù)器是為客戶端提供對(duì)業(yè)務(wù)邏輯的訪問(wèn)這種服務(wù)器,根據(jù)客戶端的請(qǐng)求會(huì)將數(shù)據(jù)轉(zhuǎn)化為動(dòng)態(tài)內(nèi)容,一般還需要數(shù)據(jù)庫(kù)的支持,應(yīng)用服務(wù)器的搭建很多時(shí)候依賴于應(yīng)用程序的開(kāi)發(fā)語(yǔ)言,需要的朋友可以參考下2023-07-07git簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了git簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理,Git是目前世界上最先進(jìn)的分布式版本控制系統(tǒng),有興趣的可以了解一下2017-08-08DELL服務(wù)器RAID H700,PERC H800陣列卡配置中文完全手冊(cè)圖解
這篇文章主要介紹了DELL服務(wù)器RAID H700,PERC H800陣列卡配置中文完全手冊(cè)圖解,供參考。疏漏之處敬請(qǐng)反饋2016-04-04ubuntu20.04部署ntp服務(wù)器ntpd(ntpdate?)的詳細(xì)過(guò)程
這篇文章主要介紹了ubuntu20.04部署ntp服務(wù)器ntpd(ntpdate?)的詳細(xì)過(guò)程,本文分步驟給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09