天天看點

[Dubbo日記](1)Zookeeper安裝

版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 https://blog.csdn.net/SunnyYoona/article/details/51247539

1. 下載下傳位址
http://www.apache.org/dyn/closer.cgi/zookeeper/
2. 解壓

tar zxvf  zookeeper-3.4.8.tar.gz

3. 重命名

在對應的zookeeper-3.4.8/conf 下有一個檔案zoo_sample.cfg的這個檔案裡面配置了監聽用戶端連接配接的端口等一些資訊,Zookeeper 在啟動時會找zoo.cfg這個檔案作為預設配置檔案,是以我們重命名zoo_sample.cfg為zoo.cfg。使用如下指令:

  1. mv zoo_sample.cfg zoo.cfg

4. 配置檔案 zoo.cfg
  1. # The number of milliseconds of each tick

  2. tickTime=2000

  3. # The number of ticks that the initial

  4. # synchronization phase can take

  5. initLimit=10

  6. # The number of ticks that can pass between

  7. # sending a request and getting an acknowledgement

  8. syncLimit=5

  9. # the directory where the snapshot is stored.

  10. # do not use /tmp for storage, /tmp here is just

  11. # example sakes.

  12. dataDir=/home/xiaosi/zookeeper/data

  13. # the port at which the clients will connect

  14. clientPort=2181

  15. # the maximum number of client connections.

  16. # increase this if you need to handle more clients

  17. #maxClientCnxns=60

  18. #

  19. # Be sure to read the maintenance section of the

  20. # administrator guide before turning on autopurge.

  21. #

  22. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

隻需修改dataDir項即可,不要使用預設的/tmp目錄;

如果需要叢集,zoo.cfg的内容如下:(其中data目錄和server位址需改成你真實部署機器的資訊):

  1. tickTime=2000

  2. initLimit=10

  3. syncLimit=5

  4. dataDir=/home/xiaosi/zookeeper/data

  5. clientPort=2181

  6. server.1=10.20.153.10:2555:3555

  7. server.2=10.20.153.11:2555:3555

并在data目錄下放置myid檔案:(上面zoo.cfg中的dataDir)

  1. sudo mkdir data

  2. sudo vim myid

myid指明自己的id,對應上面zoo.cfg中server.後的數字,第一台的内容為1,第二台的内容為2,myid内容如下:

  1. 1

5. 啟動

進入bin目錄 ./zkServer.sh start

  1. xiaosi@Qunar:/opt/zookeeper-3.4.8/bin$ ./zkServer.sh start

  2. ZooKeeper JMX enabled by default

  3. Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg

  4. Starting zookeeper ... STARTED

檢視zookeeper狀态:

  1. xiaosi@Qunar:/opt/zookeeper-3.4.8/bin$ ./zkServer.sh status

  2. ZooKeeper JMX enabled by default

  3. Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg

  4. Mode: standalone

當zookeeper啟動時,會在/home/xiaosi/zookeeper/data下生成一個zookeeper_server.pid檔案。記錄了zookeeper程序的程序ID号(本例中為13402)。

  1. xiaosi   13402  6831  0 00:06 pts/20   00:00:00 /opt/jdk1.7.0_40/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /opt/zookeeper-3.4.8/bin/../build/classes:/opt/zookeeper-3.4.8/bin/../build/lib/*.jar:/opt/zookeeper-3.4.8/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper-3.4.8/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper-3.4.8/bin/../lib/netty-3.7.0.Final.jar:/opt/zookeeper-3.4.8/bin/../lib/log4j-1.2.16.jar:/opt/zookeeper-3.4.8/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.8/bin/../zookeeper-3.4.8.jar:/opt/zookeeper-3.4.8/bin/../src/java/lib/*.jar:/opt/zookeeper-3.4.8/bin/../conf:.:/opt/jdk1.7.0_40/lib -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg

  2. xiaosi   13497 12559  0 00:07 pts/20   00:00:00 grep --color=auto zookeeper

6. 關閉

進入bin目錄 ./zkServer.sh stop

  1. xiaosi@Qunar:/opt/zookeeper-3.4.8/bin$ ./zkServer.sh stop

  2. ZooKeeper JMX enabled by default

  3. Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg

  4. Stopping zookeeper ... STOPPED