博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

zookeeper安装

Posted on 2017-12-14 17:41  红与黑hyh  阅读(273)  评论(0编辑  收藏  举报

1.         Zookeeper服务集群规模不小于三个节点,要求各服务之间系统时间要保持一致。

2.         在m1的usr/local目录下,解压缩zookeeper(执行命令tar –zvxf zookeeper.tar.gz)

3.         设置环境变量

打开/etc/profile文件!内容如下:

 

[html] view plain copy
 
  1. #set java & hadoop   
  2. export JAVA_HOME=/usr/local/program/jdk  
  3. export HADOOP_HOME=/usr/local/program/hadoop  
  4. export ZOOKEEPER_HOME=/usr/local/program/zookeeper  
  5. export PATH=.:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin:$JAVA_HOME/bin:$PATH 

 

 

注:修改完后profile记得执行source /etc/profile

 

4.         在解压后的zookeeper的目录下进入conf目录修改配置文件(zk版本为:zookeeprer-3.4.6)

更名操作:mv zoo_sample.cfg zoo.cfg

5.         编辑zoo.cfg (vi zoo.cfg)

修改dataDir=/usr/local/program/zookeeper/data/

新增server.0=m1:2888:3888

         server.1=s1:2888:3888

         server.2=s2:2888:3888

 

文件如下:

[html] view plain copy
 
  1. # The number of milliseconds of each tick  
  2.   
  3. tickTime=2000  
  4.   
  5. # The number of ticks that the initial   
  6.   
  7. # synchronization phase can take  
  8.   
  9. initLimit=10  
  10.   
  11. # The number of ticks that can pass between   
  12.   
  13. # sending a request and getting an acknowledgement  
  14.   
  15. syncLimit=5  
  16.   
  17. # the directory where the snapshot is stored.  
  18.   
  19. # do not use /tmp for storage, /tmp here is just   
  20.   
  21. # example sakes.  
  22.   
  23. dataDir=/usr/local/program/zookeeper/data  
  24.   
  25. # the port at which the clients will connect  
  26.   
  27. clientPort=2181  
  28.   
  29. #  
  30.   
  31. # Be sure to read the maintenance section of the   
  32.   
  33. # administrator guide before turning on autopurge.  
  34.   
  35. #  
  36.   
  37. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance  
  38.   
  39. #  
  40.   
  41. # The number of snapshots to retain in dataDir  
  42.   
  43. #autopurge.snapRetainCount=3  
  44.   
  45. # Purge task interval in hours  
  46.   
  47. # Set to "0" to disable auto purge feature  
  48.   
  49. #autopurge.purgeInterval=1  
  50.   
  51.    
  52.   
  53. server.0=m1:2888:3888  
  54.   
  55. server.1=s1:2888:3888  
  56.   
  57. server.2=s2:2888:3888  

 

  注:

[html] view plain copy
 
  1. server.0=m1:2888:3888  
  2. server.1=s1:2888:3888  
  3. server.2=s2:2888:3888  

这三行为配置zookeeper集群的机器(m1、s1、s2)分别用server.0和server.1、server.2标识,2888和3888为端口号(zookeeper集群包含一个leader(领导)和多个fllower(随从),启动zookeeper集群时会随机分配端口号,分配的端口号为2888的为leader,端口号为3888的是fllower)

 

6.         创建文件夹mkdir /usr/local/program/zookeeper/data

7.         在data目录下,创建文件myid,值为0  (0用来标识m1这台机器的zookeeper )

 

到此为止 m1上的配置就已经完成;接下来配置s1和s2.

 

8.         把zookeeper目录复制到s1和s2中(scp –r /usr/local/program/zookeeper s1:/usr/local/program/zookeeper)

9.         把修改后的etc/profile文件复制到s1和s2中

(复制完后记得在s1和s2中执行命令source /etc/profile)

10.     把s1中相应的myid中的值改为1,s2中相应的myid中的值改为2

11.     启动,在三个节点上分别执行命令zkServer.sh  start

12.     检验,在三个节点上分别执行命令zkServer.sh  status

 

 

 

zookeeper的shell操作

启动zookeeper:zkServer.sh  start

进入zookeeper:zkCli.sh