# 进入项目根目录下
$ cd /Users/yunyu/workspace_git/birdHadoop
# 编译打包
$ mvn clean package
# 执行java -jar运行我们打好的jar包,这里将相关操作写成了Shell脚本
$ sh scripts/storm/runWordCount_Local.sh
1
2
#### runWordCount_Local.sh脚本文件
#!/bin/bash
local_path=~/workspace_git/birdHadoop
local_inputfile_path=$local_path/inputfile/WordCount
local_outputfile_path=$local_path/outputfile/WordCount
if [ -f $local_inputfile_path/input_WordCount.bak ]; then
# 如果本地bak文件存在,就重命名去掉bak
echo "正在重命名$local_inputfile_path/input_WordCount.bak文件"
mv $local_inputfile_path/input_WordCount.bak $local_inputfile_path/input_WordCount
fi
if [ ! -d $local_outputfile_path ]; then
# 如果本地文件目录不存在,就自动创建
echo "自动创建$outputfile_path目录"
mkdir -p $local_outputfile_path
else
# 如果本地文件已经存在,就删除
echo "删除$local_outputfile_path/*目录下的所有文件"
rm -rf $local_outputfile_path/*
fi
# 需要在Maven的pom.xml文件中指定jar的入口类
echo "开始执行birdHadoop.jar..."
java -jar $local_path/target/birdHadoop.jar $local_inputfile_path $local_outputfile_path
echo "结束执行birdHadoop.jar..."
1
2
下面是执行过程中的输出
$ sh scripts/storm/runWordCount_Local.sh
正在重命名/Users/yunyu/workspace_git/birdHadoop/inputfile/WordCount/input_WordCount.bak文件
删除/Users/yunyu/workspace_git/birdHadoop/outputfile/WordCount/*目录下的所有文件
开始执行birdHadoop.jar...
log4j:WARN No appenders could be found for logger (backtype.storm.utils.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
WordCounter prepare out start
WordCounter clean out start
WordCounter result : hadoop 3
WordCounter result : hive 2
WordCounter result : logstash 1
WordCounter result : hbase 2
WordCounter result : flume 1
WordCounter result : kafka 2
WordCounter result : storm 1
WordCounter result : spark 1
WordCounter result : es 1
WordCounter clean out end
结束执行birdHadoop.jar...
Caused by: java.io.IOException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar. [jar:file:/data/storm-0.10.2/lib/storm-core-0.10.2.jar!/defaults.yaml, jar:file:/home/yunyu/Downloads/birdHadoop/target/birdHadoop.jar!/defaults.yaml]
at backtype.storm.utils.Utils.getConfigFileInputStream(Utils.java:266)
at backtype.storm.utils.Utils.findAndReadConfigFile(Utils.java:220)
... 103 more
1
2
集群模式提交Topology,需要将代码打包成jar包,然后在Storm集群机器上运行"storm jar birdHadoop.jar com.birdben.storm.demo.WordCountMain inputpath outputpath"命令,这样该Topology会运行在不同的JVM或物理机器上,并且可以在Storm UI中监控到。使用集群模式时,不能在代码中控制集群,这和LocalCluster是不一样的。无法在代码中控制集群的停止
$ storm kill WordCount
Running: /usr/local/java/bin/java -client -Ddaemon.name= -Dstorm.options= -Dstorm.home=/data/storm-0.10.2 -Dstorm.log.dir=/data/storm-0.10.2/logs -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dstorm.conf.file= -cp /data/storm-0.10.2/lib/kryo-2.21.jar:/data/storm-0.10.2/lib/servlet-api-2.5.jar:/data/storm-0.10.2/lib/hadoop-auth-2.4.0.jar:/data/storm-0.10.2/lib/minlog-1.2.jar:/data/storm-0.10.2/lib/storm-core-0.10.2.jar:/data/storm-0.10.2/lib/log4j-core-2.1.jar:/data/storm-0.10.2/lib/reflectasm-1.07-shaded.jar:/data/storm-0.10.2/lib/clojure-1.6.0.jar:/data/storm-0.10.2/lib/disruptor-2.10.4.jar:/data/storm-0.10.2/lib/log4j-over-slf4j-1.6.6.jar:/data/storm-0.10.2/lib/asm-4.0.jar:/data/storm-0.10.2/lib/log4j-slf4j-impl-2.1.jar:/data/storm-0.10.2/lib/slf4j-api-1.7.7.jar:/data/storm-0.10.2/lib/log4j-api-2.1.jar:/usr/local/storm/conf:/data/storm-0.10.2/bin backtype.storm.command.kill_topology WordCount
1467 [main] INFO b.s.u.Utils - Using defaults.yaml from resources
1535 [main] INFO b.s.u.Utils - Using storm.yaml from resources
2180 [main] INFO b.s.u.Utils - Using defaults.yaml from resources
2200 [main] INFO b.s.u.Utils - Using storm.yaml from resources
2227 [main] INFO b.s.thrift - Connecting to Nimbus at hadoop1:6627 as user:
2228 [main] INFO b.s.u.Utils - Using defaults.yaml from resources
2251 [main] INFO b.s.u.Utils - Using storm.yaml from resources
2269 [main] INFO b.s.u.StormBoundedExponentialBackoffRetry - The baseSleepTimeMs [2000] the maxSleepTimeMs [60000] the maxRetries [5]