大数据集群相关组件的群起脚本

脚本一:集群群发脚本

#!/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=101; host<104; host++)); do
        echo ------------------- hadoop$host --------------
        rsync -rvl $pdir/$fname $user@hadoop$host:$pdir
done

脚本二:集群中的所有节点执行相同的指令

#! /bin/bash
params=$@
for((i=101;i<=103;i=$i+1));do
echo "==================hadoop$i $params==============="
ssh hadoop$i "source /etc/profile;$params"
done

脚本三:启动hdfs、yarn的脚本

#!/bin/bash
user=`whoami` 
echo "================    正在启动HDFS              ==============="
ssh $user@hadoop101 '/opt/module/hadoop-2.7.2/sbin/start-dfs.sh'
echo "================    正在启动YARN                ==============="
ssh $user@hadoop102 '/opt/module/hadoop-2.7.2/sbin/start-yarn.sh'
done

脚本四:启动zookeeper集群的脚本

#! /bin/bash
params=$@
for((i=101;i<=103;i=$i+1));do
echo "==================hadoop$i $params==============="
ssh hadoop$i "source /etc/profile;$params"
done
[fym000@hadoop101 bin]$ cat zk.sh 
#! /bin/bash
case $1 in
"start"){
    for i in fym000@hadoop101 fym000@hadoop102 fym000@hadoop103
    do
        ssh $i "source /etc/profile;/opt/module/zookeeper-3.4.10/bin/zkServer.sh start"
    done
};;
"stop"){
    for i in fym000@hadoop101 fym000@hadoop102 fym000@hadoop103
    do
        ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh stop"
    done
};;
"status"){
    for i in fym000@hadoop101 fym000@hadoop102 fym000@hadoop103
    do
        ssh $i "source /etc/profile;/opt/module/zookeeper-3.4.10/bin/zkServer.sh status"
    done
};;

脚本五:启动kafka集群的脚本

#!/bin/bash
case $1 in
"start"){

    for i in fym000@hadoop101 fym000@hadoop102 fym000@hadoop103
    do
        echo "=================== $i ================"
        ssh $i "source /etc/profile;/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties"
    done
};;
"stop"){

    for i in fym000@hadoop101 fym000@hadoop102 fym000@hadoop103
    do
        echo "=================== $i ================"
        ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh"
    done
};;
esac

 

posted @ 2020-07-31 09:05  有心有梦  阅读(230)  评论(0编辑  收藏  举报