佳木斯湛栽影视文化发展公司

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

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

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

 一、單機環(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 修改配置#

進入安裝目錄的 conf/ 目錄下,拷貝配置樣本并進行修改:

# cp zoo_sample.cfg zoo.cfg

指定數(shù)據(jù)存儲目錄和日志文件目錄(目錄不用預(yù)先創(chuà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:用于計算的基礎(chǔ)時間單元。比如 session 超時:N*tickTime;
•initLimit:用于集群,允許從節(jié)點連接并同步到 master 節(jié)點的初始化連接時間,以 tickTime 的倍數(shù)來表示;
•syncLimit:用于集群, master 主節(jié)點與從節(jié)點之間發(fā)送消息,請求和應(yīng)答時間長度(心跳機制);
•dataDir:數(shù)據(jù)存儲位置;
•dataLogDir:日志目錄;
•clientPort:用于客戶端連接的端口,默認 2181

1.5 啟動#

由于已經(jīng)配置過環(huán)境變量,直接使用下面命令啟動即可:

zkServer.sh start

1.6 驗證#

使用 JPS 驗證進程是否已經(jīng)啟動,出現(xiàn) QuorumPeerMain 則代表啟動成功。

[root@hadoop001 bin]# jps
3814 QuorumPeerMain

二、集群環(huán)境搭建#

為保證集群高可用,Zookeeper 集群的節(jié)點數(shù)最好是奇數(shù),最少有三個節(jié)點,所以這里演示搭建一個三個節(jié)點的集群。這里我使用三臺主機進行搭建,主機名分別為 hadoop001,hadoop002,hadoop003。

2.1 修改配置#

解壓一份 zookeeper 安裝包,修改其配置文件 zoo.cfg,內(nèi)容如下。之后使用 scp 命令將安裝包分發(fā)到三臺服務(wù)器上:

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper-cluster/data/
dataLogDir=/usr/local/zookeeper-cluster/log/
clientPort=2181
# server.1 這個1是服務(wù)器的標識,可以是任意有效數(shù)字,標識這是第幾個服務(wù)器節(jié)點,這個標識要寫到dataDir目錄下面myid文件里
# 指名集群間通訊端口和選舉端口
server.1=hadoop001:2287:3387
server.2=hadoop002:2287:3387
server.3=hadoop003:2287:3387

2.2 標識節(jié)點#

分別在三臺主機的 dataDir 目錄下新建 myid 文件,并寫入對應(yīng)的節(jié)點標識。Zookeeper 集群通過 myid 文件識別集群節(jié)點,并通過上文配置的節(jié)點通信端口和選舉端口來進行節(jié)點通信,選舉出 Leader 節(jié)點。

創(chuàng)建存儲目錄:

# 三臺主機均執(zhí)行該命令
mkdir -vp /usr/local/zookeeper-cluster/data/

創(chuàng)建并寫入節(jié)點標識到 myid 文件:

# hadoop001主機
echo "1" > /usr/local/zookeeper-cluster/data/myid
# hadoop002主機
echo "2" > /usr/local/zookeeper-cluster/data/myid
# hadoop003主機
echo "3" > /usr/local/zookeeper-cluster/data/myid

2.3 啟動集群#

分別在三臺主機上,執(zhí)行如下命令啟動服務(wù):

/usr/app/zookeeper-cluster/zookeeper/bin/zkServer.sh start

2.4 集群驗證#

啟動后使用 zkServer.sh status 查看集群各個節(jié)點狀態(tài)。如圖所示:三個節(jié)點進程均啟動成功,并且 hadoop002 為 leader 節(jié)點,hadoop001 和 hadoop003 為 follower 節(jié)點。

  

更多大數(shù)據(jù)系列文章可以參見 GitHub 開源項目:大數(shù)據(jù)入門指南

總結(jié)

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

標簽:湘潭 黃山 通遼 湖北 山南 煙臺 賀州 懷化

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

    • 400-1100-266
    云南省| 安岳县| 阿拉善左旗| 清远市| 盐城市| 江山市| 资中县| 兖州市| 杭锦旗| 岳阳市| 内江市| 阿荣旗| 西林县| 衡东县| 西吉县| 泾川县| 潢川县| 洛川县| 凤山市| 资阳市| 高密市| 冀州市| 清涧县| 樟树市| 余姚市| 岱山县| 诏安县| 呼和浩特市| 南平市| 晋宁县| 肥西县| 南川市| 吐鲁番市| 本溪市| 保康县| 长海县| 惠东县| 龙南县| 大方县| 玉屏| 安化县|