其他分享
首页 > 其他分享> > Hadoop HA一键启动,一键关闭脚本

Hadoop HA一键启动,一键关闭脚本

作者:互联网

本脚本实现一个简单的三台机器分布式集群环境下的Hadoop一键启动。

ZK:Zookeeper  ZKFC:Zookeeper FailoverController  JN:JournalNodes   RM:Yarn ResourceManager   DM:Yarn ApplicationManager(DateManager)

ZKFC 必须跟namenode在一起(hearbeat) DM 最好跟DataNode放一起,JN和ZK必须为奇数个(3,5,7)

机器编号 Namenode DateNode ZKFC ZKFC JN RM DM
hadoop202
hadoop203  
hadoop204      

 

#判断用户是否传参
if [ $# -ne 1 ];then
    echo "无效参数,用法为: $0  {start|stop}"
    exit
fi
#获取用户输入的命令
cmd=$1
#定义函数功能
function hadoopManger(){
    case $cmd in
    start)
        echo "启动服务"        
        remoteExecutionstart
        ;;
    stop)
        echo "停止服务"
        remoteExecutionstop
        ;;
    *)
        echo "无效参数,用法为: $0  {start|stop}"
        ;;
    esac
}



#启动HADOOP
function remoteExecutionstart(){
    #zookeeper
    echo ==========   ZooKeeper   ================
    for (( i=202 ; i<=204 ; i++ )) ; 
    do
            tput setaf 2
            echo ========== 启动 hadoop${i} zookeeper  $1 ================
            tput setaf 9
            ssh hadoop${i}  "source /etc/profile ; /opt/module/zookeeper-3.4.10/bin/zkServer.sh start"
    done
    
    #journalnode 
    echo ==========   Journalnode   ================
    for (( i=202 ; i<=204 ; i++ )) ; 
    do
            tput setaf 2
            echo ==========启动  hadoop${i} journalnode  $1 ================
            tput setaf 9
            ssh hadoop${i}  "source /etc/profile ; /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh start journalnode"
    done
    
    echo "启动HDFS"        
    ssh hadoop202  "source /etc/profile ; /opt/module/hadoop-2.7.2/sbin/start-dfs.sh"
    
    echo "启动YARM"        
    ssh hadoop202  "source /etc/profile ; /opt/module/hadoop-2.7.2/sbin/start-yarn.sh"
    
    echo "启动ResourceManager"        
    ssh hadoop203  "source /etc/profile ; /opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh start resourcemanager"
    
}


#关闭HADOOP
function remoteExecutionstop(){
    
    echo "关闭ResourceManager"        
    ssh hadoop203  "source /etc/profile ; /opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh stop resourcemanager"
    
    echo "关闭YARM"        
    ssh hadoop202  "source /etc/profile ; /opt/module/hadoop-2.7.2/sbin/stop-yarn.sh"
    
    echo "关闭HDFS"        
    ssh hadoop202  "source /etc/profile ; /opt/module/hadoop-2.7.2/sbin/stop-dfs.sh"    
    
    #journalnode
    echo ==========   Journalnode   ================
    for (( i=202 ; i<=204 ; i++ )) ; 
    do
            tput setaf 2
            echo ==========关闭  hadoop${i} journalnode  $1 ================
            tput setaf 9
            ssh hadoop${i}  "source /etc/profile ; /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh stop journalnode"
    done
    
    #zookeeper
    echo ==========   ZooKeeper   ================
    for (( i=202 ; i<=204 ; i++ )) ; 
    do
            tput setaf 2
            echo ========== 关闭 hadoop${i} zookeeper  $1 ================
            tput setaf 9
            ssh hadoop${i}  "source /etc/profile ; /opt/module/zookeeper-3.4.10/bin/zkServer.sh stop"
    done
    
}
#调用函数
hadoopManger

 

标签:DM,stop,一键,Hadoop,echo,start,JN,HA,ZKFC
来源: https://www.cnblogs.com/kpwong/p/13940405.html