• 8.3.ZooKeeper集群安装配置


    1.Zookeeper的搭建方式

    Zookeeper安装方式有三种,单机模式集群模式以及伪集群模式

      单机模式:Zookeeper只运行在一台服务器上,适合测试环境;

      伪集群模式:就是在一台物理机上运行多个Zookeeper 实例;

      集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble)

      Zookeeper通过复制来实现高可用性,只要集合体中半数以上的机器处于可用状态,它就能够保证服务继续(zookeeper集群机制

      Zookeeper集群机制:半数机制:集群中半数以上机器存活,集群可用

    2.ZooKeeper服务器集群搭建

      Zookeeper 集群搭建指的是 ZooKeeper 分布式模式安装。通常由 2n+1台 servers 组成。这是因为为了保证 Leader 选举(基于 Paxos 算法

    的实现)能过得到多数的支持,所以 ZooKeeper 集群的数量一般为奇数。

      Zookeeper 运行需要 java 环境,所以需要提前安装 jdk。对于安装leader+follower 模式的集群,大致过程如下:

      

    卸载系统自带的OpenJDK:查看(rpm -qa|grep java)    卸载(rpm -e --nodeps xxxxxxxxx),然后安装sun公司的 JDK,然后修改环境变量/etc/profile,

    并source /etc/profile加载配置文件

    搭建要求:

      (1) zk服务器集群规模不小于3个节点

      (2) 要求各服务器之间系统时间要保持一致:date -s命令

          (3) 关闭防火墙:service iptables stop

      1.解压缩zookeeper到指定目录: tar -zxvf  zookeeper-3.4.5.tar.gz  -C /usr/local/src

      2.重命名:解压后将文件夹,重命名为zookeeper: mv zookeeper-3.4.5 zookeeper

      3.修改环境变量:vi /etc/profile

    export ZOOKEEPER_HOME=/usr/local/src/zookeeper
    export PATH=$PATH:$ZOOKEEPER_HOME/bin

      4.重新编译文件:source /etc/profile

      5.修改配置文件:将 /usr/local/src/zookeeper/conf/目录下的zoo_sample.cfg,重命名为zoo.cfg:mv zoo_sample.cfg zoo.cfg

      6.在/usr/local/zk/conf目录下,修改文件 vi zoo.cfg,创建data、log目录,并添加如下内容

    # The number of milliseconds of each tick
    tickTime=2000
    # The number of ticks that the initial
    # synchronization phase can take
    initLimit=10
    # The number of ticks that can pass between
    # sending a request and getting an acknowledgement
    syncLimit=5
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just
    # example sakes.
    dataDir=/usr/local/src/zookeeper/data  #文件存放目录,默认设置/tmp/zookeeper临时存放目录,每次重启后会丢失,在这我们自己设一个目录,/usr/local/src/zookeeper/data
    # the port at which the clients will connect
    clientPort=2181
    #
    # 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
    #autopurge.snapRetainCount=3
    # Purge task interval in hours
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1

     添加内容:

    dataDir=/usr/local/src/zookeeper/data    #zookeeper数据存放目录
    dataLogDir=/usr/local/src/zookeeper/log server.1=shizhan2:2888:3888 (主机名, 心跳端口、选举端口) 201 server.2=shizhan3:2888:3888 205 server.3=shizhan5:2888:3888 207

      7.在data目录下创建myid:创建文件myid:touch myid,存放服务器ID

      8.将集群下发到其他机器上:基于 SSH 协议在网络之间进行安全传输的命令

    scp -r  /usr/local/src/zookeeper root@192.168.232.205:/usr/local/src/ ---(shizhan3:)
    
    scp -r  /usr/local/src/zookeeper root@192.168.232.201:/usr/local/src/ --- (shizhan2)

      9.修改myid:和server服务器ID保持一致

    到shizhan2上:修改myid为:1shizhan3上:修改myid为:2shizhan5上:修改myid为:3

      10.启动每台机器:zkServer.sh start

      11.查看集群状态,主从信息zkServer.sh status

        

      

      

      Zookeeper集群的角色:Leader 和 follower 

     

  • 相关阅读:
    【HDU3681】Prison Break-状态压缩DP+BFS+二分答案
    【BashuOJ3520】警察局长-最短路树+树上背包+概率DP
    【POJ1201】Intervals-差分约束系统+单源最长路
    【BashuOJ2041】最大矩形-矩阵型DP
    【BashuOJ2041】最大矩形-矩阵型DP
    deleted
    deleted
    deleted
    deleted
    deleted
  • 原文地址:https://www.cnblogs.com/yaboya/p/9134799.html
Copyright © 2020-2023  润新知