Storm是一个分布式的、高容错的实时计算系统,在实时性要求比较强的应用场景下,可以用它来处理海量数据。我们尝试着搭建Storm平台,来实现实时计算。下面,我们在CentOS 6.4上安装配置Storm系统。
安装配置
安装配置过程,按照如下步骤进行:
1、安装配置sunjdk
下载sunjdk,并安装Java运行环境:
wget http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin
chmod +x jdk-6u45-linux-x64-rpm.bin
./jdk-6u45-linux-x64.bin
配置Java运行时环境:
vi ~/.bashrc
export JAVA_HOME=/usr/java/jdk1.6.0_45/
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/lib/*.jar:$JAVA_HOME/jre/lib/*.jar
. ~/.bashrc
java -version
2、安装zeromq
执行如下命令,进行下载配置安装:
wget http://download.zeromq.org/zeromq-2.2.0.tar.gz
tar -zvxf zeromq-2.2.0.tar.gz
cd zeromq-2.2.0/
./configure
sudo make
sudo make install
3、安装jzmq
安装jzmq需要使用Git下载源码,从源代码编译安装:
sudo yum install git
git clone git://github.com/nathanmarz/jzmq.git
cd jzmq/
sudo make
sudo make install
4、安装Storm
下载解压缩Storm软件包即可:
wget http://cloud.github.com/downloads/nathanmarz/storm/storm-0.8.1.zip
tar -xvzf storm-0.8.1.zip
然后配置环境变量:
cd storm-0.8.1/
vi ~/.bashrc
export STORM_HOME=/home/shirdrn/programs/storm-0.8.1
export PATH=$PATH:$STORM_HOME/bin
. ~/.bashrc
5、安装构建storm-starter
首先需要下载代码,并使用Maven构建:
git clone https://github.com/nathanmarz/storm-starter.git
cd storm-starter/
mvn -f m2-pom.xml package
如果需要把Storm的示例代码导入到Eclipse环境中,需要执行如下命令:
cd storm-starter/
cp m2-pom.xml pom.xml
mvn eclipse:eclipse
6、配置Storm
修改配置文件conf/storm.yaml内容如下所示:
storm.zookeeper.servers:
- "nn"
storm.zookeeper.port: 2181
nimbus.host: "nn"
storm.local.dir: "/home/shirdrn/programs/storm-0.8.1/tmp"
supervisor.slots.ports:
- 6700
- 6701
- 6702
- 6703
启动运行
1、启动Storm相关服务
启动ZooKeeper
bin/zkServer.sh start
启动Nimbus
bin/storm nimbus
查看日志,确定Nimbus启动是否成功:
[shirdrn@nn storm-0.8.1]$ tail -100f logs/nimbus.log
启动Supervisor
bin/storm supervisor
查看日志,确定Supervisor启动是否成功:
[shirdrn@nn storm-0.8.1]$ tail -100f logs/supervisor.log
2、提交一个Topology
上面,已经使用Maven构建storm-starter工程,在target目录下生成一个jar文件,然后将该storm-starter工程中的WordCountTopology提交到Nimbus,执行如下命令:
bin/storm jar ../storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar storm.starter.WordCountTopology myFirstStormApp
上面myFirstStormApp是提交的Topology的名称,可以看到提交Topology的日志信息:
0 [main] INFO backtype.storm.StormSubmitter - Jar not uploaded to master yet. Submitting jar...
12 [main] INFO backtype.storm.StormSubmitter - Uploading topology jar ../storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar to assigned location: /home/shirdrn/programs/storm-0.8.1/tmp/nimbus/inbox/stormjar-0ae68c15-130d-46f9-a46a-69dd4de29a99.jar
119 [main] INFO backtype.storm.StormSubmitter - Successfully uploaded topology jar to assigned location: /home/shirdrn/programs/storm-0.8.1/tmp/nimbus/inbox/stormjar-0ae68c15-130d-46f9-a46a-69dd4de29a99.jar
119 [main] INFO backtype.storm.StormSubmitter - Submitting topology myFirstStormApp in distributed mode with conf {"topology.workers":3,"topology.debug":true}
423 [main] INFO backtype.storm.StormSubmitter - Finished submitting topology: myFirstStormApp
这时,可以通过查看worker的日志,来确定我们提交的Topology的执行情况:
[shirdrn@nn storm-0.8.1]$ tail -100f logs/worker-6700.log
[shirdrn@nn storm-0.8.1]$ tail -100f logs/worker-6701.log
[shirdrn@nn storm-0.8.1]$ tail -100f logs/worker-6702.log
[shirdrn@nn storm-0.8.1]$ tail -100f logs/worker-6703.log
worker日志文件名称的后缀正好对应于我们在配置文件conf/storm.yaml中配置supervisor.slots.ports中的端口号。
如果只是上面的命令不带参数,表示虚拟测试该程序,如下所示:
bin/storm jar ../storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar storm.starter.WordCountTopology
可以看到具体模拟执行的情况,它并不将这个Topology提交给Nimbus。
3、Storm管理命令
可以通过如下命令查看Storm的管理操作命令:
bin/storm help
下面,给出一些常用的命令:
查询当前运行的Topology
bin/storm list
杀掉运行中的Topology
bin/storm kill myFirstStormApp
问题说明
在安装Storm的过程中,有关一些依赖安装包的问题,不像在Ubuntu系统下,可以模糊指定软件包名称,然后会给出一些提示信息,CentOS需要明确地指定软件包名称,记录下一下在安装过程中遇到的问题及其解决办法。
1、出现错误:configure: error: Unable to find a working C++ compiler
需要安装g++编译器:
sudo yum install gcc-c++
2、出现错误:configure: error: cannot link with -luuid, install uuid-dev.
需要安装软件包uuid-devel和libuuid-devel:
sudo yum install uuid-devel
sudo yum install libuuid-devel
3、出现错误:autogen.sh: error: could not find libtool. libtool is required to run autogen.sh.
需要安装libtool:
sudo yum install libtool