zoukankan      html  css  js  c++  java
  • linux 安装配置kafka脚本

    安装脚本

    #!/bin/bash
    # auto install kafka
    echo "========= Start to install kafka =============="
    function install_kafka(){
        if [ -f "./kafka_2.12-2.0.0.gz" ];then
            echo "Start installing kafka"
    
            isopen9=$(firewall-cmd --query-port=9092/tcp)
            isopen2=$(firewall-cmd --query-port=2181/tcp)
    
            if [ 'no' == $isopen9 ];then
             echo "open 9092"
              addresult=$(firewall-cmd --add-port=9092/tcp --permanent)
             reloadresult=$(firewall-cmd --reload)
            else
                echo "port 9092 already opened"
            fi
    
            if [ 'no' == $isopen2 ];then
             echo "open 2181"
             addresult=$(firewall-cmd --add-port=2181/tcp --permanent)
             reloadresult=$(firewall-cmd --reload)
            else
                echo "port 2181 already opened"
            fi
        
            mkdir -p /opt/ops/kafka/logs
            kafkahome=/opt/ops/kafka
    
            tar -zxf kafka_2.12-2.0.0.gz -C $kafkahome
    
            localip=$(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
            #sed -i "s#host.name=#host.name=$localip#g" $kafkahome/kafka_2.12-2.0.0/config/server.properties
            sed -i "s@#advertised.*@advertised.listeners = PLAINTEXT://$localip:9092@g" $kafkahome/kafka_2.12-2.0.0/config/server.properties
            sed -i "s@log.dirs=/tmp/kafka-logs@log.dirs=$kafkahome/logs@g" $kafkahome/kafka_2.12-2.0.0/config/server.properties
            sed -i "s@num.partitions=1@num.partitions=10@g" $kafkahome/kafka_2.12-2.0.0/config/server.properties
            sed -i "s@zookeeper.connect=localhost:2181@zookeeper.connect=$localip:2181@g" $kafkahome/kafka_2.12-2.0.0/config/server.properties
        
        else
         echo "Failed to install kafka"
         echo "Missing 'kafka_2.12-2.0.0.gz' file in statistical catalogue"
        fi
    }
    
    if [ -d "/opt/ops/kafka" ];then
        echo "Kafka has been installed"
    else
        install_kafka
    fi
    echo "========= End installation of kafka ==========="

    创建topic脚本

    #!/bin/bash
    # create topic
    topic='vehiclepass'
    cd /opt/ops/kafka/kafka_2.12-2.0.0/bin
    zk_ip=$(cat /opt/ops/kafka/kafka_2.12-2.0.0/config/server.properties | grep zookeeper.connect= | awk -F'=' '{ print $2 }' | sed s/[[:space:]]//g)
    partitions_num=$(cat /opt/ops/kafka/kafka_2.12-2.0.0/config/server.properties | grep num.partitions= | awk -F'=' '{ print $2 }' | sed s/[[:space:]]//g)
    ./kafka-topics.sh --create --zookeeper $zk_ip --topic $topic --partitions $partitions_num --replication-factor 1
  • 相关阅读:
    tornado硬件管理系统-数据存储与表格实时监控(8)
    db2 内存研究
    Oracle dml开始到commit期间的流程
    用户界面与业务逻辑的分离
    计算器核心算法——终结版
    计算器核心算法——中缀表达式转为后缀表达式
    计算器核心解析算法(上)
    Qt中的字符串类
    初探Qt中的消息处理
    计算器界面代码重构
  • 原文地址:https://www.cnblogs.com/donfaquir/p/10540812.html
Copyright © 2011-2022 走看看