赞
踩
#!/bin/bash
#启动hadoop ha集群
start(){
md hadoop"zkServer.sh start"node1 node2 node3
md hadoop"start-dfs.sh"master1
md hadoop"start-yarn.sh"master1
md hadoop"yarn-daemon.sh start resourcemanager"master2
}
#启动hadoop ha集群
stop(){
md hadoop"yarn-daemon.sh stop resourcemanager"master2
md hadoop"stop-yarn.sh"master1
md hadoop"stop-dfs.sh"master1
md hadoop"zkServer.sh stop"node1 node2 node3
}
#验证hadoop NameNode状态
statusNN(){
success=0nn=$1
echo "[INFO] check hadoop in $nn status..."rm1=`ssh hadoop@$nn "source /etc/profile; jps | grep ResourceManager"`
nn1=`ssh hadoop@$nn "source /etc/profile; jps | grep NameNode"`
zkfc1=`ssh hadoop@$nn "source /etc/profile; jps |grep DFSZKFailoverController"`
len_rm1=${#rm1}
len_nn1=${#nn1}
len_zkfc1=${#zkfc1}if [ $len_rm1 == 0]then
echo -e "[WARING] ResourceManager in $nn do not running"let success=1
fi
if [ $len_nn1 == 0]then
echo -e "[WARING] NameNode in $nn do not running"let success=1
fi
if [ $len_zkfc1 == 0]then
echo -e "[WARING] DFSZKFailoverController in $nn do not running"let success=1
fi
if [ $success != 1]then
echo -e "[INFO] hadoop in $nn is running well"
fi}
#验证Hadoop DataNode状态
statusDN(){
success=0dn=$1
echo "[INFO] check hadoop in $dn status..."qpm1=`ssh hadoop@$dn "source /etc/profile; jps | grep QuorumPeerMain"`
jn1=`ssh hadoop@$dn "source /etc/profile; jps | grep JournalNode"`
nm1=`ssh hadoop@$dn "source /etc/profile; jps | grep NodeManager"`
dn1=`ssh hadoop@$dn "source /etc/profile; jps | grep DataNode"`
len_qpm1=${#qpm1}
len_jn1=${#jn1}
len_nm1=${#nm1}
len_dn1=${#dn1}if [ $len_qpm1 == 0 ]; then
echo -e "[WARING] QuorumPeerMain in $dn is not running"let success=1
fi
if [ $len_jn1 == 0 ]; then
echo -e "[WARING] JournalNode in $dn is not running"let success=1
fi
if [ $len_nm1 == 0 ]; then
echo -e "[WARING] NodeManager in $dn is not running"let success=1
fi
if [ $len_dn1 == 0 ]; then
echo -e "[WARING] DataNode in $dn is not running"let success=1
fi
if [ $success != 1 ]; then
echo -e "[INFO] hadoop in $dn is running well"
fi}
status(){
statusNN master1
statusNN master2
statusDN node1
statusDN node2
statusDN node3
}
opt=$1
if [ "$opt" == "start"]then
echo "[INFO] start hadoop..."startelif [ "$opt" == "stop"]then
echo "[INFO] stop hadoop..."stopelif [ "$opt" == "restart"]then
echo "[INFO] restart hadoop..."stop
startelif [ "$opt" == "status"]then
echo "checking hadoop status...."statuselse
echo "Usage: hadoop-admin "
fi
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。