shell脚本实现实现hadoop,zookeeper,mapreduce的自动开启与关闭

shell脚本实现实现hadoop,zookeeper,mapreduce的自动开启与关闭

我们在学习大数据之路的初期,安装好虚拟机集群以及zookeeper,hadoop,MapReduce等组件后需要手动依次启动以上该组件,因此为了方便启动和关闭,我们可以编写一个shell脚本来实现。
这里以首先启动zks,再启动hdfs,yarn以及resourcemanager。
#这里是启动脚本 
#!/bin/bash
#start zks
for node in node2 node4 node4
do
        ssh $node "source /etc/profile; zkServer.sh start"  # ssh是以便能在其他机群实现
done
#sleep 1s
sleep 1
#start hdfs
start-dfs.sh
#start yarn node3:rm node2,node3,node4 nodemanager
        ssh node3 "source /etc/profile; start-yarn.sh"
#start standby rm node4上的rm
ssh node4 "source /etc/profile; yarn-daemon.sh start resourcemanager"
#jps print node1--node4 上的jps进程
allJps.sh

以上是启动的脚本,其中allJps.sh是写的打印每台节点上的进程信息,方便我们查看。代码如下:

#!/bin/bash
echo "--------node1 jps---------"
jps
for nd in node2 node3 node4
do
        echo "----------$nd jps------------"
        ssh $nd "source /etc/profile; jps"
done
最后就是关闭的脚本啦。

```powershell
#!/bin/bash
#stop node4 rm
ssh node4 "source /etc/profile; yarn-daemon.sh stop resourcemanager"
#stop node3 rm node2-node4 nodemanager
ssh node3 "source /etc/profile; stop-yarn.sh"
#stop hdfs
stop-dfs.sh
#stop zks
for node in node2 node3 node4
do
        ssh $node "source /etc/profile; zkServer.sh stop"
done

allJps.sh

	**重点:以上脚本编写完毕后,需要配置环境变量,或者直接在/root/bin目录下编写(默认环境变量位置,不需要我们手动配置)。同时编写完的脚本需要我们授予执行权限:chmod +x allJps.sh (其他两个脚本同理)**
	以上便是利用脚本实现同时启动和关闭,大家需要注意的是在其他集群上使用该命令时要使用ssh,并且让配置文件重新生效。(source /etc/profile)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值