hadoop 服务启停管理脚本 留存备用

B站影视 2024-12-25 23:17 1

摘要:echo "I'm Engine-Hadoop, starting......!"

hadoop 服务启停管理脚本 留存备用

#!/bin/bash

source ~/.bash_profile

source ./props.sh ./config.properties

export JAVA_HOME=${JAVA_HOME}

WORK_HOME=$(cd "$(dirname "$0")"; pwd)

cd $WORK_HOME

umask 077

INSTALL_DIR=$WORK_HOME/..

export hadoop_HOME=$INSTALL_DIR/hadoop

IS_HAS_SET_HADOOP_HOME=$(echo $PATH | grep "$HADOOP_HOME")

if [[ "$IS_HAS_SET_HADOOP_HOME" == "" ]];then

export PATH="$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH"

fi

clear_hdfs {

echo "clear the hdfs work dir......"

nohup sh clear_hdfs.sh > $INSTALL_DIR/logs/clear_hdfs_result.log 2>&1 &

}

start {

if [ -n "$(ps aux | grep namenode | grep -v grep)" ]; then

ps -ef | grep namenode | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [ -n "$(ps aux | grep datanode | grep -v grep)" ]; then

ps -ef | grep datanode | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [ -n "$(ps aux | grep resourcemanager | grep -v grep)" ]; then

ps -ef | grep resourcemanager | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [ -n "$(ps aux | grep nodemanager | grep -v grep)" ]; then

ps -ef | grep nodemanager | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [ -n "$(ps aux | grep historyserver | grep -v grep)" ]; then

ps -ef | grep historyserver | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [[ "${INSTALL_ROLE}" == "slave" ]] ; then

echo "I am not master, only start slave......"

$INSTALL_DIR/hadoop/sbin/hadoop-daemon.sh start datanode

$INSTALL_DIR/hadoop/sbin/yarn-daemon.sh start nodemanager

echo "I'm Engine-Hadoop, starting......!"

sleep 3

elif [[ "${INSTALL_ROLE}" == "master" ]];then

echo "I am master, only start master......"

$INSTALL_DIR/hadoop/sbin/hadoop-daemon.sh start namenode

$INSTALL_DIR/hadoop/sbin/yarn-daemon.sh start resourcemanager

$INSTALL_DIR/hadoop/sbin/mr-jobhistory-daemon.sh start historyserver

sleep 10

else

echo "I am single, start master and slave......"

$INSTALL_DIR/hadoop/sbin/hadoop-daemon.sh start datanode

$INSTALL_DIR/hadoop/sbin/yarn-daemon.sh start nodemanager

sleep 10

fi

if [[ "${INSTALL_ROLE}" == "single" ]] || [[ "${INSTALL_ROLE}" == "slave" ]] ; then

$INSTALL_DIR/hadoop/bin/hdfs dfs -mkdir -p /ops/databank/spark-logs

$INSTALL_DIR/hadoop/bin/hdfs dfs -chmod -R 777 /ops

fi

}

stop {

if [[ "${INSTALL_ROLE}" == "slave" ]] ; then

echo "I am not master, only stop slave......"

$INSTALL_DIR/hadoop/sbin/hadoop-daemon.sh stop datanode

$INSTALL_DIR/hadoop/sbin/yarn-daemon.sh stop nodemanager

echo "I'm Engine-Hadoop,stopping......!"

sleep 3

elif [[ "${INSTALL_ROLE}" == "master" ]] ; then

echo "I am master, stop master......"

$INSTALL_DIR/hadoop/sbin/hadoop-daemon.sh stop namenode

$INSTALL_DIR/hadoop/sbin/yarn-daemon.sh stop resourcemanager

$INSTALL_DIR/hadoop/sbin/mr-jobhistory-daemon.sh stop historyserver

sleep 3

else

echo "I am master, stop master and slave......"

sleep 3

fi

sleep 3

if [ -n "$(ps aux | grep namenode | grep -v grep)" ]; then

ps -ef | grep namenode | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [ -n "$(ps aux | grep datanode | grep -v grep)" ]; then

ps -ef | grep datanode | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [ -n "$(ps aux | grep resourcemanager | grep -v grep)" ]; then

ps -ef | grep resourcemanager | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [ -n "$(ps aux | grep nodemanager | grep -v grep)" ]; then

ps -ef | grep nodemanager | grep -v grep | awk '{print $2}' | xargs kill -9

fi

if [ -n "$(ps aux | grep historyserver | grep -v grep)" ]; then

ps -ef | grep historyserver | grep -v grep | awk '{print $2}' | xargs kill -9

fi

echo "I'm stoped!"

}

stop_clear {

if [ -n "$(ps aux | grep manage.sh | grep -v grep)" ]; then

ps -ef | grep manage.sh | grep -v grep|awk '{print $2}'| xargs kill -9

fi

}

status {

#echo "checking status"

if [[ "${INSTALL_ROLE}" == "slave" ]] ; then

#echo "I am not master, only status slave......"

if [ -n "$(ps aux | grep datanode | grep -v grep)" ] && [ -n "$(ps aux | grep nodemanager | grep -v grep)" ]; then

exit 0

else

exit 1

fi

else

#echo "I am master, status master and slave......"

if [ -n "$(ps aux | grep namenode | grep -v grep)" ] && [ -n "$(ps aux | grep resourcemanager | grep -v grep)" ]; then

exit 0

else

exit 1

fi

fi

}

ignore{

echo "hahaha,nothing!"

}

case "$1" in

'start')

start

;;

'start_clear')

schedule_clear_hdfs

;;

'stop')

stop

;;

'stop_clear')

stop_clear

;;

'restart')

stop

sleep 3

start

;;

'status')

status

;;

'ignore')

;;

*)

echo "Usage: $0 {start|stop|restart|status|info|start_clear|stop_clear|ignore}"

exit 1

来源:小鱼科技每日一讲

相关推荐