假设有4台机,IP及主机名如下:
192.168.100.105 c1 192.168.100.110 c2 192.168.100.115 c3 192.168.100.120 c4
假设Storm安装在/home/目录下,也就是/home/storm/
* 先登录root账号再进行以下操作
1.创建脚本
创建并赋予运行权限
mk batch-storm.sh chmod u+x batch-storm.sh
2.编辑脚本
vim batch-storm.sh
添加以下内容:
#!/bin/bash usage="Usage: $0 (start|stop)" if [ $# -lt 1 ]; then echo $usage exit 1 fi action=$1 iparray=(c1 c2 c3 c4) path="/home/storm/bin" echo "$action Storm cluster" case $action in "start") echo "$action Nimbus" $path/storm nimbus & sleep 3s for ip in ${iparray[*]} do echo "ssh to $ip - $action Supervisor" ssh $ip $path/storm supervisor & sleep 2s done echo "$action UI" $path/storm ui & ;; "stop") echo "$action UI" ps -ef|grep UIServer|grep -v grep|awk '{print $2}'|xargs kill -9 sleep 3s for ip in ${iparray[*]} do echo "ssh to $ip - $action Supervisor" # ssh $ip ps -ef|grep Supervisor|grep -v grep|awk '{print $2}'|xargs kill -9 pid=$(ssh $ip ps -ef | grep Supervisor | grep -v grep | awk '{print $2}') ssh $ip "kill -9 ${pid}" sleep 2s done echo "$action Nimbus" ps -ef|grep Nimbus|grep -v grep|awk '{print $2}'|xargs kill -9 ;; esac exit 0
3.编辑storm文件
* 该步骤在每台机都要执行
vim /home/storm/bin/storm
添加一行内容:
export JAVA_HOME=/usr/bin/jdk1.8.0
这里的/usr/bin/jdk1.8.0是Java安装目录,请按实际情况修改。
4.运行脚本
只需要在其中一台机运行即可
批量启动:
./batch-storm.sh start
批量停止:
./batch-storm.sh stop