apache storm은 apache zookeeper를 필요로한다. 




* apache zookeeper 설치와 실행

http://www.apache.org/dyn/closer.cgi/zookeeper/



$ ./zkServer.sh start

ZooKeeper JMX enabled by default

Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED






* apache storm 설치 


http://storm.apache.org/downloads.html에서 설치 후 /usr/local로 옮긴다.


(archieves는 http://archive.apache.org/dist/storm/에 존재한다. 1.0.1로 테스트한다.)



설정을 변경해 local zookeeper를 바라보도록 한다. 


$ vi conf/storm.yaml


storm.zookeeper.servers:

      - localhost

nimbus.seeds: ["localhost"]





master node인 nimbus를 실행한다. 



$ ./bin/storm nimbus

Running: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java -server -Ddaemon.name=nimbus .... org.apache.storm.daemon.nimbus




supervisor 노드를 실행한다.


$ ./bin/storm supervisor

Running: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java -server -Ddaemon.name=supervisor... org.apache.storm.daemon.supervisor




admin ui를 위해 ui도 실행한다.


$ ./bin/storm ui

Running: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java -server -Ddaemon.name=ui ... org.apache.storm.ui.core



웹 브라우져에서 http://localhost:8080에 접속해서 정상적으로 접근되는지 확인한다.




데몬을 확인한다. 

$ ps -ef | grep apache-storm


3개의 데몬 nimbus, ui, supervisor가 제대로 떠 있는지 확인할 수 있다. 


  


테스트를 위해 wordcount topology를 submit 한다. 


$ ./bin/storm jar ./examples/storm-starter/storm-starter-topologies-1.0.1.jar org.apache.storm.starter.WordCountTopology wordcount

Running: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java -client -Ddaemon.name= -Dstorm.options= -Dstorm.home=/usr/local/apache-storm-1.0.1 -Dstorm.log.dir=/usr/local/apache-storm-1.0.1/logs -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dstorm.conf.file= -cp /usr/local/apache-storm-1.0.1/lib/asm-5.0.3.jar:/usr/local/apache-storm-1.0.1/lib/clojure-1.7.0.jar:/usr/local/apache-storm-1.0.1/lib/disruptor-3.3.2.jar:/usr/local/apache-storm-1.0.1/lib/kryo-3.0.3.jar:/usr/local/apache-storm-1.0.1/lib/log4j-api-2.1.jar:/usr/local/apache-storm-1.0.1/lib/log4j-core-2.1.jar:/usr/local/apache-storm-1.0.1/lib/log4j-over-slf4j-1.6.6.jar:/usr/local/apache-storm-1.0.1/lib/log4j-slf4j-impl-2.1.jar:/usr/local/apache-storm-1.0.1/lib/minlog-1.3.0.jar:/usr/local/apache-storm-1.0.1/lib/objenesis-2.1.jar:/usr/local/apache-storm-1.0.1/lib/reflectasm-1.10.1.jar:/usr/local/apache-storm-1.0.1/lib/servlet-api-2.5.jar:/usr/local/apache-storm-1.0.1/lib/slf4j-api-1.7.7.jar:/usr/local/apache-storm-1.0.1/lib/storm-core-1.0.1.jar:/usr/local/apache-storm-1.0.1/lib/storm-rename-hack-1.0.1.jar:./examples/storm-starter/storm-starter-topologies-1.0.1.jar:/usr/local/apache-storm-1.0.1/conf:/usr/local/apache-storm-1.0.1/bin -Dstorm.jar=./examples/storm-starter/storm-starter-topologies-1.0.1.jar org.apache.storm.starter.WordCountTopology wordcount

534  [main] INFO  o.a.s.StormSubmitter - Generated ZooKeeper secret payload for MD5-digest: -8806961472207405752:-5043320726578157353

585  [main] INFO  o.a.s.s.a.AuthUtils - Got AutoCreds []

640  [main] INFO  o.a.s.StormSubmitter - Uploading topology jar ./examples/storm-starter/storm-starter-topologies-1.0.1.jar to assigned location: /usr/local/apache-storm-1.0.1/storm-local/nimbus/inbox/stormjar-609f1ee2-82e5-4111-bba2-c36b830e0b15.jar

Start uploading file './examples/storm-starter/storm-starter-topologies-1.0.1.jar' to '/usr/local/apache-storm-1.0.1/storm-local/nimbus/inbox/stormjar-609f1ee2-82e5-4111-bba2-c36b830e0b15.jar' (62432746 bytes)

[==================================================] 62432746 / 62432746

File './examples/storm-starter/storm-starter-topologies-1.0.1.jar' uploaded to '/usr/local/apache-storm-1.0.1/storm-local/nimbus/inbox/stormjar-609f1ee2-82e5-4111-bba2-c36b830e0b15.jar' (62432746 bytes)

935  [main] INFO  o.a.s.StormSubmitter - Successfully uploaded topology jar to assigned location: /usr/local/apache-storm-1.0.1/storm-local/nimbus/inbox/stormjar-609f1ee2-82e5-4111-bba2-c36b830e0b15.jar

936  [main] INFO  o.a.s.StormSubmitter - Submitting topology wordcount in distributed mode with conf {"storm.zookeeper.topology.auth.scheme":"digest","storm.zookeeper.topology.auth.payload":"-8806961472207405752:-5043320726578157353","topology.workers":3,"topology.debug":true}

1196 [main] INFO  o.a.s.StormSubmitter - Finished submitting topology: wordcount


job업로드하고 잘 실행되는지 확인할 수 있다.




실제 소스 디렉토리는 https://github.com/apache/storm/tree/1.0.x-branch/examples/storm-starter에 있다.




main 메소드는 아래 링크에 있다. 


https://github.com/apache/storm/blob/1.0.x-branch/examples/storm-starter/src/jvm/org/apache/storm/starter/WordCountTopology.java


로컬 테스트를 위해 LocalCluster를 사용하고 있고 Spout -> Bolt("split")-> Bolt("count")의 토롤리지를 구성하고 있다. 




  public static void main(String[] args) throws Exception {


    TopologyBuilder builder = new TopologyBuilder();


    builder.setSpout("spout", new RandomSentenceSpout(), 5);


    builder.setBolt("split", new SplitSentence(), 8).shuffleGrouping("spout");

    builder.setBolt("count", new WordCount(), 12).fieldsGrouping("split", new Fields("word"));


    Config conf = new Config();

    conf.setDebug(true);


    if (args != null && args.length > 0) {

      conf.setNumWorkers(3);


      StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());

    }

    else {

      conf.setMaxTaskParallelism(3);


      LocalCluster cluster = new LocalCluster();

      cluster.submitTopology("word-count", conf, builder.createTopology());


      Thread.sleep(10000);


      cluster.shutdown();

    }

  }




데몬을 확인하면 3개의 주요 데몬 외에.. 6개가 더 떠 있는 것을 확인할 수 있다. (주목할 점은 6700~6702!!)


$ ps -ef | grep apache-storm


  ...  org.apache.storm.daemon.worker wordcount-1-1503398931 6dd4cbd3-1f43-4f17-a90f-b470fddbccbc 6700 28fae52d-9d91-4de8-9130-fe1dff2f2487

... org.apache.storm.daemon.worker wordcount-1-1503398931 6dd4cbd3-1f43-4f17-a90f-b470fddbccbc 6701 8b53b715-0184-4639-b33f-68208cc7d2e3

...  org.apache.storm.daemon.worker wordcount-1-1503398931 6dd4cbd3-1f43-4f17-a90f-b470fddbccbc 6702 e8357b79-dd08-4d70-b4de-2bf69598eadf

비슷한 것 3개가 또 있음 

 


 


제대로 동작했는지 웹 브라우져에서 살펴볼 수 있다. 


http://localhost:8080/topology.html?id=wordcount-1-1503398931

  



http://localhost:8080/api/v1/topology/summary을 호출해 api summary로 확인할 수 있다.


$ curl http://localhost:8080/api/v1/topology/summary

{"topologies":[{"assignedTotalMem":2496.0,"owner":"samuel.kim","requestedMemOnHeap":0.0,"encodedId":"wordcount-1-1503398931","assignedMemOnHeap":2496.0,"id":"wordcount-1-1503398931","uptime":"11m 28s","schedulerInfo":null,"name":"wordcount","workersTotal":3,"status":"INACTIVE","requestedMemOffHeap":0.0,"tasksTotal":28,"requestedCpu":0.0,"replicationCount":1,"executorsTotal":28,"uptimeSeconds":688,"assignedCpu":0.0,"assignedMemOffHeap":0.0,"requestedTotalMem":0.0}],"schedulerDisplayResource":false}




목록을 확인할 수 있다. 


$ ./bin/storm list

Topology_name        Status     Num_tasks  Num_workers  Uptime_secs

-------------------------------------------------------------------

wordcount            ACTIVE     28         3            370




로그로 확인해보려면 logs 밑에 디렉토리가 있는데, 아까 봤던 ps ef로 봤던 6700~6702가 보인다. 


$ls -al logs/workers-artifacts/wordcount-1-1503398931/670

6700/ 6701/ 6702/




$ ls -al logs/workers-artifacts/wordcount-1-1503398931/6700/

gc.log.0.current    worker.log          worker.log.err      worker.log.metrics  worker.log.out      worker.pid          worker.yaml




정상적으로 작동했는지 하나 살펴본다. 


$ ls -al logs/workers-artifacts/wordcount-1-1503398931/6700/worker.log

-rw-r--r--  1 samuel.kim  staff  48832569  8 22 19:57 logs/workers-artifacts/wordcount-1-1503398931/6700/worker.log

[/usr/local/apache-storm-1.0.1] tail -n 10 logs/workers-artifacts/wordcount-1-1503398931/6700/worker.log

2017-08-22 19:57:46.245 o.a.s.d.executor [INFO] Processing received message FOR 10 TUPLE: source: split:21, stream: default, id: {}, [cow]

2017-08-22 19:57:46.245 o.a.s.d.executor [INFO] BOLT ack TASK: 13 TIME:  TUPLE: source: split:22, stream: default, id: {}, ["away"]

2017-08-22 19:57:46.245 o.a.s.d.task [INFO] Emitting: count default [cow, 4976]

2017-08-22 19:57:46.245 o.a.s.d.executor [INFO] Execute done TUPLE source: split:22, stream: default, id: {}, ["away"] TASK: 13 DELTA:

2017-08-22 19:57:46.245 o.a.s.d.executor [INFO] BOLT ack TASK: 10 TIME:  TUPLE: source: split:21, stream: default, id: {}, [cow]

2017-08-22 19:57:46.245 o.a.s.d.executor [INFO] Execute done TUPLE source: split:21, stream: default, id: {}, [cow] TASK: 10 DELTA:

2017-08-22 19:57:46.246 o.a.s.d.executor [INFO] Processing received message FOR 7 TUPLE: source: split:19, stream: default, id: {}, ["am"]

2017-08-22 19:57:46.246 o.a.s.d.task [INFO] Emitting: count default [am, 5050]

2017-08-22 19:57:46.246 o.a.s.d.executor [INFO] BOLT ack TASK: 7 TIME:  TUPLE: source: split:19, stream: default, id: {}, ["am"]

2017-08-22 19:57:46.246 o.a.s.d.executor [INFO] Execute done TUPLE source: split:19, stream: default, id: {}, ["am"] TASK: 7 DELTA:






deactivate 할 수도 있다. 


$ ./bin/storm deactivate wordcount

1650 [main] INFO  o.a.s.c.deactivate - Deactivated topology: wordcount




list로 상태를 본다.


$ ./bin/storm list

Topology_name        Status     Num_tasks  Num_workers  Uptime_secs

-------------------------------------------------------------------

wordcount            INACTIVE   28         3            617








kill해본다.

$./bin/storm kill wordcount

1696 [main] INFO  o.a.s.c.kill-topology - Killed topology: wordcount


ui에서 목록이 사라진다. 


$ curl http://localhost:8080/api/v1/topology/summary

{"topologies":[],"schedulerDisplayResource":false}



웹 브라우저에서 http://localhost:8080/index.html를 열어보면 wordcount topology가 보이지 않거나 wordcount topology가 나타나되 KILLED 상태인 것을 확인할 수도 있다. 

잠깐 wordcount topology가 보여도 결국은 사라진다..





nimbus를 중지해야 worker 데몬은 모두 종료된다. SPOF의 위험성이 높긴 하다.. 


Posted by '김용환'
,