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

    一、预备工作

          1、zookeepeer需要安装JDK,至于版本,大家可以去官网查询一下。这里我安装的是JDK8。

          2、需要开放zookeepeer用到的端口,默认端口2181、2888、3888,至于开放的方法,可以通过关闭防火墙,也可以通过添加IP例外。

               a、 关闭防火墙的方法为:chkconfig iptables off,然后重启。

               b、为IP添加例外,可以使用:iptables -I INPUT 1 -p tcp --dport 2181-j ACCEPT

                     查看例外列表:iptables --list

    二、下载并安装

          1、官网地址:https://www.apache.org/dyn/closer.cgi/zookeeper/ 这里有很多镜像的地址,你可以选择一个比较近的,我选的是清华的

          2、解压&安装:

          tar zxvf zookeeper-3.4.8.tar.gz -C /usr/app

          cd /usr/app

          mv zookeeper-3.4.8 zookeepeer

          cd zookeepeer

          cp conf/zoo_sample.cfg conf/zoo.cfg//这里用的zookeepeer的示例配置,在这个基础上修改

    三、配置zookeeper

     1 [root@sxl132 conf]# cat zoo.cfg
     2 # The number of milliseconds of each tick
     3 tickTime=2000  //心跳时间间隔,有关时间的设置均以这个时间为最小单位,单位是毫秒,这里是2000毫秒
     4 # The number of ticks that the initial 
     5 # synchronization phase can take
     6 initLimit=10  //集群中的fllower服务器与leader服务器之间,初始连接时能容忍的最多心跳数,这里则是:在初始化连接时,如果超过10个心跳时,对方未答应,则连接失败
     7 # The number of ticks that can pass between 
     8 # sending a request and getting an acknowledgement
     9 syncLimit=5   //fllower服务器与leader服务器之间,请求和应答能容忍的最多心跳数,超过这个心跳,则会丢充这个fllower。所以连接到这个fllower的client,则会连接到其他的fllower
    10 # the directory where the snapshot is stored.
    11 # do not use /tmp for storage, /tmp here is just 
    12 # example sakes.
    13 dataDir=/usr/data/zookeepeer //zookeepeer的数据目录
    14 # the port at which the clients will connect
    15 clientPort=2181 //连接到此台zookeepeer的client所使用的端口
    16 # the maximum number of client connections.
    17 # increase this if you need to handle more clients
    18 #maxClientCnxns=60
    19 #
    20 # Be sure to read the maintenance section of the 
    21 # administrator guide before turning on autopurge.
    22 #
    23 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    24 #
    25 # The number of snapshots to retain in dataDir
    26 #autopurge.snapRetainCount=3
    27 # Purge task interval in hours
    28 # Set to "0" to disable auto purge feature
    29 #autopurge.purgeInterval=1
    30 server.2=192.168.116.142:2888:3888 //数据格式为server.myid=IP:PORT1:PORT2,每一行代表zookeepeer集群中的一台服务器
    31 server.3=192.168.116.143:2888:3888 //其中myid为数字,标志着zookeepeer服务器在这个集群中的惟一标志,IP为服务器的IP地址
    32 server.4=192.168.116.144:2888:3888 //PORT1:用来进行集群成员间信息交换,表示这个服务器与集群中的leader服务器交换信息的端口;PORT2:在leader挂掉时专门用来进行选举leader所用的端口

          创建myid标志:

          首先,myid在这里是一个文件,文件中的内容很单纯,只有当前服务器的myid内容,而且一定要与zookeepeer配置中的myid一一对应;

          其次,myid的位置一定要在zookeepeer的数据目录下,前面我们配置的数据目录为:/usr/data/zookeepeer

          如:

    1 [root@sxl132 zookeepeer]# cat myid
    2 2

    四、启动zookeepeer并查看fllower&leader

          启动zookeepeer:      

    1 [root@sxl132 zookeepeer]# ./bin/zkServer.sh start
    2 ZooKeeper JMX enabled by default
    3 Using config: /usr/app/zookeepeer/bin/../conf/zoo.cfg
    4 Starting zookeeper ... STARTED

        3台服务器都依次启动。

        查看fllower&leader。

        下面提leader:

    [root@sxl132 zookeepeer]# ./bin/zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /usr/app/zookeepeer/bin/../conf/zoo.cfg
    Mode: leader

          下面是fllower:      

    1 [root@sxl133 bin]# zkServer.sh status
    2 ZooKeeper JMX enabled by default
    3 Using config: /usr/app/zookeepeer/bin/../conf/zoo.cfg
    4 Mode: follower

          到此,说明我们的zookeepeer集群搭建成功了。

    参考文档

    https://www.cnblogs.com/linuxprobe/p/5851699.html

    https://www.cnblogs.com/tonylovett/p/5227973.html

    http://blog.csdn.net/gobitan/article/details/8659175

  • 相关阅读:
    完美解决php无法上传大文件代码
    完美解决php无法上传大文件源代码
    完美解决php无法上传大文件源码
    IfcCartesianTransformationOperator3D
    IfcCartesianTransformationOperator3DnonUniform
    IfcCartesianTransformationOperator2D
    IfcCartesianTransformationOperator2DnonUniform
    IfcCartesianTransformationOperator
    IfcCartesianPointList3D
    IfcCartesianPointList2D
  • 原文地址:https://www.cnblogs.com/gudi/p/8053741.html
Copyright © 2011-2022 走看看