rsync同步

rsync概述

快速增量备份的工具
remote sync,支持远程同步
支持本地复制,或者与其他SSH,rsync主机同步

常用选项

-a归档模式,递归并保留对象属性,等同于-rlptgoD
-v显示同步过程的详细信息
-z在传输时进行压缩
-H保留硬链接文件
-A保留ACL属性信息
–delete删除目标位置有而原始位置没有的文件
–checksum根据对象的校验和决定是否跳过文件

实操

rsync本地复制

[root@rsync ~]# mkdir /www
[root@rsync ~]# cd /www
[root@rsync www]# touch test test1
[root@rsync www]# mkdir /hhh
[root@rsync www]# rsync -avz /www /hhh				#将/www带目录复制到/hhh下
sending incremental file list
www/
www/test
www/test1

sent 160 bytes  received 58 bytes  436.00 bytes/sec
total size is 0  speedup is 0.00
[root@rsync www]# ls /hhh							#查看结果显示联通目录一起复制
www
[root@rsync www]# rsync -avz /www/ /hhh				#原目录后加上/表示仅复制目录下的文件
sending incremental file list
./
test
test1

sent 148 bytes  received 57 bytes  410.00 bytes/sec		
total size is 0  speedup is 0.00
[root@rsync www]# ls /hhh							#查看结果
test  test1  www

配置源服务器


[root@rsync www]# yum install -y rsync					
[root@rsync www]# vim /etc/rsyncd.conf 					
##删除原本内容,添加以下内容
uid = root											
默认是nobody
gid = root										
use chroot = yes										                                              
address = 192.168.118.100								
port 873                     	                                           
log file = /var/log/rsyncd.log							# 日志文件位置                  
pid file = /var/run/rsyncd.pid	                		# 存放进程id的文件位置
hosts allow = 192.168.118.0/24							
[wwwroot]   					                                                         
path = /var/www/html     		                  		             
comment = Document Root of www.ljm.com	
read only = yes             	 						                              
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z  		
auth users = backuper                                   
secrets file = /etc/users.db 							
[root@rsync ~]# vim /etc/user.db						
whd:abc123
[root@rsync ~]# chmod 600 /etc/user.db 				
[root@rsync ~]# mkdir -p /var/www/html				
[root@rsync ~]# chmod +r /var/www/html/
[root@rsync ~]# ls -ld /var/www/html/
drwxr-xr-x. 2 root root 6 八月 11 05:27 /var/www/html/
[root@rsync ~]# rsync --daemon						#开启服务
[root@rsync ~]# netstat -antp | grep rsync
tcp        0      0 192.168.118.100:873     0.0.0.0:*               LISTEN      88951/rsync  

查看同步
在这里插入图片描述

客户端交互同步
在这里插入图片描述

inotify安装

修改rsync配置文件
在这里插入图片描述

重启服务
在这里插入图片描述
修改客户端参数

[root@client aaa]# vim /etc/sysctl.conf 				
fs.inotify.max_queued_events = 32768					
fs.inotify.max_user_instances = 1024					
fs.inotify.max_user_watches = 1048576					
8192
[root@client aaa]# sysctl -p
fs.inotify.max_queued_events = 32768
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576

安装inotify-tools
在这里插入图片描述

触发同步脚本
在这里插入图片描述

查看

[root@rsync html]# ls
chx.txt
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值