脚本启动zookeeper、kafka集群JAVA_HOME找不到

  • Post author:
  • Post category:java


启动脚本

#!/bin/bash
case $1 in
"start"){

echo ---------- zookeeper hadoop1 启动 ------------
sh /usr/local/zookeeper3.5.7/bin/zkServer.sh start
for i in  hadoop2 hadoop3
do
echo ---------- zookeeper $i 启动 ------------
ssh $i "/usr/local/zookeeper3.5.7/bin/zkServer.sh start"
done


echo "==========kafka hadoop1 启动 =========="
sh /usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties
for i in  hadoop2 hadoop3
do
echo "==========kafka $i 启动 ==========" 
ssh $i '/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties'
done
};;


"stop"){

echo ---------- zookeeper hadoop1 停止 ------------ 
sh /usr/local/zookeeper3.5.7/bin/zkServer.sh stop
for i in  hadoop2 hadoop3
do
echo ---------- zookeeper $i 停止 ------------ 
ssh $i "/usr/local/zookeeper3.5.7/bin/zkServer.sh stop"
done

echo ---------- kafka hadoop1 停止 ------------ 
sh /usr/local/kafka/bin/kafka-server-stop.sh stop
for i in  hadoop2 hadoop3
do
 echo ---------- kafka $i 停止 ------------ 
ssh $i "/usr/local/kafka/bin/kafka-server-stop.sh stop"
done

};;
"status"){
echo ---------- zookeeper hadoop1 状态 ------------ 
sh /usr/local/zookeeper3.5.7/bin/zkServer.sh status
for i in  hadoop2 hadoop3
do
 echo ---------- zookeeper $i 状态 ------------ 
ssh $i "/usr/local/zookeeper3.5.7/bin/zkServer.sh status"
done
};;
esac



1 启动时zookeeper报错找不到JAVA_HOME,在zkEnv.sh下图片段报错

此处报错

/etc/profile 有export JAVA_HOME且可以取到,但是zkEnv.sh取不到值

在这里插入图片描述

可在zkEnv.sh或zkServer.sh 上source /etc/profile

profile

profile

zkEnv.sh

在这里插入图片描述

zkServer.sh,顶行,在zkEnv.sh之前

在这里插入图片描述



2启动Kafka没反应,起不来

kafkaServer.out日志

在这里插入图片描述

kafka-server-start.sh 顶行增加 source /etc/profile

在这里插入图片描述



版权声明:本文为Nozomi_Ame原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。