• CentOS7下安装配置zookeeper集群


    CentOS7下安装配置zookeeper集群

    1、搭建zookeeper集群之前需要有至少三台机器或虚拟机,这里采用centos7.2系统

    2、去zookeeper官网下载对应的压缩包,我下载的是目前最新的zookeeper-3.5.2-alpha.tar.gz,将该压缩包放到usr目       录下,用

          tar -zxf zookeeper-3.5.2-alpha.tar.gz  

          命令将该压缩包解压到当前目录下

    3、在解压后的目录下新建两个新目录,分别是data和log,等下在下一步中需要用到

    4、将解压后的目录下的conf目录中的zoo_sample.cfg 复制一份,并命名为zoo.cfg,将该配置文件的内容修改成如下      的样子

    # 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/zookeeper-3.5.2-alpha/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
    
    
    dataLogDir=/usr/zookeeper-3.5.2-alpha/log
    server.1=192.168.202.66:2888:3888
    server.2=192.168.202.67:2888:3888
    server.3=192.168.202.68:2888:3888
    
    
    # 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


    5、在第3步中新建的data目录中新建名为myid的文件,文件内容是上面配置文件中server.x的x,也即是1、2、3这样       的一个数字,这个文件3台机器里面都需要新建,所以需要根据配置上的内容分别存入1  2  3 ,不能弄错了

    6、将zookeeper加入到path路径中,在/etc/profile中加入

    export PATH=$PATH:/usr/zookeeper-3.5.2-alpha/bin

       再用 

       source /etc/profile

       刷新配置文件

          这样就可以在任何位置使用zookeeper的命名

    7、到目前为止需要做的事情已经做好了,可以来分别启动3台机器中的zookeeper了,用如下命令来启动

        1)如果没有配置第6步的内容,则需要进去到zookeeper目录下的bin目录中 ,用

           ./zkServer.sh start

          来启动zookeeper

        2)如果配置了第6步的内容,则可以在任何位置使用

           zkServer.sh start

           来启动zookeeper

    8、启动zookeeper之后,可以进去到zookeeper的logs目录下,用

       tail -f zookeeper-root-server-localhost.localdomain.out

       来查看日志,zookeeper-root-server-localhost.localdomain.out是logs目录的输出日志文件,不知道各个版本的        zookeeper是不是都叫这个名字。

    9、最后可以使用 zkServer.sh status 命令来查看zookeeper服务的状态,如果现实如下内容,则说明zookeeper已经        启动成功

    ZooKeeper JMX enabled by default
    Using config: /usr/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost.
    Mode: follower

    或者

    ZooKeeper JMX enabled by default
    Using config: /usr/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost.
    Mode: leader

    10、如果在启动zookeeper后发现输出的日志中有报错,那么可能有这么两个原因

         1)可能是防火墙没关,或者没有将zookeeper的需要用到的相关的端口号从防火墙中排出,可以使用下面的命令              来关闭防火墙

               

    systemctl status firewalld.service  #检查防火墙状态
    
    systemctl stop firewalld.service  #关闭防火墙
    
    systemctl disable firewalld.service  #禁止开机启动防火墙

       2)如果关闭了防火墙之后还出错的话,可能只是其他两台机器中的zookeeper还没启动成功导致的,所以把所有3           台机器中的zookeeper都启动之后再看,如果没有其他问题刚才的报错信息在之后就不会报了

    11.关闭zookeeper

    zkServer.sh stop

    12.配置zookeeper开机启动

    1)进入到/etc/init.d目录下,新建一个zookeeper脚本

    cd /etc/init.d

    vi zookeeper

    #!/bin/bash
    #chkconfig:2345 20 90
    #description:zookeeper    
    #processname:zookeeper
    export JAVA_HOME=/usr/java/jdk1.8.0_181
    case $1 in
            start) su root /root/tengjs/zookeeper-3.4.12/bin/zkServer.sh start;;
            stop) su root /root/tengjs/zookeeper-3.4.12/bin/zkServer.sh stop;;
            status) su root /root/tengjs/zookeeper-3.4.12/bin/zkServer.sh status;;
            restart) su root /root/tengjs/zookeeper-3.4.12/bin/zkServer.sh restart;;
            *) echo "require start|stop|status|restart" ;;
    esac
    2)给脚本添加执行权限

    chmod +x zookeeper

    3)用service zookeeper start/stop命令来尝试启动关闭zookeeper,使用service zookeeper status查看zookeeper状态

    4)添加开机启动

    chkconfig --add zookeeper

    5)查看开机自启的服务中是否已经有我们的zookeeper

    chkconfig --list zookeeper

    ok,重启服务器,然后用zkServer.sh status,或者service zookeeper status可以看到zookeeper当前处于启动状态
     

       

  • 相关阅读:
    返回一个整数数组中子数组的最大值
    软工概论第二周个人项目四则运算二(改进)
    构建之法阅读笔记01
    单例模式
    .net基础加强
    使用jquery easy ui
    抽象工厂类
    System.Linq.Expressions.Expression
    创建上下文对象
    DBSesson
  • 原文地址:https://www.cnblogs.com/erlou96/p/16878530.html
Copyright © 2020-2023  润新知