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

    1.前言

      在前面的文章中讲了单机版zookeeper的搭建,现在在单机版的基础上搭建集群。默认单机版的搭建好了。我这里只有一台服务器,所以在单机上搭建的为集群

    2.将单机安装好的zookeeper复制三份

    apache-zookeeper-3.5为单机版安装好的,另外三份是复制的,且重命名.三个zookeeper的端口分别是2181、21822183

    3.修改zookeeper-2181的配置文件

      参数dataDir修改

        改成对应的路径dataDir=/usr/local/programs/zookeeper/zookeeper-2181/data

      参数clientPort修改:修改端口号

        clientPort=2181

      添加下列配置:

        #集群配置信息
        #server.A=B:C:D   
        #A:是一个数字,表示这个是服务器的编号   
        #B:是这个服务器的ip地址   
        #C:Zookeeper服务器之间的通信端口   
        #D:Leader选举的端口

        server.1=59.111.138.4.:2287:3387
        server.2=59.111.138.4:2288:3388
        server.3=59.111.138.4:2289:3389

        注意:由于我这里三个zookeeper在同一个服务器上面,所以ip是一样的,也可以写成0.0.0.0   

    # 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/programs/zookeeper/zookeeper-2181/data
    # the port at which the clients will connect
    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
    #autopurge.snapRetainCount=3
    # Purge task interval in hours
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1
    
    #集群配置信息
    #server.A=B:C:D    
    #A:是一个数字,表示这个是服务器的编号    
    #B:是这个服务器的ip地址    
    #C:Zookeeper服务器之间的通信端口    
    #D:Leader选举的端口 
    
    server.1=0.0.0.0:2287:3387
    server.2=0.0.0.0:2288:3388
    server.3=0.0.0.0:2289:3389

    4.myid文件

      在data文件夹下新建文件,文件名 myid,删除data下其他的文件

      在文件中加入数字1,这个1对应的是server.1=0.0.0.0:2287:3387中server.后面的数字1

      

    5. zookeeper-2182和2183重复上面3/4两步的操作

    6.到各个的bin目录下启动服务器

      ./zkServer.sh start 启动服务器

       ./zkServer.sh status 查看服务器状态

    7.启动可能出现的问题

      启动服务器后,./zkServer.sh status发现服务器没有起来

       查看log文件夹下的日志文件

       7.1可能遇到的问题1

        

        服务器实际是启动了,只是没有连接到另外两台,因为另外两台还没启动。

          解决方案:先不管服务器的状态,一个一个的把zookeeper启动(./zkServer.sh start),最后一个服务器启动了,等待一会儿,再查看这台服务器的状态(./zkServer.sh status),发现,最后一个正常启动了,再回去吧之前的服务器一个个的重新启动(./zkServer.sh restart),再查看状态,发现正常启动,问题解决

      7.2可能问题2:服务器防火墙,关闭即可

      7.3可能问题3:如果用的阿里云服务器,端口需要开放

       7.4可能问题4:

        

       8080端口占用,因为Zookeeper AdminServer,默认使用8080端口(这个被占用了可以先不处理)

    8.测试

      在2181出创建节点  你好

      

      在2182出去获取

      

       获取到了,成功

    9.observer角色及其配置
      observer角色特点:
        1.不参与集群的leader选举
        2. 不参与集群中写数据时的ack反馈
        为了使用observer角色,在任何想变成observer角色的配置文件中加入如下配置:
            
    peerType=observer
        并在所有server的配置文件中,配置成observer模式的server的那行配置追加:observer,例如:
    server.3=192.168.60.130:2289:3389:observer

      

  • 相关阅读:
    Hibernate保存方式的区别
    活动图
    Apache新增站点配置
    Apache安装
    360度全方位沟通向上沟通
    时间转换
    PostgreSQL 9.2中将引入生成JSON数据功能
    Delphi 读取dbgrid中的选中一行的代码及定位函数
    彻底解决Delphi的DBGrid控件鼠标滚轮问题(转)
    DB2与PostgreSQL开发的异同
  • 原文地址:https://www.cnblogs.com/jthr/p/14649128.html
Copyright © 2011-2022 走看看