深入浅出Zookeeper集群搭建
部署環(huán)境:Centos7.5
zookeeper下載地址:https://zookeeper.apache.org/releases.html#download
選擇3.4.14版本:http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/
開始下載安裝:
接下來我們修改一下配置文件:
zoo.cfg配置文件如下:
# 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. # 數(shù)據(jù)文件夾 dataDir=/usr/local/zookeeper-3.4.14/data # 日志文件夾 dataLogDir=/usr/local/zookeeper-3.4.14/logs # 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 server.1=172.20.42.10:2888:3888 server.2=172.20.41.96:2888:3888 server.3=172.20.42.247:2888:3888tickTime:這個(gè)時(shí)間是作為 Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳。
initLimit:這個(gè)配置項(xiàng)是用來配置 Zookeeper 接受客戶端(這里所說的客戶端不是用戶連接 Zookeeper 服務(wù)器的客戶端,而是 Zookeeper 服務(wù)器集群中連接到 Leader 的 Follower 服務(wù)器)初始化連接時(shí)最長能忍受多少個(gè)心跳時(shí)間間隔數(shù)。當(dāng)已經(jīng)超過 10個(gè)心跳的時(shí)間(也就是 tickTime)長度后 Zookeeper 服務(wù)器還沒有收到客戶端的返回信息,那么表明這個(gè)客戶端連接失敗。總的時(shí)間長度就是 10*2000=20 秒
syncLimit:這個(gè)配置項(xiàng)標(biāo)識 Leader 與 Follower 之間發(fā)送消息,請求和應(yīng)答時(shí)間長度,最長不能超過多少個(gè) tickTime 的時(shí)間長度,總的時(shí)間長度就是 5*2000=10秒
dataDir:顧名思義就是 Zookeeper 保存數(shù)據(jù)的目錄,默認(rèn)情況下,Zookeeper 將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。
clientPort:這個(gè)端口就是客戶端連接 Zookeeper 服務(wù)器的端口,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請求。
server.A=B:C:D:其中 A 是一個(gè)數(shù)字,表示這個(gè)是第幾號服務(wù)器;B 是這個(gè)服務(wù)器的 ip 地址;C 表示的是這個(gè)服務(wù)器與集群中的 Leader 服務(wù)器交換信息的端口;D 表示的是萬一集群中的 Leader 服務(wù)器掛了,需要一個(gè)端口來重新進(jìn)行選舉,選出一個(gè)新的 Leader,而這個(gè)端口就是用來執(zhí)行選舉時(shí)服務(wù)器相互通信的端口。如果是偽集群的配置方式,由于 B 都是一樣,所以不同的 Zookeeper 實(shí)例通信端口號不能一樣,所以要給它們分配不同的端口號。
保存退出,去創(chuàng)建數(shù)據(jù)目錄和日志目錄
cd /usr/local/zookeeper-3.4.14mkdir logs mkdir datacd data/ vi myid #根據(jù)ip地址,在每個(gè)目錄中創(chuàng)建文件myid 文件,寫入當(dāng)前實(shí)例的server id,即1.2.3 1
啟動(dòng)三個(gè)zookeeper實(shí)例
./zkServer.sh status 查看狀態(tài)
至此,我們對zookeeper就算有了一個(gè)入門的了解,當(dāng)然zookeeper遠(yuǎn)比我們這里描述的功能多,比如用zookeeper實(shí)現(xiàn)集群管理,分布式鎖,分布式隊(duì)列,zookeeper集群leader選舉等等…
總結(jié)
以上是生活随笔為你收集整理的深入浅出Zookeeper集群搭建的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 55句史上最伤人的语录集:看完一阵心酸啊
- 下一篇: 资产管理运维一体化 接入IOT、BIM的