Windows下zookeeper註冊中心的安裝和啟動

來源:互聯網
上載者:User

標籤: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?
  1. # The number of milliseconds of each tick  
  2. #tickTime:這個時間是作為 Zookeeper 伺服器之間或用戶端與伺服器之間維持心跳的時間間隔,也就是每個 tickTime 時間就會發送一個心跳。  
  3. #預設情況下最小的會話逾時時間為兩倍的tickTime  
  4. tickTime=2000  
  5. # The number of ticks that the initial   
  6. # synchronization phase can take  
  7. #zookeeper叢集中的包含多台server, 其中一台為leader, 叢集中其餘的server為follower. initLimit參數配置初始化串連時,   
  8. #follower和leader之間的最長心跳時間. 此時該參數設定為5, 說明時間限制為5倍tickTime, 即5*2000=10000ms=10s.  
  9. initLimit=5  
  10. # The number of ticks that can pass between   
  11. # sending a request and getting an acknowledgement  
  12. #該參數配置leader和follower之間發送訊息, 請求和應答的最大時間長度. 此時該參數設定為2, 說明時間限制為2倍tickTime, 即4000ms.  
  13. syncLimit=2  
  14. # the directory where the snapshot is stored.  
  15. # do not use /tmp for storage, /tmp here is just   
  16. # example sakes.  
  17. #dataDir:顧名思義就是 Zookeeper 儲存資料的目錄,預設情況下,Zookeeper 將寫資料的記錄檔也儲存在這個目錄裡。  
  18. dataDir=D:\\zookeeper-3.4.8\\data  
  19. #dataLogDir:顧名思義就是 Zookeeper 儲存記錄檔的目錄  
  20. dataLogDir=D:\\zookeeper-3.4.8\\log  
  21. # the port at which the clients will connect  
  22. #clientPort:這個連接埠就是用戶端串連 Zookeeper 伺服器的連接埠,Zookeeper 會監聽這個連接埠,接受用戶端的訪問請求。  
  23. clientPort=2181  
  24. # the maximum number of client connections.  
  25. # increase this if you need to handle more clients  
  26. #maxClientCnxns:限制串連到 ZooKeeper 的用戶端的數量  
  27. #maxClientCnxns=60  
  28. #  
  29. # Be sure to read the maintenance section of the   
  30. # administrator guide before turning on autopurge.  
  31. #  
  32. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance  
  33. #  
  34. # The number of snapshots to retain in dataDir  
  35. #autopurge.snapRetainCount=3  
  36. # Purge task interval in hours  
  37. # Set to "0" to disable auto purge feature  
  38. #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?
  1. set JAVA_HOME="D:\Program Files\Java\jdk1.7.0_75"  
  2.   
  3. if not defined JAVA_HOME (  
  4.   echo Error: JAVA_HOME is not set.  
  5.   goto :eof  
  6. )  
  7.   
  8. if not exist %JAVA_HOME%\bin\java.exe (  
  9.   echo Error: JAVA_HOME is incorrectly set.  
  10.   goto :eof  
  11. )  
  12.   
  13. 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?
  1. dataDir=D:\\zookeeper-3.4.8-1\\data  
  2. dataLogDir=D:\\zookeeper-3.4.8-1\\log  
  3. clientPort=2181  
  4. server.1=127.0.0.1:8281:7271  
  5. server.2=127.0.0.1:8282:7272  
  6. 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?
  1. tickTime=2000  
  2. initLimit=5  
  3. syncLimit=2  
  4. dataDir=D:\\zookeeper-3.4.8\\data  
  5. dataLogDir=D:\\zookeeper-3.4.8\\log  
  6. clientPort=2181  
  7. server.21=192.168.0.1:8280:7270  
  8. server.22=192.168.0.2:8280:7270  
  9. 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註冊中心的安裝和啟動

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.