zoukankan      html  css  js  c++  java
  • Zookeeper集群搭建

    安装环境:

    • CentOS 7.x(最少三台,并以及配置好免密登录以及关闭防火墙,可参考 此博客 )
    • Java环境:JDK1.8(此步骤不再详述,如果不会的朋友请参考 此博客 中的jdk安装)
    • apache-zookeeper-3.6.2 安装包下载
    1. 上传安装包到服务器(此处以 /usr/local 为例)
    2. 解压  tar -zxvf apache-zookeeper-3.6.2-bin.tar.gz
    3. 在解压目录下创建data目录与logs目录
      # 修改名称
      mv apache-zookeeper-3.6.2-bin zookeeper
      cd zookeeper
      mkdir data mkdir logs
    4. 进入conf目录下编写配置文件
      # zoo_sample.cfg为自带的例子,拷贝一份出来修改
      cp zoo_sample.cfg zoo.cfg
      vim zoo.cfg
    5. 配置文件说明(主要修改data目录位置,日志目录位置,以及最后集群配置就可以,其他都可以默认)
      # The number of milliseconds of each tick
      # tickTime:CS通信心跳数
      # Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
      tickTime=2000
      
      # The number of ticks that the initial
      # synchronization phase can take
      # initLimit:LF初始通信时限
      # 集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
      initLimit=5
      
      # The number of ticks that can pass between
      # sending a request and getting an acknowledgement
      # syncLimit:LF同步通信时限
      # 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
      syncLimit=5
      
      # the directory where the snapshot is stored.
      # do not use /tmp for storage, /tmp here is just
      # example sakes.
      # dataDir:数据文件目录
      # Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
      dataDir=/usr/local/zookeeper/data
      
      # dataLogDir:日志文件目录
      # Zookeeper保存日志文件的目录。
      dataLogDir=/usr/local/zookeeper/logs
      
      # 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=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 保留数量3
      autopurge.snapRetainCount=3
      # Purge task interval in hours
      # Set to "0" to disable auto purge feature 清理时间间隔1小时
      autopurge.purgeInterval=1
      
      # 服务器名称与地址:集群信息(服务器编号,服务器地址,LF通信端口,选举端口)
      # 这个配置项的书写格式比较特殊,规则如下:
      # server.N=YYY:A:B
      # 其中N表示服务器编号,YYY表示服务器的IP地址,A为LF通信端口,表示该服务器与集群中的leader交换的信息的端口。B为选举端口,表示选举新leader时服务器间相互通信的端口(当leader挂掉时,其余服务器会相互通信,选择出新的leader)。一般来说,集群中每个服务器的A端口都是一样,每个服务器的B端口也是一样。但是当所采用的为伪集群时,IP地址都一样,只能时A端口和B端口不一样。

       server.1=192.168.1.1:2881:3881
       server.2=192.168.1.2:2881:3881
       server.3=192.168.1.3:2881:3881

    6. 进入data目录中创建文件
      cd /usr/local/zookeeper/data
      echo 1 > myid
    7. 拷贝zookeeper安装目录到其他服务器
      cd /usr/local
      scp -r zookeeper root@192.168.1.2:/usr/local
      scp -r zookeeper root@192.168.1.3:/usr/local
    8. 进入另外服务器修改data目录中创建的myid文件内容,数字随便,但是不能重复
    9. 到此以及配置成功,启动每台服务器中的zookeeper就可以了,进入bin目录中执行
      启动命令:./zkServer.sh start
      
      停止命令:./zkServer.sh stop  
      
      重启命令:./zkServer.sh restart
      
      状态查看命令:./zkServer.sh status
    10. 当查看状态出现follower或者leader时表明已经安装成功

  • 相关阅读:
    cnblog项目--20190309
    django js引入失效问题
    Python老男孩 day16 函数(六) 匿名函数
    Python老男孩 day16 函数(五) 函数的作用域
    Python老男孩 day15 函数(四) 递归
    Python老男孩 day15 函数(三) 前向引用之'函数即变量'
    Python老男孩 day15 函数(二) 局部变量与全局变量
    Python老男孩 day14 函数(一)
    Python老男孩 day14 字符串格式化
    Python老男孩 day14 集合
  • 原文地址:https://www.cnblogs.com/cui0614/p/14298682.html
Copyright © 2011-2022 走看看