最近打算好好學(xué)習(xí)一下zookeeper,那么第一步就是要搭建一個(gè)環(huán)境。
單機(jī)版的比較簡(jiǎn)單,這里就不介紹了。
集群版本的,看網(wǎng)上的教程也蠻簡(jiǎn)單的,但是自己動(dòng)起手來還是會(huì)遇到各種問題,這里做一下記錄。
成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比靈臺(tái)網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式靈臺(tái)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋靈臺(tái)地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。
1、3個(gè)阿里云服務(wù)器,其中2個(gè)ECS,1個(gè)輕量服務(wù)器。
2、zookeeper使用最新版本 https://archive.apache.org/dist/zookeeper/stable/apache-zookeeper-3.5.5-bin.tar.gz
3、3臺(tái)云主機(jī)的Java使用jdk1.8版本。
1、檢查各個(gè)主機(jī)的Java環(huán)境是否正常
2、下載最新版本zookeeper,并解壓,3臺(tái)機(jī)器最好采用統(tǒng)一的目錄,我采用的目錄
/enzi/zk/apache-zookeeper-3.5.5-bin
3、3個(gè)機(jī)器,分別創(chuàng)建zookeeper的數(shù)據(jù)目錄和日志目錄
/enzi/zk/data
/enzi/zk/log
4、進(jìn)入程序目錄下,3個(gè)機(jī)器操作都一樣
/enzi/zk/apache-zookeeper-3.5.5-bin/conf
復(fù)制zoo_sample.cfg為zoo.cfg,并修改zoo.cfg內(nèi)容如下:
# 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=/enzi/zk/data
dataLogDir=/enzi/zk/log
# the port at which the clients will connect
clientPort=2181
#admin.serverPort=8089
# 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
server.1=ip1:2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888
quorumListenOnAllIPs=true
5、創(chuàng)建myid文件
分別在對(duì)應(yīng)的data目錄下,為自己的服務(wù)指定myid,內(nèi)容就是zoo.cfg里面server.后面的序號(hào),分別是1,2,3,ip1機(jī)器下myid內(nèi)容為1,依次類推。
6、依次啟動(dòng)3個(gè)機(jī)器zookeeper服務(wù)
bin/zkServer.sh start
如果想看有沒有什么錯(cuò)誤信息可以使用如下命令,在調(diào)試階段建議使用這個(gè)命令。
bin/zkServer.sh start-foreground
7、查看是否啟動(dòng)成功
mode:follower,代表這個(gè)服務(wù)是follower節(jié)點(diǎn)。
這里server.1是leader節(jié)點(diǎn)。
8、使用客戶端進(jìn)行連接,這里采用的windows的客戶端
zkCli.cmd -server ip1:2181,ip2:2181,ip3:2181
使用命令,創(chuàng)建臨時(shí)節(jié)點(diǎn)如下
注意:對(duì)于阿里云,因?yàn)榉阑饓蛘逧CS的安全策略來說,會(huì)導(dǎo)致集群之間的接口連接失敗。
1、輕量服務(wù)器來說需要把2181,2888,3888增加到防火墻上。
2、對(duì)于ESC需要把2181,2888,3888的安全規(guī)則,入口和出口都設(shè)置為允許。
分享文章:zookeeper(1)利用3個(gè)機(jī)器,搭建zk集群模式
轉(zhuǎn)載源于:http://jinyejixie.com/article34/podjse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、自適應(yīng)網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、建站公司、用戶體驗(yàn)、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)