zoukankan      html  css  js  c++  java
  • Kafka集群启停脚本参考

    对kafka-server-start.sh脚本和kafka-server-stop.sh脚本进行二次封装

    #! /bin/bash
    
    # Kafka代理节点地址, 如果节点较多可以用一个文件来存储
    hosts=(dn1 dn2 dn3)
    
    # 打印启动分布式脚本信息
    mill=`date "+%N"`
    tdate=`date "+%Y-%m-%d %H:%M:%S,${mill:0:3}"`
    
    echo [$tdate] INFO [Kafka Cluster] begins to execute the $1 operation.
    
    # 执行分布式开启命令    
    function start()
    {
        for i in ${hosts[@]}
            do
                smill=`date "+%N"`
                stdate=`date "+%Y-%m-%d %H:%M:%S,${smill:0:3}"`
                ssh hadoop@$i "source /etc/profile;echo [$stdate] INFO [Kafka Broker $i] begins to execute the startup operation.;kafka-server-start.sh $KAFKA_HOME/config/server.properties>/dev/null" &
                sleep 1
            done
    }    
    
    # 执行分布式关闭命令    
    function stop()
    {
        for i in ${hosts[@]}
            do
                smill=`date "+%N"`
                stdate=`date "+%Y-%m-%d %H:%M:%S,${smill:0:3}"`
                ssh hadoop@$i "source /etc/profile;echo [$stdate] INFO [Kafka Broker $i] begins to execute the shutdown operation.;kafka-server-stop.sh>/dev/null;" &
                sleep 1
            done
    }
    
    # 查看Kafka代理节点状态
    function status()
    {
        for i in ${hosts[@]}
            do
                smill=`date "+%N"`
                stdate=`date "+%Y-%m-%d %H:%M:%S,${smill:0:3}"`
                ssh hadoop@$i "source /etc/profile;echo [$stdate] INFO [Kafka Broker $i] status message is :;jps | grep Kafka;" &
                sleep 1
            done
    }
    
    # 判断输入的Kafka命令参数是否有效
    case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        status)
            status
            ;;
        *)
            echo "Usage: $0 {start|stop|status}"
            RETVAL=1
    esac

    参考:https://www.cnblogs.com/smartloli/p/9984140.html

  • 相关阅读:
    LWIP的底层结构(物理层)
    Source insight 支持汇编
    Camera Vision
    i2c-tools的使用方法及举例
    浅析C语言中strtol()函数与strtoul()函数的用法
    CF540C Ice Cave
    CF540B School Marks
    hdu5122 K.Bro Sorting
    hdu1013 Digital Roots
    蓝桥杯 算法提高 递推求值
  • 原文地址:https://www.cnblogs.com/-courage/p/14690950.html
Copyright © 2011-2022 走看看