hadoop集群常用shell脚本

ぐ巨炮叔叔 提交于 2020-03-05 22:48:38

1.群发脚本XSync(xsync)

#!/bin/bash
#1 获取参数,如果不够直接退出
pcount=$#
if ((pcount==0)); then
echo no args;
exit;
fi

#2 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname

#3 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir

#4 获取当前用户名称
user=`whoami`

#5 循环遍历工作主机 执行分发命令
for host in hadoop102 hadoop103  hadoop104
do
    echo ------------------- $host --------------
    rsync -av $pdir/$fname $user@$host:$pdir
done

2.群控命令脚本XCall(xcall)

#!/bin/bash
#接收命令
params=$@
#验证参数
if(($#==0))
then
        echo 请传入要执行的命令!
        exit;
fi

 echo "要执行的命令是:$params"

for((i=102 ;i<=104 ;i=$i+1 ));
do


 echo ==========hadoop$i $params==========
 ssh hadoop$i "source /etc/profile;$params"

done

3.群起journalNode

#!/bin/bash
for i in hadoop102 hadoop103 hadoop104
do
        echo "================           $i             ================"
    #根据自己的zkServer.sh适当修改
        ssh $i 'source /etc/profile && /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh start journalnode'
done


4.群起ZK(zkstart)

#!/bin/bash
for i in hadoop102 hadoop103 hadoop104
do
        echo "================           $i             ================"
    #根据自己的zkServer.sh适当修改
        ssh $i 'source /etc/profile && /opt/module/zookeeper-3.4.10/bin/zkServer.sh start'
done

5.群关zk(zkstop)

#!/bin/bash
for i in hadoop102 hadoop103 hadoop104
do
        echo "================           $i             ================"
    #根据自己的zkServer.sh适当修改
        ssh $i 'source /etc/profile && /opt/module/zookeeper-3.4.10/bin/zkServer.sh stop'
done

6.群起zk及hadoop相关进程(zhstart)

#!/bin/bash
echo "================     开始启动所有节点服务            ==========="
echo "================     正在启动Zookeeper               ==========="
for i in hadoop102 hadoop103 hadoop104
do
        ssh $i 'source /etc/profile && /opt/module/zookeeper-3.4.10/bin/zkServer.sh start'
done
echo "================     正在启动HDFS                    ==========="
#根据自身情况修改用户名
ssh zhengkw@hadoop102 '/opt/module/hadoop-2.7.2/sbin/start-dfs.sh'
echo "================     正在启动YARN                    ==========="
ssh zhengkw@hadoop103 '/opt/module/hadoop-2.7.2/sbin/start-yarn.sh'
echo "================     正在开启JobHistoryServer        ==========="
ssh zhengkw@hadoop102 '/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh start historyserver'

7.群关zk及hadoop相关进程(zhstop)

#!/bin/bash
echo "================     开始关闭所有节点服务            ==========="
echo "================     正在关闭Zookeeper               ==========="
for i in hadoop102 hadoop103 hadoop104
do
        ssh $i 'source /etc/profile && /opt/module/zookeeper-3.4.10/bin/zkServer.sh stop'
done
echo "================     正在关闭HDFS                    ==========="
ssh zhengkw@hadoop102 '/opt/module/hadoop-2.7.2/sbin/stop-dfs.sh'
echo "================     正在关闭YARN                    ==========="
ssh zhengkw@hadoop103 '/opt/module/hadoop-2.7.2/sbin/stop-yarn.sh'
echo "================     正在关闭JobHistoryServer        ==========="
ssh zhengkw@hadoop102 '/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh stop historyserver'

注意
所有脚本创建好后配置好ssh免密服务,可参照点我!here!!里面的ssh免密配置。
给予脚本执行权限!
根据自己的配置修改用户名或者是主机名!!!!
适当分发脚本到/home/用户名/bin/下

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!