我們在上一篇文章中已經安裝部署了Azkaban,但是啟動的時候要去每個機器上執行一下命令。來回切換機器太麻煩,今天我們輸出一個腳本,搞定自動啟動停止。
1 登錄到hadoop01上,在~/bin 目錄下創建一個azkaban.sh腳本
[hadoop@hadoop01 ~] cd bin
[hadoop@hadoop01 ~] vi azkaban.sh
2 編寫腳本文件,保持退出
#!/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
3 修改腳本權限
[hadoop@hadoop01 bin] sudo chmod 777 azkaban.sh
4 啟動/停止腳本
- 啟動服務
[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