当前位置: 首页 > >

群起群停Hadoop集群shell脚本

发布时间:

if [ $# -eq 0 ]
then
echo “No Args input…”
fi
case $1 in
“start”)
#start操作
echo “=正在开启HDFS====”
for i in hadoop102 hadoop103 hadoop104
do
if [ $i = hadoop102 ]
then
ssh $i /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh start namenode
fi


ssh $i /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh start datanode

if [ $i = hadoop104 ]
then
ssh $i /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh start secondarynamenode
fi

done


echo “=正在开启YARN====”
for i in hadoop103 hadoop102 hadoop104
do
if [ $i = hadoop103 ]
then
ssh $i /opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh start resourcemanager
fi


ssh $i /opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh start nodemanager

done


;;
“stop”)
#stop操作
echo “=正在关闭HDFS====”
for i in hadoop102 hadoop103 hadoop104
do
if [ $i = hadoop102 ]
then
ssh $i /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh stop namenode
fi


ssh $i /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh stop datanode

if [ $i = hadoop104 ]
then
ssh $i /opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh stop secondarynamenode
fi

done


echo "=====================正在关闭YARN========================"
for i in hadoop103 hadoop102 hadoop104

do
if [ $i = hadoop103 ]
then
ssh $i /opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh stop resourcemanager
fi


ssh $i /opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh stop nodemanager

done
;;


*)
echo “input Args error…”
;;
esac


================================================================
注:


(1)文件可命名为mycluster。
(2)可以在任意位置输入mycluster start 和mycluster stop 一键启动和停止Hadoop集群。
(3)在~/bin/目录下 touch mycluster新建脚本。
(4)最终给权限 chmod 777 mycluster



友情链接: