• 【zookeeper】linux中编写脚本批量启动zookeeper


    实现功能:一键启动、关闭主从端3个节点上的zookeeper,附加查看启动状态

    mkdir bin --新建文件夹
    cd bin 跳转到bin文件夹里
    touch  zookeeperstart.sh --新建一键启动文件
    touch  zookeeperstop.sh --新建一键停止文件

    zookeeperstart.sh添加内容:

    #!/bin/bash
    ZOOKEEPER_HOME=/home/hadoop/apache-zookeeper-3.5.5
     
    if [ $ZOOKEEPER_HOME != ""  ]; then
            ZOOCFG=$ZOOKEEPER_HOME/conf/zoo.cfg
            for s in 01 02 03 --循环启动
                    do
                            echo "INFO:starting zookeeper on ${s}"
                            ssh hadoop$s "source /etc/profile;$ZOOKEEPER_HOME/bin/zkServer.sh start" --利用ssh登陆对应的节点,执行当前对应启动命令
                            if [ $? != 0 ];
                                    then
                                    echo "Can not starting zookeeper server on host $s}"
                                    exit 1
                            fi
                    done
            for s in 01 02 03 --循环查看zookeeper状态
                    do
                            echo "INFO:starting zookeeper on ${s}"
                            ssh hadoop$s "source /etc/profile;$ZOOKEEPER_HOME/bin/zkServer.sh status" --显示各节点zookeeper的启动状态
                            if [ $? != 0 ];
                                    then
                                    echo "Can not starting zookeeper server on host $s}"
                                    exit 1
                            fi
                    done
    fi



    zookeeperstopsh添加内容:

    #!/bin/bash
    ZOOKEEPER_HOME=/home/hadoop/apache-zookeeper-3.5.5
    if [ $ZOOKEEPER_HOME != ""  ]; then
            ZOOCFG=$ZOOKEEPER_HOME/conf/zoo.cfg
            for s in 01 02 03
                    do
                            echo "INFO:starting zookeeper on ${s}"
                            ssh hadoop$s "source /etc/profile;$ZOOKEEPER_HOME/bin/zkServer.sh stop"
                            if [ $? != 0 ];
                                    then
                                    echo "Can not starting zookeeper server on host $s}"
                                    exit 1
                            fi
                    done
    fi


    启动脚本:

    sh zookeeperstart.sh
    sh zookeeperstop.sh

    例:以我的linux虚拟机上配置zookeeper为例

    [hadoop@hadoop01 bin]$ sh zookeeperstop.sh
    INFO:starting zookeeper on 01
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Stopping zookeeper ... STOPPED
    INFO:starting zookeeper on 02
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Stopping zookeeper ... STOPPED
    INFO:starting zookeeper on 03
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Stopping zookeeper ... STOPPED
    [hadoop@hadoop01 bin]$ sh zookeeperstart.sh
    INFO:starting zookeeper on 01
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    INFO:starting zookeeper on 02
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    INFO:starting zookeeper on 03
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    INFO:starting zookeeper on 01
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost.
    Mode: follower
    INFO:starting zookeeper on 02
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost.
    Mode: leader
    INFO:starting zookeeper on 03
    /usr/bin/java
    ZooKeeper JMX enabled by default
    Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
    Client port found: 2181. Client address: localhost.
    Mode: follower

    最后,我们可以看见,系统给出的信息表明,有两个follower,一个leader,这是zookeeper的工作原理



  • 相关阅读:
    ActiveMQ_Linux安装(一)
    Jenkins_多项目构建(二):使用Maven聚集关系
    Shell命令_for
    C# 读取Excel
    [ORACLE错误]ORA-00001: unique constraint (...) violated并不一定是数据冲突
    [ORACLE错误]ORA-00054:resource busy and acquire with nowait specified解决方法
    [ORACLE错误]oracle 不能更新 PL/SQL 点击“edit data”报“ these query results are not updateable”
    只有 DBA 才能导入由其他 DBA 导出的文件
    Windows系统安装Oracle 11g客户端
    Windows系统安装Oracle 11g数据库
  • 原文地址:https://www.cnblogs.com/CQ-LQJ/p/11605603.html
Copyright © 2020-2023  润新知