每日总结

编写Hadoop集群常用脚本

1Hadoop集群启停脚本(包含HDFSYarnHistoryserver):myhadoop.sh

[atguigu@hadoop102 ~]$ cd /home/atguigu/bin

[atguigu@hadoop102 bin]$ vim myhadoop.sh

  • 输入如下内容

#!/bin/bash

 

if [ $# -lt 1 ]

then

    echo "No Args Input..."

    exit ;

fi

 

case $1 in

"start")

        echo " =================== 启动 hadoop集群 ==================="

 

        echo " --------------- 启动 hdfs ---------------"

        ssh hadoop102 "/opt/module/hadoop-3.1.3/sbin/start-dfs.sh"

        echo " --------------- 启动 yarn ---------------"

        ssh hadoop103 "/opt/module/hadoop-3.1.3/sbin/start-yarn.sh"

        echo " --------------- 启动 historyserver ---------------"

        ssh hadoop102 "/opt/module/hadoop-3.1.3/bin/mapred --daemon start historyserver"

;;

"stop")

        echo " =================== 关闭 hadoop集群 ==================="

 

        echo " --------------- 关闭 historyserver ---------------"

        ssh hadoop102 "/opt/module/hadoop-3.1.3/bin/mapred --daemon stop historyserver"

        echo " --------------- 关闭 yarn ---------------"

        ssh hadoop103 "/opt/module/hadoop-3.1.3/sbin/stop-yarn.sh"

        echo " --------------- 关闭 hdfs ---------------"

        ssh hadoop102 "/opt/module/hadoop-3.1.3/sbin/stop-dfs.sh"

;;

*)

    echo "Input Args Error..."

;;

esac

  • 保存后退出,然后赋予脚本执行权限

[atguigu@hadoop102 bin]$ chmod +x myhadoop.sh

2)查看三台服务器Java进程脚本:jpsall

[atguigu@hadoop102 ~]$ cd /home/atguigu/bin

[atguigu@hadoop102 bin]$ vim jpsall

  • 输入如下内容

#!/bin/bash

 

for host in hadoop102 hadoop103 hadoop104

do

        echo =============== $host ===============

        ssh $host jps

done

  • 保存后退出,然后赋予脚本执行权限

[atguigu@hadoop102 bin]$ chmod +x jpsall

3)分发/home/atguigu/bin目录,保证自定义脚本在三台机器上都可以使用

[atguigu@hadoop102 ~]$ xsync /home/atguigu/bin/

posted @ 2021-11-08 18:50  小萌新一枚lll  阅读(60)  评论(0编辑  收藏  举报