1. 程式人生 > 實用技巧 >zookeeper在window下配置

zookeeper在window下配置

一、下載地址

http://apache.fayea.com/zookeeper

二、安裝

下載解壓後如圖

三、單機配置

1. 修改 config 下的配置檔案

開啟 conf 目錄下 zoo_sample.cfg 將其名字改為 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=D:/JAVA/zookeeper-3.4.10/data dataLogDir=D:/JAVA/zookeeper-3.4.10/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

2. 引數說明

  • tickTime:基本事件單元,以毫秒為單位,用來控制心跳和超時,預設情況超時的時間為兩倍的tickTime
  • dataDir:資料目錄.可以是任意目錄.
  • dataLogDir:log目錄, 同樣可以是任意目錄. 如果沒有設定該引數, 將使用和dataDir相同的設定.
  • clientPort:監聽client連線的埠號.
  • maxClientCnxns:限制連線到zookeeper的客戶端數量,並且限制併發連線數量,它通過ip區分不同的客戶端。
  • minSessionTimeout和maxSessionTimeout:最小會話超時時間和最大的會話超時時間,在預設情況下,最小的超時時間為2倍的tickTime時間,最大的會話超時時間為20倍的會話超時時間,系統啟動時會顯示相應的資訊。預設為-1
  • initLimit:引數設定了允許所有跟隨者與領導者進行連線並同步的時間,如果在設定的時間段內,半數以上的跟隨者未能完成同步,領導者便會宣佈放棄領導地位,進行另一次的領導選舉。如果zk叢集環境數量確實很大,同步資料的時間會變長,因此這種情況下可以適當調大該引數。預設為10
  • syncLimit:引數設定了允許一個跟隨者與一個領導者進行同步的時間,如果在設定的時間段內,跟隨者未完成同步,它將會被叢集丟棄。所有關聯到這個跟隨者的客戶端將連線到另外一個跟隨著。

3. 啟動 Zookeeper

在bin目錄下,雙擊zkServer.cmd即可啟動Zookeeper。
如果啟動閃退,可能是配置檔案有問題,可以使用預設配置檔案看是否可以啟動。

四、偽叢集模式

所謂偽叢集, 是指在單臺機器中啟動多個zookeeper程序, 並組成一個叢集. 以啟動3個zookeeper程序為例.
將zookeeper的目錄拷貝2份:
|–zookeeper-3.4.10-0
|–zookeeper-3.4.10-1
|–zookeeper-3.4.10-2

1. 配置資料和日誌存放路徑

與單機配置類似,只是3個zookeeper不能配置同一個目錄下,配置如下
zookeeper0

# 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=D:/JAVA/zookeeper-3.4.10-0/data
dataLogDir=D:/JAVA/zookeeper-3.4.10-0/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.0=127.0.0.1:2888:3888
server.1=127.0.0.1:2889:3889
server.2=127.0.0.1:2890:3890
zookeeper-3.4.10-1 、zookeeper-3.4.10-2與zookeeper-3.4.10-0類似,只有dataDir和dataLogDir配置到不同的目錄,clientPort在zookeeper-3.4.10-0中是2181,在zookeeper-3.4.10-1中是 2182,在 zookeeper-3.4.10-2中為 2183
       在之前設定的dataDir中新建myid檔案, 寫入一個數字, 該數字表示這是第幾號server. 該數字必須和zoo.cfg檔案中的server.X中的X一一對應.
D:/JAVA/zookeeper-3.4.10-0/data/myid檔案中寫入0,zookeeper-3.4.10-1為1,zookeeper-3.4.10-2為2
 server.A=B:C:D:其中
A 是一個數字,表示這個是第幾號伺服器;
B 是這個伺服器的 ip 地址;
C 表示的是這個伺服器與叢集中的 Leader 伺服器交換資訊的埠;
D 表示的是萬一叢集中的 Leader 伺服器掛了,需要一個埠來重新進行選舉,選出一個新的 Leader,而這個埠就是用來執行選舉時伺服器相互通訊的埠。
如果是偽叢集的配置方式,由於 B 都是一樣,所以不同的 Zookeeper 例項通訊埠號不能一樣,所以要給它們分配不同的埠號。

五、叢集模式

叢集模式的配置和偽叢集基本一致.
由於叢集模式下, 各server部署在不同的機器上, 因此各server的conf/zoo.cfg檔案可以完全一樣.基於Linux配置。

tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/zookeeper/data
dataLogDir=/home/zookeeper/logs
clientPort=4180
server.43=10.1.39.43:2888:3888
server.47=10.1.39.47:2888:3888
server.48=10.1.39.48:2888:3888
部署了3臺zookeeper server, 分別部署在10.1.39.43, 10.1.39.47, 10.1.39.48上. 需要注意的是, 各server的dataDir目錄下的myid檔案中的數字必須不同.

10.1.39.43 server的myid為43, 10.1.39.47 server的myid為47, 10.1.39.48 server的myid為48.

10.1.39.43 server的myid為43, 10.1.39.47 server的myid為47, 10.1.39.48 server的myid為48.

部署完成後即可分別啟動。
啟動後要檢查 Zookeeper 是否已經在服務,可以通過 netstat -at|grep 2181 命令檢視是否有 clientPort 埠號在監聽服務。

原文出處:

https://blog.csdn.net/cainiao_ACCP/article/details/73850904