• 【4】Kafka集群启动/关闭脚本


    说明:本脚本基于SSH服务器免密登录,如集群未配置SSH,参照:《SSH安装配置》 。

    一、启动脚本:start-kafka-cluster.sh

    #!/bin/bash
    brokers="server1 server2 server3"
    KAFKA_HOME="/usr/local/services/kafka/kafka_2.11-2.3.0"
    KAFKA_NAME="kafka_2.11-2.3.0"
    
    echo "INFO : Begin to start kafka cluster ..."
    
    for broker in $brokers
    do
      echo "INFO : Starting ${KAFKA_NAME} on ${broker} ..."
      ssh ${broker} -C "source /etc/profile; sh ${KAFKA_HOME}/bin/kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties"
      if [[ $? -eq 0 ]]; then
          echo "INFO:[${broker}] Start successfully"
      fi
    done
    echo "INFO:Kafka cluster starts successfully !"
    

    为脚本添加执行权限:

    chmod a+x start-kafka-cluster.sh
    

    二、停止脚本:stop-kafka-cluster.sh

    #!/bin/bash
    brokers="server1 server2 server3"
    KAFKA_HOME="/usr/local/services/kafka/kafka_2.11-2.3.0"
    KAFKA_NAME="kafka_2.11-2.3.0"
    
    echo "INFO : Begin to stop kafka cluster ..."
    
    for broker in $brokers
    do
      echo "INFO : Shut down ${KAFKA_NAME} on ${broker} ..."
      ssh ${broker} "source /etc/profile;bash ${KAFKA_HOME}/bin/kafka-server-stop.sh"
      if [[ $? -ne 0 ]]; then
          echo "INFO : Shut down ${KAFKA_NAME} on ${broker} is down"
      fi
    done
    
    echo "INFO : kafka cluster shut down completed!"
    

    为脚本添加执行权限:

    chmod a+x stop-kafka-cluster.sh
    

    参考资料

    参考书籍:Kafka入门与实践

  • 作者: DeepInThought
    出处: https://www.cnblogs.com/DeepInThought
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    SQL查询,点击三维图层,查询属性信息
    title标签的使用
    idea快捷键大全
    intellij idea创建第一个动态web项目
    IDEA设置为黑色背景(今天开始使用idea,并记录点滴,记录坑)
    Eclipse导出Jar包(包含外部包)
    获取当前系统时间
    JS实现的ajax和同源策略
    缓存
    Restful Framework (四)
  • 原文地址:https://www.cnblogs.com/DeepInThought/p/11143981.html
  • Copyright © 2020-2023  润新知