问题描述:
之前写的kafka集群启动脚本,今天重启服务器后失效了, 只启动了本地的kafka1, 另一台虚拟机上的kafka2没启动也没有日志
#! /bin/bash
case $1 in
"start"){
echo " --------Start 10.168.204.158 Kafka Broker $j-------"
# 用于KafkaManager监控
export JMX_PORT=9988 && /home/pmish/software/kafka_2.12-2.4.1/bin/kafka-server-start.sh -daemon /home/pmish/software/kafka_2.12-2.4.1/config/server.properties
for i in 10.168.204.2
do
echo " --------Start $i Kafka Broker $j-------"
# 用于KafkaManager监控
ssh $i "export JMX_PORT=9988 && /home/pmish/software/kafka_2.12-2.4.1/bin/kafka-server-start.sh -daemon /home/pmish/software/kafka_2.12-2.4.1/config/server.properties "
done
};;
"stop"){
echo " --------Stop 10.168.204.158 Kafka-------"
/home/pmish/software/kafka_2.12-2.4.1/bin/kafka-server-stop.sh stop
for i in 10.168.204.2
do
echo " --------Stop $i Kafka-------"
ssh $i "/home/pmish/software/kafka_2.12-2.4.1/bin/kafka-server-stop.sh stop"
done
};;
esac
百度后找到一篇文章解决了:
解决方法:
1、先测试 ssh [kafka2 ip] "which java" 是否有反应
如果显示no found,
[root@kafka1 software]# ssh kafka2 "which java"
which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
需要下面的配置
2、需要配置 vim ~/.bashrc
添加代码:
export JAVA_HOME=/usr/local/java/jdk1.8.0_211
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
将.bashrc文件分发到其他节点上
scp ~/.bashrc root@kafka2:/root/.bashrc
3、继续测试 ssh [kafka2 ip] "which java" 成功后重启脚本,看进程是否存在
[root@kafka1 software]# ssh kafka2 "which java"
/usr/local/java/jdk1.8.0_211/bin/java
原因:
- 登录式Shell,采用用户名比如xxx登录,会自动加载/etc/profile
- 非登录式Shell,采用ssh 比如ssh 10.168.204.203登录,不会自动加载/etc/profile,会自动加载~/.bashrc
其他方法:
-
检查broker.id是否不一致
-
zookeeper.connect是否正确
-
Kafka的环境变量
————————————————
参考https://blog.csdn.net/weixin_45721882/article/details/116033387
https://www.cnblogs.com/ttzz/p/13355567.html