配置開發環境:
http://storm.apache.org/releases/current/Setting-up-development-environment.html
開發環境定義:
Storm有兩種操作模式:本地模式和遠程模式。本地模式允許在本機開發測試Storm topologies,遠程模式允許你提交topologies到Storm集群上執行。
開發環境則將所有的功能包括在內,以使你能在本機開發測試,也能提交topologies包到遠程集群上運行,同時可以kill掉遠程上運行的topology。
步驟:
1. 下載一個 Storm release ,解壓縮到任意目錄,將bin/目錄放到PATH環境變量中。
2. 為了能夠開啟和關閉遠程集群上的topologies,需要
將遠程集群上master的主機地址放到~/.storm/storm.yaml文件中,來指明客戶端通信的集群是哪個。配置如下:
nimbus.seeds: ["123.45.678.890"]
3. 開發環境中建議使用maven添加storm依賴:
<dependency> <groupId>org.apache.storm</groupId> <artifactId>storm-core</artifactId> <version>1.1.1</version> <scope>provided</scope> </dependency>
Here's an example of a pom.xml for a Storm project.
http://storm.apache.org/releases/1.1.1/Running-topologies-on-a-production-cluster.html
4. 生產環境的集群中運行Topologies
1) 定義topology (在Java中使用 TopologyBuilder 來定義)
TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("1", new TestWordSpout(true), 5); builder.setSpout("2", new TestWordSpout(true), 3); builder.setBolt("3", new TestWordCounter(), 3) .fieldsGrouping("1", new Fields("word")) .fieldsGrouping("2", new Fields("word")); builder.setBolt("4", new TestGlobalCount()) .globalGrouping("1"); StormTopology topology = builder.createTopology();
2) 使用 StormSubmitter 提交topology到集群上。
Config conf = new Config(); conf.setNumWorkers(20); conf.setMaxSpoutPending(5000); StormSubmitter.submitTopology("mytopology", conf, topology);
3) 將你的代碼和其依賴打包成jar包(除了Storm相關的jar包 -- 這些jar包會加到worker節點的類路徑上).
如果你使用Maven來構建項目的話,Maven Assembly Plugin 可以幫你做這項工作,只需要你添加如下配置到pom.xml中:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.path.to.main.Class</mainClass> </manifest> </archive> </configuration> </plugin>
4) 使用 storm客戶端工具將topology提交到集群, 指定你jar包所在路徑,運行類的名稱以及運行參數:
storm jar path/to/allmycode.jar org.me.MyTopology arg1 arg2 arg3
storm jar 將提交jar到集群上並配置 StormSubmitter 類來和正確的集群會話。在這個例子中, 上傳完storm jar 后 org.me.MyTopology 中帶有 "arg1", "arg2", and "arg3"參數的main方法將會執行。
一般配置項:
所有配置項列表可以在這找到。 那些帶 "TOPOLOGY" 前綴的可以被重新設置,常用的設置項如下:
1. Config.TOPOLOGY_WORKERS: worker的進程數.
2. Config.TOPOLOGY_ACKER_EXECUTORS:ACKER的數量,不設置該項,或者設置該項為null,Storm將設置ACKER數為worker數. 如果設置該項為0,則Storm會在tuple從spout中出來時,立即 ack,這將大大地限制可靠性。
3. Config.TOPOLOGY_MAX_SPOUT_PENDING: 單個spout任務上單次能添加的最大tuple數(pending means the tuple has not been acked or failed yet). 強烈建議加上以防隊列溢出.
4. Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS: 被認為執行失敗的最大時間。默認30秒,這對大多數topology來說是足夠運行的。 Guaranteeing message processing for more information on how Storm's reliability model works.
5. Config.TOPOLOGY_SERIALIZATIONS: You can register more serializers to Storm using this config so that you can use custom types within tuples.
Killing a topology
只需要運行:
storm kill {stormname}
Storm 將不會立即殺死 topology進程. 而是先使所有的spout失效,然后等待TOPOLOGY_MESSAGE_TIMEOUT_SECS 秒后銷毀所有的worker進程.
Updating a running topology
現在只能先kill再重新提交。計划將來能實現 storm swap 命令來 that swaps a running topology with a new one, ensuring minimal downtime and no chance of both topologies processing tuples at the same time.
Monitoring topologies
Storm UI和集群上的worker的日志。