【运维技术】Zookeeper单机以及集群搭建教程
生活随笔
收集整理的這篇文章主要介紹了
【运维技术】Zookeeper单机以及集群搭建教程
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Zookeeper單機(jī)以及集群搭建教程
單機(jī)搭建
單機(jī)安裝以及啟動(dòng)
安裝zookeeper的前提是必須有java環(huán)境
# 選擇目錄進(jìn)行下載安裝 cd /app # 下載zk,可以去官方網(wǎng)站下載,自己上傳 wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz # 解壓zk tar -zxvf zookeeper-3.4.11.tar.gz # 設(shè)定軟連接 ln -s zookeeper-3.4.11 zookeeper # 添加兩個(gè)目錄,一個(gè)是數(shù)據(jù)目錄,一個(gè)是日志目錄 cd zookeeper/ mkdir data mkdir log # 添加配置文件zoo.cfg在zookeeper的config目錄下面見(jiàn)【2】使用:wq! 進(jìn)行保存 cd conf cp zoo_sample.cfg zoo.cfg # 修改 dataDir=/app/zookeeper/data dataLogDir=/app/zookeeper/log 目錄 vi zoo.cfg # 進(jìn)入bin目錄進(jìn)行啟動(dòng) cd ../bin ./zkServer.sh start # 顯示如下:Starting zookeeper ... STARTED即為成功單機(jī)配置zoo.cfg的配置的內(nèi)容,只需要修改dataDir、dataLogDir
# 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=/app/zookeeper/data dataLogDir=/app/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單機(jī)常用命令
# 進(jìn)入zookeeper目錄使用命令,連接成功則說(shuō)明通過(guò) ./zkCli.sh # 啟動(dòng)zk服務(wù) ./zkServer.sh start # 查看zk服務(wù)狀態(tài) ./zkServer.sh status # 停止zk服務(wù) ./zkServer.sh stop # 重啟zk服務(wù) ./zkServer.sh restart集群搭建
虛擬機(jī)配置
| 172.16.48.129 | 172.16.48.130 | 172.16.48.131 |
| myid:1 | myid:2 | myid:3 |
myid配置
# 在每個(gè)虛擬機(jī)的dataDir=/app/zookeeper/data目錄下面創(chuàng)建myid文件 cd /app/zookeeper/data # 創(chuàng)建myid文件,內(nèi)容依照表格1,2,3.使用:wq進(jìn)保存 vim myidzoo.cfg配置添加
# 其他配置同單機(jī)配置 # 在zoo.cfg下面添加如下的集群配置server.myid # 對(duì)應(yīng)其他實(shí)例的內(nèi)網(wǎng)ip地址 server.1=172.16.48.129:2888:3888 server.2=172.16.48.130:2888:3888 server.3=172.16.48.131:2888:3888在三臺(tái)虛擬機(jī)的終端同時(shí)啟動(dòng)三個(gè)zookeeper實(shí)例,zk1 -》 zk2 -》 zk3
cd /app/zookeeper/bin ./zkServer.sh start ./zkServer.sh status # 分別在狀態(tài)中顯示了leader還是follower| 172.16.48.129 | 172.16.48.130 | 172.16.48.131 |
| follower | follower | leader |
高可用測(cè)試
按照道理zookeeper高可用3臺(tái)的情況下只要兩臺(tái)掛了,集群就無(wú)法提供服務(wù)了。
一臺(tái)掛了的情況: 關(guān)閉虛擬機(jī)3的zookeeper,調(diào)用status命令
| 172.16.48.129 | 172.16.48.130 | 172.16.48.131 |
| follower | leader | Error contacting service. It is probably not running. |
虛擬機(jī)2轉(zhuǎn)為了leader,虛擬機(jī)1和2一起提供服務(wù)
兩臺(tái)掛了的情況: 關(guān)閉虛擬機(jī)2的zookeeper,調(diào)用status命令
| 172.16.48.129 | 172.16.48.130 | 172.16.48.131 |
| Error contacting service. It is probably not running. | Error contacting service. It is probably not running. | Error contacting service. It is probably not running. |
重新啟動(dòng)一臺(tái)后,虛擬機(jī)1和虛擬機(jī)2能夠提供服務(wù)
轉(zhuǎn)載于:https://www.cnblogs.com/fly-piglet/p/9837206.html
總結(jié)
以上是生活随笔為你收集整理的【运维技术】Zookeeper单机以及集群搭建教程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 洛谷P1966 火柴排队(逆序对)
- 下一篇: 学习笔记27—python中numpy.