標籤:loser each set apache initial syn 下載 connect more
http://blog.csdn.net/aqsunkai/article/details/51683632
zookeeper的安裝支援單機模式和叢集模式
:http://www.apache.org/dyn/closer.cgi/zookeeper/,當前穩定版本為3.4.8
單機模式修改zookeeper設定檔zoo.cfg
解壓後進入conf目錄,修改zoo_sample.cfg檔案名稱為:zoo.cfg,這是因為zookeeper啟動時預設載入zoo.cfg設定檔。修改zoo.cfg檔案內容如下:
[html] view plain copy print?
- # The number of milliseconds of each tick
- #tickTime:這個時間是作為 Zookeeper 伺服器之間或用戶端與伺服器之間維持心跳的時間間隔,也就是每個 tickTime 時間就會發送一個心跳。
- #預設情況下最小的會話逾時時間為兩倍的tickTime
- tickTime=2000
- # The number of ticks that the initial
- # synchronization phase can take
- #zookeeper叢集中的包含多台server, 其中一台為leader, 叢集中其餘的server為follower. initLimit參數配置初始化串連時,
- #follower和leader之間的最長心跳時間. 此時該參數設定為5, 說明時間限制為5倍tickTime, 即5*2000=10000ms=10s.
- initLimit=5
- # The number of ticks that can pass between
- # sending a request and getting an acknowledgement
- #該參數配置leader和follower之間發送訊息, 請求和應答的最大時間長度. 此時該參數設定為2, 說明時間限制為2倍tickTime, 即4000ms.
- syncLimit=2
- # the directory where the snapshot is stored.
- # do not use /tmp for storage, /tmp here is just
- # example sakes.
- #dataDir:顧名思義就是 Zookeeper 儲存資料的目錄,預設情況下,Zookeeper 將寫資料的記錄檔也儲存在這個目錄裡。
- dataDir=D:\\zookeeper-3.4.8\\data
- #dataLogDir:顧名思義就是 Zookeeper 儲存記錄檔的目錄
- dataLogDir=D:\\zookeeper-3.4.8\\log
- # the port at which the clients will connect
- #clientPort:這個連接埠就是用戶端串連 Zookeeper 伺服器的連接埠,Zookeeper 會監聽這個連接埠,接受用戶端的訪問請求。
- clientPort=2181
- # the maximum number of client connections.
- # increase this if you need to handle more clients
- #maxClientCnxns:限制串連到 ZooKeeper 的用戶端的數量
- #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-3.4.8檔案夾下建立data和log檔案夾
啟動zookeeper
cmd命令進入zookeeper-3.4.8\bin目錄,啟動zkServer.cmd
或者直接雙擊zkServer.cmd啟動,雙擊後視窗不會關閉,如果關閉了表示未啟動成功
如果jdk環境變數設定了,但是提示JAVA_HOME找不到,則需要修改該目錄下的zkEnv.cmd關於JAVA_HOME的一部分
[html] view plain copy print?
- set JAVA_HOME="D:\Program Files\Java\jdk1.7.0_75"
-
- if not defined JAVA_HOME (
- echo Error: JAVA_HOME is not set.
- goto :eof
- )
-
- if not exist %JAVA_HOME%\bin\java.exe (
- echo Error: JAVA_HOME is incorrectly set.
- goto :eof
- )
-
- set JAVA=%JAVA_HOME%\bin\java
偽叢集模式
所謂偽叢集, 是指在單台機器中啟動多個zookeeper進程,,並組成一個叢集, 以啟動3個zookeeper進程為例。
把zookeeper-3.4.8檔案夾複製2份,這三個檔案夾分別命名為zookeeper-3.4.8-1、zookeeper-3.4.8-2、zookeeper-3.4.8-3
下面是zookeeper-3.4.8-1/conf檔案夾下的zoo.cfg檔案中配置的幾個選項:
[html] view plain copy print?
- dataDir=D:\\zookeeper-3.4.8-1\\data
- dataLogDir=D:\\zookeeper-3.4.8-1\\log
- clientPort=2181
- server.1=127.0.0.1:8281:7271
- server.2=127.0.0.1:8282:7272
- server.3=127.0.0.1:8283:7273
server.X=A:B:C 其中X是一個數字, 表示這是第幾號server. A是該server所在的IP地址. B配置該server和叢集中的leader交換訊息所使用的連接埠. C配置選舉leader時所使用的連接埠. 由於配置的是偽叢集模式, 所以各個server的B, C參數必須不同。
參照zookeeper-3.4.8-1/conf檔案夾下zoo.cfg檔案,分別配置zookeeper-3.4.8-2/conf/zoo.cfg、zookeeper-3.4.8-3/conf/zoo.cfg檔案,只需要修改dataDir、dataLogDir、clientPort即可。
在三個zoo.cfg檔案中設定的dataDir目錄下建立myid檔案,寫入一個數字, 該數字表示這是第幾號server,該數字必須和zoo.cfg檔案中的server.X中的X對應。如D:\\zookeeper-3.4.8-1\\data\\myid檔案中數字是1。
然後就是分別啟動三個zookeeper了。
叢集模式
叢集模式的配置和偽叢集基本一致.
由於叢集模式下, 各server部署在不同的機器上, 因此各server的conf/zoo.cfg檔案可以完全一樣。
下面是一個樣本:
[html] view plain copy print?
- tickTime=2000
- initLimit=5
- syncLimit=2
- dataDir=D:\\zookeeper-3.4.8\\data
- dataLogDir=D:\\zookeeper-3.4.8\\log
- clientPort=2181
- server.21=192.168.0.1:8280:7270
- server.22=192.168.0.2:8280:7270
- server.23=192.168.0.3:8280:7270
樣本中部署了3台zookeeper server,分別部署在192.168.0.1、192.168.0.2、192.168.0.3上。 需要注意的是,各server的dataDir目錄下的myid檔案中的數字必須不同。
192.168.0.1server的myid為21,192.168.0.2server的myid為22,192.168.0.3server的myid為23。
Windows下zookeeper註冊中心的安裝和啟動