改进部署脚本——xcall.sh和xrsync.sh¶
1. 进入bin目录¶
su - centos
cd /usr/local/bin
2. 创建xcall脚本¶
# xcall脚本负责同步命令
touch xcall.sh
3. 添加可执行权限¶
chmod a+x xcall.sh
4. 编写xcall脚本内容¶
#!/bin/bash
for (( i=101; i<=104; i++ )); do
ssh s$i "$@";
done
1. 测试¶
xcall.sh hostname
5. 优化xcall脚本-参数¶
vim xcall.sh
#!/bin/bash
if [ $# -lt 1 ]; then echo 需要参数; exit ; fi
for (( i=101; i<=104; i++ )); do
ssh s$i "$@";
done
1. 测试¶
xcall.sh
6. 优化xcall脚本-美观¶
vim xcall.sh
#!/bin/bash
if [ $# -lt 1 ]; then echo 需要参数; exit ; fi
for (( i=101; i<=104; i++ )); do
echo --------------s$i $@-------------------
ssh s$i "$@";
done
1. 测试¶
xcall.sh touch ~/test-xcall
7. xcall脚本的作用¶
# 如果集群出现问题,需要手动进行格式化
# 格式化之前需要做的步骤
1)删除/home/centos/hadoop
xcall.sh rm -rf /home/centos/hadoop
2)重新格式化
hdfs namenode -format
8. 创建xsync脚本¶
# xsync脚本负责同步文件
cp xcall.sh xsync.sh
9. 配置root免密登录¶
#1.
su - root
#2.
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
#3.
ssh-copy-id s101
ssh-copy-id s102
ssh-copy-id s103
ssh-copy-id s104
10. 安装rsync同步命令¶
xcall.sh yum install -y rsync
11. 修改xsync脚本¶
vim xsync.sh
#!/bin/bash
if [ $# -lt 1 ]; then echo 需要参数; exit; fi
dir=`dirname $1`
filename=`basename $1`
cd $dir
for (( i=102; i<=104; i++ )); do
echo ==============s$i $1=====================
rsync -lr $filename `whoami`@s$i:`pwd`
done
1. 测试¶
touch 1.txt
xsync.sh 1.txt
最后更新:
2022-02-20 08:44:07