storm自身不支持開(kāi)機(jī)自啟和集群整體啟動(dòng)和關(guān)閉的功能,當(dāng)集群包含很多節(jié)點(diǎn)時(shí)管理起來(lái)會(huì)很麻煩盟迟。本文介紹了批量啟動(dòng)和停止集群所有節(jié)點(diǎn)的腳本以及設(shè)置storm開(kāi)機(jī)自啟秋泳。
一、設(shè)置節(jié)點(diǎn)間無(wú)密碼訪問(wèn)
為了實(shí)現(xiàn)批量啟動(dòng)和停止攒菠,需要提前配置好各節(jié)點(diǎn)間的無(wú)密碼訪問(wèn)迫皱,具體方法詳見(jiàn)我以前的帖子或者問(wèn)度娘,這里不再介紹要尔。
二舍杜、(主節(jié)點(diǎn))切換當(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
三既绩、腳本編寫(xiě)
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ù)自身需要來(lái)設(shè)置
rm -rf /software/storm/workdir/*
rm -rf /software/storm/apache-storm-0.9.2-incubating/logs/*
5救欧、supervisor-hosts
文件中寫(xiě)入所有節(jié)點(diǎn)的主機(jī)名或者ip衰粹,格式如下:
storm1
storm2
storm3
四、腳本的使用
腳本需要在主節(jié)點(diǎn)上使用笆怠。為了便于使用铝耻,請(qǐng)確保環(huán)境變量中已經(jīng)加入storm的bin目錄。
將上文編輯好的start-supervisor和stop-supervisor腳本復(fù)制到所有節(jié)點(diǎn)相同路徑下蹬刷。
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
- 啟動(dòng)集群中所有節(jié)點(diǎn)supervisor進(jìn)程瓢捉,并在主節(jié)點(diǎn)上啟動(dòng)nimbus和ui進(jìn)程
start-all.sh
- 停止集群中所有節(jié)點(diǎn)supervisor進(jìn)程,并停止nimbus和ui進(jìn)程
stop-all.sh
五、設(shè)置開(kāi)機(jī)自啟
要實(shí)現(xiàn)storm開(kāi)機(jī)自啟办成,比較簡(jiǎn)單的方法就是開(kāi)機(jī)自動(dòng)運(yùn)行下之前的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