xsync集群分发脚本
1.安装 rsync远程同步工具
yum install -y rsync
2.需要在etc/hosts 中添加映射 (每台都配置)
vim /etc/hosts # 添加相关hosts映射 192.168.175.51 hadoop51 192.168.175.52 hadoop52 192.168.175.53 hadoop53
3.配置ssh免密
# 在hadoop51上配置免密 rm -rf /root/.ssh ssh-keygen cd /root/.ssh mv id_rsa.pub authorized_keys scp -r /root/.ssh 192.168.175.52:/root scp -r /root/.ssh 192.168.175.53:/root
4.编写xsync脚本
vim /scripts/xsync #!/bin/bash #1. 判断参数个数 if [ $# -lt 1 ] then echo Not Enough Arguement! exit; fi #2. 遍历集群所有机器 for host in hadoop51 hadoop52 hadoop53 # 注意修改hosts对应解析 do echo ==================== $host ==================== #3. 遍历所有目录,挨个发送 for file in $@ do #4. 判断文件是否存在 if [ -e $file ] then #5. 获取父目录 pdir=$(cd -P $(dirname $file); pwd) #6. 获取当前文件的名称 fname=$(basename $file) ssh $host "mkdir -p $pdir" rsync -av $pdir/$fname $host:$pdir else echo $file does not exists! fi done done
5.赋予执行脚本执行权限
chmod +x /scripts/xsync
6.复制脚本到bin目录下
cp /scripts/xsync /bin/
7.测试
xsync /usr/local/src/kafka