storm自身不支持開機自啟和集群整體啟動和關(guān)閉的功能,當(dāng)集群包含很多節(jié)點時管理起來會很麻煩。本文介紹了批量啟動和停止集群所有節(jié)點的腳本以及設(shè)置storm開機自啟。
一、設(shè)置節(jié)點間無密碼訪問
為了實現(xiàn)批量啟動和停止,需要提前配置好各節(jié)點間的無密碼訪問,具體方法詳見我以前的帖子或者問度娘,這里不再介紹。
二、(主節(jié)點)切換當(dāng)前路徑到storm的bin目錄下,并創(chuàng)建以下腳本和文件。
cd /software/storm/apache-storm-0.9.2-incubating/bin
touch start-supervisor.sh
touch start-all.sh
touch stop-supervisor.sh
touch stop-all.sh
touch supervisor-hosts
賦予以上腳本可執(zhí)行權(quán)限
chmod +x *.sh
三、腳本編寫
1、start-supervisor.sh
#!/bin/bash
. /etc/profile
# storm的bin目錄
bin=/software/storm/apache-storm-0.9.2-incubating/bin
supervisors=$bin/supervisor-hosts
storm nimbus >/dev/null 2>&1 &
storm ui >/dev/null 2>&1 &
cat $supervisors | while read supervisor
do
echo $supervisor
ssh $supervisor $bin/start-supervisor.sh &
done
2、start-supervisor.sh
#!/bin/bash
. /etc/profile
storm supervisor >/dev/null 2>&1 &
3、stop-all.sh
#!/bin/bash
. /etc/profile
# storm的bin目錄
bin=/software/storm/apache-storm-0.9.2-incubating/bin
supervisors=$bin/supervisor-hosts
kill -9 `ps -ef|grep daemon.nimbus| awk '{print $2}'`
kill -9 `ps -ef|grep ui.core| awk '{print $2}'`
cat $supervisors | while read supervisor
do
echo $supervisor
ssh $supervisor $bin/stop-supervisor.sh &
done
4、stop-supervisor.sh
#!/bin/bash
. /etc/profile
kill -9 `ps -ef|grep daemon.supervisor| awk '{print $2}'`
# 這里我直接清理了storm的工作路徑和log文件,根據(jù)自身需要來設(shè)置
rm -rf /software/storm/workdir/*
rm -rf /software/storm/apache-storm-0.9.2-incubating/logs/*
5、supervisor-hosts
文件中寫入所有節(jié)點的主機名或者ip,格式如下:
storm1
storm2
storm3
四、腳本的使用
腳本需要在主節(jié)點上使用。為了便于使用,請確保環(huán)境變量中已經(jīng)加入storm的bin目錄。
將上文編輯好的start-supervisor和stop-supervisor腳本復(fù)制到所有節(jié)點相同路徑下。
scp *-supervisor.sh storm2:/software/storm/apache-storm-0.9.2-incubating/bin
scp *-supervisor.sh storm3:/software/storm/apache-storm-0.9.2-incubating/bin
- 啟動集群中所有節(jié)點supervisor進程,并在主節(jié)點上啟動nimbus和ui進程
start-all.sh
- 停止集群中所有節(jié)點supervisor進程,并停止nimbus和ui進程
stop-all.sh
五、設(shè)置開機自啟
要實現(xiàn)storm開機自啟,比較簡單的方法就是開機自動運行下之前的start-all腳本,設(shè)置方法如下
vi /etc/rc.d/rc.local
添加執(zhí)行腳本
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
sh /software/storm/apache-storm-0.9.2-incubating/bin/start-all.sh