寫在前面
本系列文章索引以及一些默認(rèn)好的條件在 傳送門
在配置Zookeeper之前,建議先配置Hadoop集群,具體的操作流程博主已更新完成,鏈接
step1 Zookeeper安裝包的下載
Zookeeper的安裝包版本不太相同,大致分為有編譯過的和沒有編譯過的(如有錯(cuò)請留言指正
一般情況下對(duì)于我們在解壓配置就能使用的情況下,我們可以下載編譯之后的版本,比如在官網(wǎng)上:
下面代表著源代碼,我們應(yīng)該選擇不在紅框之內(nèi)的
Zookeeper倉庫
本文以3.5.9為例,應(yīng)該下載上方連接中的:
這個(gè)版本的解壓后和其他未編譯過的有個(gè)顯著的不同:在解壓后有一個(gè)lib文件夾,通常里面保存著應(yīng)該會(huì)用到的文件等下載速度較快,不再網(wǎng)盤分享
step2 關(guān)閉防火墻
如果防火墻處于打開的狀態(tài),會(huì)影響到虛擬機(jī)之間的互相訪問,以及從主機(jī)通過web瀏覽器查看各個(gè)服務(wù)器節(jié)點(diǎn)的狀態(tài)
命令:
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
step3 解壓配置Zookeeper
1 解壓并創(chuàng)建修改/conf/zoo.cfg文件
將下載好的文件放到master節(jié)點(diǎn)的/usr/local/
之下
然后解壓文件,命令:
tar -zxvf apache-zookeeper-3.5.9-bin.tar.gz
解壓之后,將文件夾的名字去掉版本號(hào):mv apache-zookeeper zookeeper
然后跳轉(zhuǎn)到./zookeeper/conf
下,將官方給的zoo.cfg示例文件改名:
cp zoo_sample.cfg zoo.cfg
然后編輯zoo.cfg
大致改為:
切勿盲目CV,記得修改為自己的主機(jī)名
# 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/
# the port at which the clients will connect
clientPort=2181
# master
server.1=0.0.0.0:2881:3881
server.2=slave01-315:2881:3881
server.3=slave02-315:2881:3881
2 創(chuàng)建并修改/data/myid
在zookeeper根目錄下,我們再創(chuàng)建一個(gè)data文件夾mkdir -p /usr/local/zookeeper/data
然后創(chuàng)建并編輯myid
文件
cd /usr/local/zookeeper/data
touch myid
vim myid
在master節(jié)點(diǎn)的myid中,寫入一個(gè)數(shù)字1
注意不得加任何空格,任何注釋,必須單純一行一列一個(gè)字符’1’
step4 配置文件傳送到其他節(jié)點(diǎn)
我們需要將從master的文件放到slave1,slave2上
scp -r /usr/local/zookeeper slave1:/usr/local
scp -r /usr/local/zookeeper slave2:/usr/local
在slave1上,我們需要把/data/myid
中的內(nèi)容改為2
在slave2上,我們需要把/data/myid
中的內(nèi)容改為3
注意不得加任何空格,任何注釋,必須單純一行一列一個(gè)字符’1’
在slave1上,我們需要把/conf/zoo.cfg
改成:
切勿盲目CV,記得修改為自己的主機(jī)名
# 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/
# the port at which the clients will connect
clientPort=2181
server.1=master315:2881:3881
server.2=0.0.0.0:2881:3881
server.3=slave02-315:2881:3881
在slave2下,我們需要將/conf/zoo.cfg
文件修改為:
切勿盲目CV,記得修改為自己的主機(jī)名
# 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/
# the port at which the clients will connect
clientPort=2181
server.1=master315:2881:3881
server.2=slave01-315:2881:3881
server.3=0.0.0.0:2881:3881
如果是小白從頭開始配的話,應(yīng)該不會(huì)出現(xiàn)2181端口被占用的情況,如果說自己的2181端口被占用,可以kill -9該進(jìn)程
查看進(jìn)程是否被占用:netstat -nltp | grep 2181
若顯示空白則恭喜你不需要進(jìn)行任何操作
若顯示除了某進(jìn)程占用該端口,應(yīng)該kill -9 進(jìn)程號(hào)
step5 設(shè)置環(huán)境變量
我們修改~/.bashrc
文件
vim ~/.bashrc
加入:
export PATH=$PATH:/usr/local/zookeeper/bin
然后:
source ~/.bashrc
現(xiàn)在應(yīng)該使得該文件生效了
step6 啟動(dòng)zookeeper
zkServer.sh start
這時(shí),我們查看zookeeper/data/
下的所有文件:
cd /usr/local/zookeeper/data
ls -laF
發(fā)現(xiàn)除了myid
還會(huì)有另外的若干文件(version-2文件夾&&zookeeper_server.pid),這是請注意:
如果不是通過命令使得zookeeper自動(dòng)關(guān)閉的,在下次啟動(dòng)前均需刪除該目錄下除了myid的所有文件
在三個(gè)節(jié)點(diǎn)均啟動(dòng)zookeeper集群
啟動(dòng)命令是:zkServer.sh start
重啟命令是:zkServer.sh restart
關(guān)閉命令是:zkServer.sh stop
查看狀態(tài)命令是:zkServer.sh status
注意,在我們依次啟動(dòng)節(jié)點(diǎn)的zookeeper的過程中,可能會(huì)遇到首先啟動(dòng)的節(jié)點(diǎn)的日志文件中出現(xiàn)拒絕連接的情況,這時(shí)請忽略,原因是:
后續(xù)節(jié)點(diǎn)未啟動(dòng),所以會(huì)導(dǎo)致和其他未開啟的節(jié)點(diǎn)通信失敗導(dǎo)致拒絕連接,我們應(yīng)當(dāng)查看最后啟動(dòng)zookeeper的結(jié)點(diǎn)的日志文件(/usr/local/zookeeper/logs/
),
step7 啟動(dòng)成功及狀態(tài)查看
在我們成功啟動(dòng)集群之后,應(yīng)該會(huì)看到:
master
slave1:
slave2:
出現(xiàn)started則證明啟動(dòng)成功,我們查看狀態(tài):
master:
slave1:
slave2:
在此,發(fā)現(xiàn)master為leader,其余兩個(gè)節(jié)點(diǎn)為follower
這里的leader由zookeeper內(nèi)部選舉產(chǎn)生,誰是leader均有可能,不必太在意
step8 驗(yàn)證zookeeper安裝
在每個(gè)節(jié)點(diǎn)均輸入:jps
來查看相關(guān)進(jìn)程
master:
slave1:
slave2:
到這里進(jìn)本就證明安裝沒大問題了
但是為了嚴(yán)謹(jǐn)一點(diǎn),我們測試下功能
step9 zookeeper功能測試
我們進(jìn)入zookeeper的命令行工具:
紅框是命令zkCli.sh -server master315:2181
在箭頭所示區(qū)域輸入:create /hello world
get /hello
可以發(fā)現(xiàn)莫得問題,然后就可以退出了
輸入:quit
文章來源:http://www.zghlxwxcb.cn/news/detail-428662.html
到此,Zookeeper安裝結(jié)束
如有問題可以 留言 or 私信 or q_2649432030文章來源地址http://www.zghlxwxcb.cn/news/detail-428662.html
到了這里,關(guān)于Zookeeper集群搭建記錄 | 云計(jì)算[CentOS7] | Zookeeper集群搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!