我们在上一篇文章中已经安装部署了Azkaban,但是启动的时候要去每个机器上执行一下命令。来回切换机器太麻烦,今天我们输出一个脚本,搞定自动启动停止。
[hadoop@hadoop01 ~] cd bin
[hadoop@hadoop01 ~] vi azkaban.sh
#!/bin/bash
#1 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if ((pcount==0)); then
echo no args;
exit;
fi
if ((pcount==1)); then
echo no second param;
exit;
fi
#2 获取启动类型 exec 还是 web
p1=$1
p2=$2
if [[ $p1 == "exec" ]]; then
if [[ $p2 == "start" ]]; then
for (( i = 1; i <= 3; i++ )); do
echo ====================hadoop$i azkaban exec $p2 ==============================
ssh hadoop$i "source /etc/profile;cd /bigdata/install/azkaban-exec-server-4.0.0; bin/start-exec.sh"
done
elif [[ $p2 == "active" ]]; then
for (( i =1; i <= 3; i++ )); do
echo ====================hadoop$i azkaban exec $p2 ===============================
ssh hadoop$i ‘source /etc/profile;curl http://hadoop‘${i}‘:$(‘cat /bigdata/install/azkaban-exec-server-4.0.0/executor.port‘)/executor?action=activate‘
done
elif [[ $p2 == "stop" ]]; then
for (( i = 1; i <= 3; i++ )); do
echo ====================hadoop$i azkaban exec $p2 ==============================
ssh hadoop$i "cd /bigdata/install/azkaban-exec-server-4.0.0/;bin/shutdown-exec.sh"
done
fi
elif [[ $p1 == "web" ]]; then
if [[ $p2 == "start" ]]; then
echo ====================azkaban web $p2 ==============================
ssh hadoop3 "source /etc/profile;cd /bigdata/install/azkaban-web-server-4.0.0/; bin/start-web.sh"
elif [[ $p2 == "stop" ]]; then
echo ====================azkaban web $p2 ==============================
ssh hadoop3 "source /etc/profile;cd /bigdata/install/azkaban-web-server-4.0.0/; bin/shutdown-web.sh"
fi
fi
[hadoop@hadoop01 bin] sudo chmod 777 azkaban.sh
[hadoop@hadoop01 bin] azkaban.sh exec start
[hadoop@hadoop01 bin] azkaban.sh exec active
[hadoop@hadoop01 bin] azkaban.sh web start
[hadoop@hadoop01 bin] xcall jps
[hadoop@hadoop01 bin] azkaban.sh exec stop
[hadoop@hadoop01 bin] azkaban.sh web stop
[hadoop@hadoop01 bin] xcall jps
原文:https://www.cnblogs.com/tenic/p/14891548.html