#启动dfs,yarn,historyserver,先判断再执行
#!/bin/sh
case $1 in
start|START|Start)
echo "****************checking nodes****************"
jps>status804
NN=$(cat status804|grep NameNode)
DN=$(cat status804|grep DateNode)
SC=$(cat status804|grep SecondaryNameNode)
RM=$(cat status804|grep ResourceManager)
NM=$(cat status804|grep NodeManager)
HS=$(cat status804|grep JobHistoryServer)
HI=$(cat status804|grep RunJar)
ZK=$(cat status804|grep QuorumPeerMain)
len_NN=${#NN}
len_RM=${#RM}
len_HS=${#HS}
len_HI=${#HI}
len_ZK=${#ZK}
#检测字符长度是否不为0
if [ $len_NN == 0 ]
then
echo "****************dfs is not running****************"
else
echo "**************** dfs has been started ****************"
echo "****************stoppping dfs first****************"
stop-dfs.sh
echo "****************dfs has benn stopped successfully****************"
fi
#判断yarn是否被开启
if [ $len_RM == 0 ]
then
echo "**************** yarn is not running****************"
else
echo "**************** yarn has been started ****************"
echo "****************stopping yarn frist****************"
stop-yarn.sh
echo "****************yarn has benn stooped successfully****************"
fi
#判断historyserver是否被开启
if [ $len_HS == 0 ]
then
echo "****************hostoryserver is not running****************"
else
echo "**************** historyserver has been started ****************"
echo "****************stopping historyserver first****************"
mapred --daemon stop historyserver
echo "****************historyserver has been stopped successfully********************************"
fi
if [ $len_HI == 0 ]
then
echo "****************hive is not running****************"
fi
#启动服务
echo "The servers are ready to be started!"
start-dfs.sh
echo "****************dfs has been started successfully ****************"
start-yarn.sh
echo "****************yarn has been started successfully ****************"
mapred --daemon start historyserver
echo "****************historyserver has been started successfully********************************"
nohup hive --service metastore 1>/dev/null 2>&1 &
nohup hive --service hiveserver2 1>/dev/null 2>&1 &
echo "****************metastore and hiveserver has been started successfully ****************"
zkServer.sh start
unset HS
unset NM
unset RM
unset SC
unset DN
unset NN
unset len_NN
unset len_RM
unset len_HS
unset len_HI
unset len_ZK
rm -f status804
echo "****************checking checking checking ****************"
jps
;;
stop|STOP|Stop)
echo "****************checking nodes****************"
jps>status804
NN=$(cat status804|grep NameNode)
DN=$(cat status804|grep DateNode)
SC=$(cat status804|grep SecondaryNameNode)
RM=$(cat status804|grep ResourceManager)
NM=$(cat status804|grep NodeManager)
HS=$(cat status804|grep JobHistoryServer)
len_NN=${#NN}
len_RM=${#RM}
len_HS=${#HS}
#判断服务是否开启
if [ $len_HS !== 0 ]
then
echo "****************stoppping historyserver now ****************"
mapred --daemon stop historyserver
echo "****************historyserver has benn stopped ****************"
else
echo "****************the service of historyserver is not on ****************"
fi
if [ $len_RM !== 0 ]
then
echo "****************stopping yarn now ****************"
stop-yarn.sh
echo "****************yarn has been stopped successfully ****************"
else
echo "****************the service of yarn is not on ****************"
fi
if [ $len_NN !== 0 ]
then
echo "****************stopped dfs now ****************"
stop-dfs.sh
echo "****************dfs has been stopped successfully ****************"
else
echo "****************the service of dfs is not on ****************"
fi
unset HS
unset NM
unset RM
unset SC
unset DN
unset NN
unset len_NN
unset len_RM
unset len_HS
rm -f status804
echo "****************checking checking checking ****************"
jps
;;
hive)
beeline -u jdbc:hive2://localhost:10000
;;
kafka|Kafka)
nohup kafka-server-start.sh /opt/software/kafka2.12_280/config/server.properties 1>/dev/null 2>&1 &
echo "****************kafka has been started ****************"
;;
*)
echo "Choice is wrong!"
;;
esac