问题
以下脚本中,用ssh执行时:
#!/bin/bash
case $1 in
"start"){
for i in hadoop102 hadoop103
do
echo " --------启动 $i 采集flume-------"
ssh $i "nohup /opt/module/flume-1.9.0/bin/flume-ng agent -n a1 -c /opt/module/flume-1.9.0/conf/ -f /opt/module/flume-1.9.0/job/file_to_kafka.conf >/dev/null 2>&1 &"
#ssh $i "/opt/module/flume-1.9.0/bin/flume-ng agent -n a1 -c /opt/module/flume-1.9.0/conf/ -f /opt/module/flume-1.9.0/job/file_to_kafka.conf &"
done
};;
"stop"){
for i in hadoop102 hadoop103
do
echo " --------停止 $i 采集flume-------"
ssh $i "ps -ef | grep file_to_kafka | grep -v grep |awk '{print \$2}' | xargs -n1 kill -9 "
done
};;
esac
(1)执行 fl.sh stop时,能正常关闭。————> 表示该脚本能正常执行(权限为777)
(2)但在执行 fl.sh start ,却发现没有启动任何一个服务器的 Flume进程(即 JPS都查不到Application)
尝试:
(1)确保命令本身没问题:
服务器终端直接执行 Flume启动命令:
/opt/module/flume/bin/flume-ng agent --conf /opt/module/flume/conf --conf-file /opt/module/flume/conf/file_flume_kafka.conf --name a1 -Dflume.root.logger=INFO,console
可以正常启动 Flume,用jps查询进程能查到 “Application”
(2)将问题输出到终端
将脚本的启动命令简化:
ssh $i "/opt/module/flume-1.9.0/bin/flume-ng agent -n a1 -c /opt/module/flume-1.9.0/conf/ -f /opt/module/flume-1.9.0/job/file_to_kafka.conf &"
发现报错如下:
--------启动 hadoop102 采集flume-------
Info: Including Hive libraries found via () for Hive access
+ exec /opt/module/jdk1.8.0_212/bin/java -Xmx20m -cp '/opt/module/flume-1.9.0/conf:/opt/module/flume-1.9.0/lib/*:/lib/*' -Djava.library.path= org.apache.flume.node.Application -n a1 -f /opt/module/flume-1.9.0/job/file_to_kafka.conf
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Lists
at org.apache.flume.node.Application.main(Application.java:346)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Lists
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
--------启动 hadoop103 采集flume-------
Info: Including Hive libraries found via () for Hive access
+ exec /opt/module/jdk1.8.0_212/bin/java -Xmx20m -cp '/opt/module/flume-1.9.0/conf:/opt/module/flume-1.9.0/lib/*:/lib/*' -Djava.library.path= org.apache.flume.node.Application -n a1 -f /opt/module/flume-1.9.0/job/file_to_kafka.conf
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Lists
at org.apache.flume.node.Application.main(Application.java:346)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Lists
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
即表示:
Flume 在启动时遇到了 java.lang.NoClassDefFoundError 错误,具体是找不到 com.google.common.collect.Lists 类
——> PS:com.google.common.collect.Lists
类是 Google Guava 库的一部分。这意味着在您的环境中,Flume 需要 Guava 库才能正常运行,但似乎找不到这个库。
解决办法:
检查 Guava 库是否存在:
- 确认
/opt/module/flume-1.9.0/lib/
目录下是否有 Guava 库的 jar 文件。通常这个文件名类似于guava-xx.x.jar
,其中xx.x
是版本号。
如果不存在,那就好办了,将hadoop里的guava的Jar文件拷贝过来:
cp /opt/module/hadoop-3.1.4/share/hadoop/common/lib/guava-27.0-jre.jar /opt/module/flume-1.9.0/lib/
再次运行脚本,执行 fl.sh start。发现可以正常开启hadoop102和hadoop103的Flume进程。
问题解决