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