zoukankan      html  css  js  c++  java
  • kafka 自启脚本

    每次使用的时候都要手动去启动真头痛!

    解决办法,自启吧!

    方法一:

    方法一: /etc/rc.local中添加 

    文件地址记得替换掉 ,我没使用这种,发现不是每次都行,就换了第二种方法

    /usr/local/kafka_2.11-0.9.0.1/bin/kafka-server-start.sh  /usr/local/kafka_2.11-0.9.0.1/config/server.properties

    cd /etc/rc.d/init.d

    touch kafka 

    chmod +x kafka  

    #!/bin/bash  
    #chkconfig:2345 30 80  
    #description:kafka  
    #processname:kafka  
    case $1 in  
     start) su root /usr/local/kafka_2.11-0.9.0.1/bin/kafka-server-start.sh  /usr/local/kafka_2.11-0.9.0.1/config/server.properties;;  
     stop) su root /usr/local/kafka_2.11-0.9.0.1/bin/kafka-server-stop.sh  /usr/local/kafka_2.11-0.9.0.1/config/server.properties;;  
     *)  echo "require start|stop"  ;;  
    esac 

    chkconfig --add kafka   添加到服务器中

    chkconfig kafka on 设置开机自动启动

    至此完事了,附上官方的脚本一份 ,都可以使用

    #!/bin/sh
    #
    # chkconfig: 345 99 01
    # description: Kafka
    #
    # File : Kafka
    #
    # Description: Starts and stops the Kafka server
    #
    
    source /etc/rc.d/init.d/functions
    
    KAFKA_HOME=/opt/kafka
    KAFKA_USER=kafka
    export LOG_DIR=/var/log/kafka
    
    [ -e /etc/sysconfig/kafka ] && . /etc/sysconfig/kafka
    
    # See how we were called.
    case "$1" in
    
      start)
        echo -n "Starting Kafka:"
        /sbin/runuser -s /bin/sh $KAFKA_USER -c "nohup $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties > $LOG_DIR/server.out 2> $LOG_DIR/server.err &"
        echo " done."
        exit 0
        ;;
    
      stop)
        echo -n "Stopping Kafka: "
        /sbin/runuser -s /bin/sh $KAFKA_USER  -c "ps -ef | grep kafka.Kafka | grep -v grep | awk '{print $2}' | xargs kill"
        echo " done."
        exit 0
        ;;
      hardstop)
        echo -n "Stopping (hard) Kafka: "
        /sbin/runuser -s /bin/sh $KAFKA_USER  -c "ps -ef | grep kafka.Kafka | grep -v grep | awk '{print $2}' | xargs kill -9"
        echo " done."
        exit 0
        ;;
    
      status)
        c_pid=`ps -ef | grep kafka.Kafka | grep -v grep | awk '{print $2}'`
        if [ "$c_pid" = "" ] ; then
          echo "Stopped"
          exit 3
        else
          echo "Running $c_pid"
          exit 0
        fi
        ;;
    
      restart)
        stop
        start
        ;;
    
      *)
        echo "Usage: kafka {start|stop|hardstop|status|restart}"
        exit 1
        ;;
    
    esac
  • 相关阅读:
    关于Git的一些常规操作
    .Net 常用ORM框架对比:EF Core、FreeSql、SqlSuger (下篇)
    Myeclipse打开许多JSP文件或者js文件之后非常卡-------的解决办法
    单点登录常用生成token的操作-----UUID.randomUUID().toString() 简介
    如何使用时间复杂度和空间复杂度来区分算法的效率?
    自定义注解的简单使用
    企业中常用的Git和Svn比较。
    框架中常见的注解分析
    处理大数据流常用的三种Apache框架:Storm、Spark和Samza。(主要介绍Storm)
    养生食谱
  • 原文地址:https://www.cnblogs.com/java-synchronized/p/8315400.html
Copyright © 2011-2022 走看看