storm開機自啟以及常用Shell腳本

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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • storm啟停腳本的編寫: 第一步:在master節(jié)點創(chuàng)建start-supervisor.sh腳本,然后分發(fā)到各...
    夙夜M閱讀 778評論 0 0
  • 1. Storm介紹: Storm是實時流計算框架。企業(yè)中典型實時分析框架搭建模式: Flume + Kafka ...
    奉先閱讀 1,805評論 0 3
  • 目錄 場景假設(shè) 調(diào)優(yōu)步驟和方法 Storm 的部分特性 Storm 并行度 Storm 消息機制 Storm UI...
    mtide閱讀 17,288評論 30 60
  • Date: Nov 17-24, 2017 1. 目的 積累Storm為主的流式大數(shù)據(jù)處理平臺對實時數(shù)據(jù)處理的相關(guān)...
    一只很努力爬樹的貓閱讀 2,334評論 0 4
  • 1.在快樂和痛苦中找一個平衡點,便可以一個人踏上生命中的快意之旅。 2.其實我一直都明白的,只是很多時候忘記了。我...
    沈好好閱讀 225評論 0 1

友情鏈接更多精彩內(nèi)容