搭建Hadoop数据集群时,按以下路径操作即可生成脚本
[test_1@analysis01 bin]$ pwd
/home/test_1/hadoop/bin
[test_01@analysis01 bin]$ vim jpsall
#!/bin/bash
for host in analysis01 analysis02 analysis03
do
echo =============== $host ===============
ssh $host jps
done
[test_1@analysis01] ./jpsall #运行脚本,查看状态
=============== analysis01 ===============
4304 ResourceManager
3697 NameNode
3833 DataNode
4426 NodeManager
7595 Jps
4063 SecondaryNameNode
=============== analysis02 ===============
4480 Jps
3538 NodeManager
3437 DataNode
=============== analysis03 ===============
3396 DataNode
3487 NodeManager
4431 Jps
[test_1@analysis01 ~]$ vim shutdown_servers.sh
#!/bin/bash
# 服务器IP地址列表
servers=("192.168.2.131" "192.168.2.132" "192.168.2.130")
# 遍历服务器列表
for server in "${servers[@]}"
do
# 使用ssh登录到服务器并执行关机命令
ssh root@$server 'shutdown -h now'
done
[test_1@analysis01 ~]$ ./ shutdown_servers.sh #执行脚本
[root@master bin]# vim xzk.sh
#!/bin/bash
cmd=$1
if [ $# -gt 1] ; then echo param must be 1; exit ; fi
echo ================== master $@=============
tput setaf 3
ssh master "source /etc/profile ; zkServer.sh $cmd"
for (( i=1 ; i<=2 ; i++ )) ; do
tput setaf 5
echo ============== slave$i $@ ==================
tput setaf 6
ssh slave$i "source /etc/profile ; zkServer.sh $cmd"
done
[root@master bin]# ./xzk.sh #执行脚本