kafka集群启动脚本

1: 在 /usr/local/bin 目录下touch xkafka.sh

2:脚本编写

#!/bin/bash

#判断用户是否传参
if [ $# -ne 1 ];then
    echo "无效参数,用法为: $0  {start|stop}"
    exit
fi

#获取用户输入的命令
cmd=$1

for (( i=101 ; i<=103 ; i++ )) ;do
    tput setaf 2
    echo ========== hadoop${i}  $cmd ================
    tput setaf 9
    case $cmd in
        start)
            ssh  hadoop${i} "source /etc/profile ; nohup /opt/module/kafka/bin/kafka-server-start.sh  /opt/module/kafka/config/server.properties >> /opt/module/kafka/console-logs/kafka-`date +%F`.log &" 
            #ssh  hadoop${i}  "source /etc/profile ; /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/bin/config/server.properties"
            echo  hadoop${i}  "服务已启动"
            ;;
        stop) 
            ssh hadoop${i}  "source /etc/profile ; /opt/module/kafka/bin/kafka-server-stop.sh" 
            echo hadoop${i}  "服务已停止"
            ;;
            *) 
            echo "无效参数,用法为: $0  {start|stop}"
            exit 
            ;;
     esac
done

或者

#!/bin/sh

case $1 in
"start"){

        for i in hadoop101 hadoop102 hadoop103
        do
                echo "******** $i --> kafka-server-start.sh **********"
                ssh $i 'source /etc/profile;sh /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties'
        done

};;

"stop"){

        for i in hadoop101 hadoop102 hadoop103
        do
                echo "******** $i --> kafka-server-stop.sh **********"
                ssh $i 'source /etc/profile; /opt/module/kafka/bin/kafka-server-stop.sh /opt/module/kafka/config/server.properties;exit'
        done

};;
esac

3:授予权限

chmod 777 xkafka.sh

4:添加软链接

ln -s /usr/local/bin/xkafka.sh kk

5:测试

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值