hadoop集群启动和关闭shell脚本

本文介绍了如何使用shell脚本启动和关闭Hadoop集群,强调了启动顺序(Zookeeper -> HDFS -> YARN),并指出在非登录shell环境下执行脚本时可能遇到的环境变量问题。解决方案包括在脚本中引用/etc/profile,将配置信息写入.bashrc,或直接在Zookeeper的zkEnv.sh中设置JAVA_HOME。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

说明:
1、先启动zookeeper,再启动hdfs,再启动yarn。
2、user为hadoop使用的linux用户。
3、采用SSH登陆到其他机器执行脚本的方式,且配置了ssh免密钥登陆。

start-hadoop.sh

user=hadoop
echo start zookeeper...
for zk in master05 master06 master07
do
ssh $user@$zk "source /etc/profile;/master/env/zookeeper/bin/zkServer.sh start"
done
echo zookeeper started

echo start hdfs...
hdfs=master01
ssh $user@$hdfs "source /etc/profile;/master/env/hadoop/sbin/start-dfs.sh"
echo hdfs started

echo start yarn...
yarn=master03
rsm=master04
ssh $user@$yarn "source /etc/profile;/master/env/hadoop/sbin/start-yarn.sh"
ssh $user@$rsm "source /etc/profile;/master/env/hadoop/sbin/yarn-daemon.sh start resourcemanager"
echo yarn started

stop-hadoop.sh

user=hadoop
echo stop zookeeper...
for zk in master05 master06 master07
do
ssh $user@$zk "source /etc/profile;/master/env/zookeeper/bin/zkServer.sh stop"
done
echo zookeeper stoped

echo stop hdfs...
hdfs=master01
ssh $user@$hdfs "source /etc/profile;/master/env/hadoop/sbin/stop-dfs.sh"
echo hdfs stoped

echo stop yarn...
yarn=master03
rsm=master04
ssh $user@$yarn "source /etc/profile;/master/env/hadoop/sbin/stop-yarn.sh"
ssh $user@$rsm "source /etc/profile;/master/env/hadoop/sbin/yarn-daemon.sh stop resourcemanager"
echo yarn stoped

补充:
交互式shell和非交互式shell、登录shell和非登录shell区别
在登录shell里,环境信息需要读取/etc/profile和~ /.bash_profile, ~/.bash_login, and ~/.profile按顺序最先的一个,并执行其中的命令。除非被 –noprofile选项禁止了; 在非登录shell里,环境信息只读取 /etc/bash.bashrc和~/.bashrc
手工执行是属于登陆shell,脚本执行数据非登陆shell,而我的linux环境配置中只对/etc/profile进行了jdk1.7等环境的配置,所以脚本执行/usr/local/zookeeper/bin/zkServer.sh start 启动zookeeper失败了
解决方法(下面3个方法任选1):
1、脚本代码中添加“source /etc/profile;” 改为:ssh crxy$i “source /etc/profile;/usr/local/zookeeper/bin/zkServer.sh start”
2、把profile的配置信息echo到.bashrc中 echo ‘source /etc/profile’ >> ~/.bashrc
3、在/zookeeper/bin/zkEnv.sh的中开始位置添加 export JAVA_HOME=/usr/local/jdk1.7.0_45(就像hadoop中对hadoop-env.sh的配置一样)

shell 脚本登陆其他机器操作
1、配置ssh免密钥登陆。
2、在shell脚本中执行:ssh linux用户名@主机名或者IP “要执行的命令”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值