[root@node-etl-01 bin]# yum install rsync -y
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 10:53:14 ago on Mon Nov 1 09:17:41 2021.
Dependencies resolved.
=====================================================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================================================
Installing:
rsync x86_64 3.1.3-12.el8 baseos 405 k
Transaction Summary
=====================================================================================================================================================
Install 1 Package
Total download size: 405 k
Installed size: 819 k
Downloading Packages:
rsync-3.1.3-12.el8.x86_64.rpm 372 kB/s | 405 kB 00:01
-----------------------------------------------------------------------------------------------------------------------------------------------------
Total 253 kB/s | 405 kB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : rsync-3.1.3-12.el8.x86_64 1/1
Running scriptlet: rsync-3.1.3-12.el8.x86_64 1/1
Verifying : rsync-3.1.3-12.el8.x86_64 1/1
Installed:
rsync-3.1.3-12.el8.x86_64
Complete!
[root@node-etl-01 bin]# cd /root
[root@node-etl-01 ~]# mkdir bin
[root@node-etl-01 bin]# cat xsync
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
#2 获取当前用户名
user=$(whoami)
#3. 遍历集群所有机器
for((host=1; host<=3; host++))
do
echo ==================== node-etl-0$host ====================
#4. 遍历所有目录,挨个发送
for file in $@
do
#5 判断文件是否存在
if [ -e $file ]
then
#6. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#7. 获取当前文件的名称
fname=$(basename $file)
ssh $user@node-etl-0$host "mkdir -p $pdir"
rsync -av $pdir/$fname $user@node-etl-0$host:$pdir
else
echo $file does not exists!
fi
done
done
[root@node-etl-01 bin]# chmod +x xsync
[root@node-etl-01 bin]# xsync xsync
==================== node-etl-01 ====================
sending incremental file list
sent 44 bytes received 12 bytes 112.00 bytes/sec
total size is 695 speedup is 12.41
==================== node-etl-02 ====================
sending incremental file list
xsync
sent 786 bytes received 35 bytes 1,642.00 bytes/sec
total size is 695 speedup is 0.85
==================== node-etl-03 ====================
sending incremental file list
xsync
sent 786 bytes received 35 bytes 1,642.00 bytes/sec
total size is 695 speedup is 0.85
[root@node-etl-01 bin]# yum install rsync -yFailed to set locale, defaulting to C.UTF-8Last metadata expiration check: 10:53:14 ago on Mon Nov 1 09:17:41 2021.Dependencies resolved.=====================================================================.