Hadoop启动任意功能脚本分析

#启动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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值