kafka一键启动脚本配置

创建onekey目录

mkdir /export/server/onekey

创建zk目录

mkdir /export/server/onekey/kafka

创建脚本文件slave,startkafka.sh,stopkafka.sh

-rw-r--r--. 1 root root  21 Nov 11 03:46 slave
-rwxr-xr-x. 1 root root 160 Nov 11 03:46 startkafka.sh
-rwxr-xr-x. 1 root root 172 Nov 11 03:47 stopkafka.sh

slave文件(hosts里配置的)

node01
node02
node03

startkafka.sh文件

      cat /export/servers/onekey/kafka/slave | while read line
do
{
 echo $line
 ssh $line "source /etc/profile;nohup kafka-server-start.sh /export/servers/kafk
a/config/server.properties >/dev/null 2>&1 &"
}&
wait
done

stopkafka.sh 停止脚本

        cat /export/servers/onekey/kafka/slave | while read line
do
{
 echo $line
 ssh $line "source /etc/profile;jps |grep Kafka |cut -c 1-4 |xargs kill -s 9 "
}&
wait
done

一键启动脚本的环境变量配置

   #set onekey env
    export OK_HOME=/export/servers/onekey
    export PATH=${OK_HOME}/kafka:$PATH

zookeeper的环境变量

#set kafka env
export KAFKA_HOME=/export/servers/kafka
export PATH=${KAFKA_HOME}/bin:$PATH

跨服务器运行命令

ssh hostname "command"

你可能感兴趣的:(kafka一键启动)