Kafka 集群安装脚本

最近又在搞Kafka集群,安装kafka集群感觉太麻烦,所以就写了一个简单的kafka 集群安装脚本,但是有个前提,各个机器的 ssh 免密要配置好,然后jdk 要安装成功。

kafka 安装分两步,一是安装 zookkper ,二是安装配置集群。

注意:
* 各个机器的 ssh 免密要配置好,jdk 要安装成功。
* 如果安装在本机,那么本机也要配置ssh自免密。
* 脚本要和安装包在同一个目录。

zookeeper 安装脚本

ROOT:为安装的根目录
USER :为安装的用户
ZOOKEEPER_NAME:为安装包的名字

#!bin/sh

ROOT=/usr/cpic/testapps
USER=cpic

ZOOKEEPER_NAME=zookeeper-3.4.10
ZOOKEEPER_TAR=$ZOOKEEPER_NAME.tar.gz

NODES="192.168.100.90"

function install_zookeeper()
{
    for i in $NODES
    do  
        ssh -oStrictHostKeyChecking=no $USER@${i} mkdir -p $ROOT/$ZOOKEEPER_NAME
        scp -rp $ZOOKEEPER_NAME $USER@${i}:$ROOT
        ssh $USER@${i} "cd $ROOT/$ZOOKEEPER_NAME/conf;cp zoo_sample.cfg zoo.cfg";
    done
    echo "success install $ZOOKEEPER_NAME";
exit 0  
}

# 判断zookeeper tar.gz  包是否存在,存在则安装
if [ -f "$ZOOKEEPER_TAR" ]; then
     echo "开始解压 $ZOOKEEPER_TAR 。。。。";
     tar -zxvf $ZOOKEEPER_TAR;
     echo "开始安装zookeeper 。。。。";
     install_zookeeper;
else
    echo "$ZOOKEEPER_TAR 在当前目录下不存在";
fi

Kafka安装脚本

ROOT:为安装的根目录
USER :为安装的用户
KAFKA_NAME:为安装包的名字

#!bin/sh

DIR=/usr/cpic/testapps
ZOOKEEPER_HOST_PORT=192.168.100.90:2181
PARTITIONS_NUM=3
BROKER_ID=0
USER=cpic

KAFKA_NAME=kafka_2.11-0.10.1.0
KAFKA_TAR=$KAFKA_NAME.tgz



BROKERS="192.168.100.91 192.168.100.92 192.168.100.93"


function install_kafka()
{
    for i in $BROKERS
    do
        ssh -oStrictHostKeyChecking=no $USER@${i} mkdir -p $DIR/data/kaka-logs
        scp -rp $KAFKA_NAME $USER@${i}:$DIR
        echo modify @${i} server.properties 
        ssh $USER@${i} "cd $DIR/$KAFKA_NAME/config;sed -i 's?^log.dirs=?#log.dirs=?' server.properties ;sed -i  's?^zookeeper.connect=?#zookeeper.connect=?' server.properties ;sed -i  's?^num.partitions=?#num.partitions=?' server.properties;sed -i  's?^broker.id=?#broker.id=?' server.properties ;echo “” >> server.properties;echo "broker.id=$BROKER_ID" >> server.properties;echo "log.dirs=$DIR/kafka-logs" >> server.properties;echo "zookeeper.connect=$ZOOKEEPER_HOST_PORT" >> server.properties;echo "num.partitions=$PARTITIONS_NUM" >> server.properties ;echo "port=9092" >> server.properties ;echo "host.name=${i}" >> server.properties;"
        let BROKER_ID+=1;
    done
    echo success modify all server.properties 
exit 0  
}

# 判断kafka tar.gz  包是否存在,存在则安装
if [ -f "$KAFKA_TAR" ]; then
     echo "开始解压 $KAFKA_NAME.tgz 。。。。"
     tar -zxvf $KAFKA_TAR;
     echo "开始安装Kafka 。。。。";
     install_kafka;
 else
    echo "$KAFKA_TAR 在当前目录下不存在";
fi

关于Kafka 的集群启动停止 请看:Kafka 集群启停脚本

你可能感兴趣的:(5.2,kafka,Kafka,集群)