主頁 > 知識(shí)庫 > Zookeeper 單機(jī)環(huán)境和集群環(huán)境搭建

Zookeeper 單機(jī)環(huán)境和集群環(huán)境搭建

熱門標(biāo)簽:阿里云 硅谷的囚徒呼叫中心 檢查注冊表項(xiàng) 智能手機(jī) 網(wǎng)站建設(shè) 使用U盤裝系統(tǒng) 美圖手機(jī) 百度競價(jià)點(diǎn)擊價(jià)格的計(jì)算公式

 一、單機(jī)環(huán)境搭建#

1.1 下載#

下載對應(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ù)說明:

•tickTime:用于計(jì)算的基礎(chǔ)時(shí)間單元。比如 session 超時(shí):N*tickTime;
•initLimit:用于集群,允許從節(jié)點(diǎn)連接并同步到 master 節(jié)點(diǎn)的初始化連接時(shí)間,以 tickTime 的倍數(shù)來表示;
•syncLimit:用于集群, master 主節(jié)點(diǎn)與從節(jié)點(diǎn)之間發(fā)送消息,請求和應(yīng)答時(shí)間長度(心跳機(jī)制);
•dataDir:數(shù)據(jù)存儲(chǔ)位置;
•dataLogDir:日志目錄;
•clientPort:用于客戶端連接的端口,默認(rèn) 2181

1.5 啟動(dòng)#

由于已經(jīng)配置過環(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í)要寫到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 文件,并寫入對應(yīng)的節(jié)點(diǎn)標(biāo)識(shí)。Zookeeper 集群通過 myid 文件識(shí)別集群節(jié)點(diǎn),并通過上文配置的節(jié)點(diǎn)通信端口和選舉端口來進(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)建并寫入節(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ù)系列文章可以參見 GitHub 開源項(xiàng)目:大數(shù)據(jù)入門指南

總結(jié)

以上所述是小編給大家介紹的Zookeeper 單機(jī)環(huán)境和集群環(huán)境搭建,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

標(biāo)簽:湘潭 黃山 通遼 湖北 山南 煙臺(tái) 賀州 懷化

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Zookeeper 單機(jī)環(huán)境和集群環(huán)境搭建》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266