天天看点

[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