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