2012/4/3 | Posted in
storm
前回からだいぶ時間がたってしまいましたが・・・
前編はこちら
Stormのことを知りたい、あるいは開発環境の設定やローカルモードでの実行を知りたい場合は、下記の記事を参照してください。
前回はzookeeperやstormのインストールまで終わりました。
今回は、1台の中で、nimbusやsupervisorを動かして、stormを使ってみます。
Stormのクラスタの設定
stormの設定は、storm.yaml というファイルを作りますが、
stormのサーバの設定用のstorm.yaml と、クライアントの設定用のstorm.yamlがあるので注意が必要です。
サーバ用とは、stormを動かすための設定で、nimbusとsupervisorで通信したり、zookeeperとやりとりをするための設定です。
クライアント用とは、stormにtopologyを投入する時に、workerはいくつにする、などの設定です。
まず、server設定用を編集します。
server用の設定は、Stormをインストールしたディレクトリを$STORM_HOMEとしたとき、$STORM_HOME/conf にあります。
$ vi /usr/local/storm-*.*.*/conf/storm.yaml
zookeeperのIP, stormの一時ファイルの置き場、nimbus hostのIP, workerがどのポートを使うか(supervisor.slots.ports)、などを指定する必要があります。
開けるポートの数は、動かすworkerの数以上である必要があります。
とりあえず今回は
zookeeper: 同じマシンで1台
nimbus : 同じマシン
なので以下のような感じにします。
# storm.zookeeper.servers:
# This is a list of the hosts in the Zookeeper cluster for your Storm cluster.
storm.zookeeper.servers:
- "127.0.0.1"
# - "localhost"
# - "127.0.0.1"
# If the port that your Zookeeper cluster uses is different than the default,
# you should set 'storm.zookeeper.port' as well.
# strom.zookeeper.port: 2181
# storm.local.dir:
# The Nimbus and Supervisor daemons require a directory on the local disk
# to store small amounts of state (like jars, confs, and things like that).
# You should create that directory on each machine, give it proper permissions,
# and then fill in the directory location using this config.
storm.local.dir: "/tmp/storm"
# java.library.path:
# This is the load path for the native libraries that Storm uses (ZeroMQ and JZMQ).
# The default of "/usr/local/lib:/opt/local/lib:/usr/lib" should be fine for
# most installations, so you probably don't need to set this config.
# java.library.path:
# nimbus.host:
# The worker nodes need to know which machine is the master in order to download
# topology jars and confs.
nimbus.host: "127.0.0.1"
# supervisor.slots.ports:
# For each worker machine, you configure how many workers run on that machine
# with this config. Each worker uses a single port for receiving messages,
# and this setting defines which ports are open for use. If you define five ports here,
# then Storm will allocate up to five workers to run on this machine. If you define
# three ports, Storm will only run up to three. By default, this setting is configured
# to run 4 workers on the ports 6700, 6701, 6702, and 6703.
supervisor.slots.ports:
- 6700
- 6701
- 6702
- 6703
他にも設定できるパラメータはいくつかあります。
デフォルトでは
defaults.yamlの値が使われます。
storm.local.dirを実際に作っておきます。
$ mkdir /tmp/storm
stormのクライアントの設定
stormのクライアント、stormクラスタに対してtopologyをsubmitする役割を持ちます。
そのため、その設定にはnimbusのIP addressが必要です。
stormのクライアントの設定は、
~/.storm/storm.yaml
に記述します。
~/.storm.yaml
nimbus.host: "127.0.0.1"
以上で設定は終わり。
storm-starterを動かしてみる
zookeeper, nimbus, supervisor, uiの順に立ち上げていきます。
uiとは、stormの処理の状態をwebから見えるようにするものです。デフォルトでポート8080を使います。
それぞれ15秒くらい待ってから立ち上げていくのがよいと思います。
$ zkServer.sh start
$ storm nimbus &
$ storm supervisor &
$ storm ui &
これでちょっと待ってから、ブラウザで接続して状態を見てみます。
以下のように表示されて、supervisor summaryのところに1台あれば、OKです。

(storm uiにはtwitter bootstrapが使われてます。)
これで、無事にsupervisorが動いてることが確認できたので、実際にtopologyをsubmitしてみます。
とりあえず、
Stormをlocalmodeで実行する で作成したstorm-starter.jarを使います。
storm-starterの中のExclamationTopologyを実行します。
ソースを見てもらえばわかりますが、このtopologyは引数があればクラスタ環境で実行され、その引数がtopologyの名前になります。
ということで、storm jar [jarの名前] [mainクラスの名前] [引数1]のようにすればtopologyをsubmitできます。
$ storm jar StormStarter.jar storm.starter.ExclamationTopology test
…..
[main] INFO backtype.storm.StormSubmitter - Jar not uploaded to master yet. Submitting jar...
37 [main] INFO backtype.storm.StormSubmitter - Uploading topology jar StormStarter.jar to assigned location: /tmp/storm/nimbus/inbox/stormjar-ea8d5f50-287e-4fcf-a371-81c84f465109.jar
53 [main] INFO backtype.storm.StormSubmitter - Successfully uploaded topology jar to assigned location: /tmp/storm/nimbus/inbox/stormjar-ea8d5f50-287e-4fcf-a371-81c84f465109.jar
53 [main] INFO backtype.storm.StormSubmitter - Submitting topology test in distributed mode with conf {"topology.workers":3,"topology.debug":true}
348 [main] INFO backtype.storm.StormSubmitter - Finished submitting topology: test
こんな感じでfinisedまで出れば、submitは成功です。
またブラウザでstorm UIを見てみると、Topology Summaryのところにtestという名前のtopologyが出てきます。
このtest をクリックすると、以下のような感じでtopologyの処理がどのくらい進んでるのか、各spoutやboltに対して見ることができます。
topologyの処理を止めるには、storm kill [topology名]です。
$ storm kill test
nimbusやsupervisorやzookeeperを止めるには、
$ zkServer.sh stop
です。storm uiだけは止まらないので、手動でkillします。
ということで、無事にnimbusやsupervisorという仕組みを使ってstormを動かすことができました。
今回は1台でzookeeperからstormまですべて動かしていますが、次はいつか複数台での動かし方について書きます。
supervisorのノードでstorm.yamlにnimbusのIPをちゃんと書けばいいだけですが。。
Tags:
storm