电商网站建设目的及网站的优势,肥西网站推广公司,自己开一个网站要多少钱,关于门户网站建设通报rsync是什么#xff1f;
rsync 是一个远程同步工具
下载
你的集群每一台都需要下载#xff01;#xff08;也就是你需要同步的机器#xff09;
yum install -y xsync如果其他不下载就是报错的这样#xff08;使用脚本的情况下#xff0c;注意这里是提示 rsync没有找到…rsync是什么
rsync 是一个远程同步工具
下载
你的集群每一台都需要下载也就是你需要同步的机器
yum install -y xsync如果其他不下载就是报错的这样使用脚本的情况下注意这里是提示 rsync没有找到不是xsync
[rootmaster bin]# xsync /opt/test/master
sending incremental file listsent 97 bytes received 17 bytes 76.00 bytes/sec
total size is 10 speedup is 0.09slave1
bash: rsync: 未找到命令
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: remote command not found (code 127) at io.c(226) [sender3.1.2]slave2
bash: rsync: 未找到命令
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: remote command not found (code 127) at io.c(226) [sender3.1.2]优点与scp对比
优点rsync主要用于备份和镜像。具有速度快、避免复制相同内容和支持符号链接的优点。 与scp对比rsync 要比scp复制速度快因为 rsync 是复制有差异性的文件它会自己检查而scp 则是把所有的文件统一复制过去达到的是一个 统统覆盖的意义
纯命令 Chat- GPT-3.5 演示
rsync 是一个用于文件同步和备份的工具可以在本地或远程系统之间高效地进行文件的复制和同步。以下是 rsync 命令的基本用法示例以及一些常用选项
rsync [options] source destination
其中 source 表示源文件或目录的路径destination 表示目标文件或目录的路径。常用的选项包括
-a归档模式用于保持文件的属性、权限和时间等。
-v详细输出模式显示正在复制的文件和目录。
-r递归复制目录及其内容。
-z传输时压缩数据可以减少传输时间。
--delete删除目标中不存在于源的文件。
--exclude排除指定的文件或目录。
-e指定远程 shell 的路径通常用于远程传输。以下是一些示例
本地文件同步
rsync -av /path/to/source /path/to/destination本地目录同步
rsync -av /path/to/source/ /path/to/destination/从本地到远程服务器同步
rsync -av /path/to/source usernameremote_server:/path/to/destination从远程服务器到本地同步
rsync -av usernameremote_server:/path/to/source /path/to/destination同步时排除特定文件或目录
rsync -av --exclude*.log /path/to/source /path/to/destination使用压缩传输
rsync -avz /path/to/source /path/to/destination请注意rsync 的选项和用法非常丰富你可以根据需要进行组合和定制。在使用之前建议查阅相关文档或执行 man rsync 命令来获取更详细的信息和帮助。
脚本
脚本来自这位仁兄 https://blog.csdn.net/qq_63756815/article/details/127016471 1、在 /bin 目录下创建 xsync文件脚本 2、需要修改的是在 第二步修改为自己的主机名 3、修改 文件权限为 777也可以单加一个可执行权限x chmod 777 xsync 4、
#!/bin/bash#1. 判断参数个数
if [ $# -lt 1 ]
thenecho Not Enough Arguement!exit;
fi#2. 遍历集群所有机器这里记得修改为自己的集群主机名
for host in hadoop102 hadoop103 hadoop104
doecho $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 $pdirrsync -av $pdir/$fname $host:$pdirelseecho $file does not exists!fidone
done演示 脚本
[rootmaster bin]# xsync /opt/test/master
sending incremental file listsent 97 bytes received 17 bytes 76.00 bytes/sec
total size is 10 speedup is 0.09slave1
sending incremental file list
test/
test/a1.txt
test/a2.txtsent 200 bytes received 58 bytes 172.00 bytes/sec
total size is 10 speedup is 0.04slave2
sending incremental file list
test/
test/a1.txt
test/a2.txtsent 200 bytes received 58 bytes 516.00 bytes/sec
total size is 10 speedup is 0.04
纯命令:
[rootmaster bin]# echo 2222 /opt/test/a2.txt
[rootmaster bin]# rsync -av /opt/test/ slave1:/opt/test/
sending incremental file list
a2.txtsent 137 bytes received 41 bytes 118.67 bytes/sec
total size is 10 speedup is 0.06
这里 我专门试了试会不会自动给我创建目录因为我没学过脚本发现是会的 但是 如果是纯命令的话你必须和scp命令相同的语法就是绝对路径且只会复制文件