rsync远程同步
1.rsync远程同步
1.1 rsync概述
rsync(Remote Sync,远程同步)是一个开源的快速备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,并保持链接和权限,且采用优化的同步算法,传输前执行压缩,因此非常适用于异地备份、镜像服务器等应用。
1.2 下行同步
在远程同步任务中,负责发起rsync同步操作的客户机称为发起端,而负责响应来自客户机rsync同步操作的服务器称为同步源。在同步过程中,同步源负责提供文件的原始位置,发起端应对该位置具有读取权限。
1.3 远程文件同步总结
#远程文件同步
scp rsync svn git(github, gitlab, gitee)
2. 搭建rsync远程文件同步
2.1 搭建rsync远程下行同步
2.1.1 配置rsync服务器端(同步源)
###关闭和禁止防火墙开机自启功能
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/enforcing/disabled/' /etc/selinux/config
(1)查看rsync软件包是否已经安装
rpm -q rsync #一般系统已默认安装rsync
rpm -qc rsync
cat /etc/services | grep rsync
(2)建立/etc/rsyncd.conf配置文件,添加共享模块
vim /etc/rsyncd.conf #添加以下配置项
uid = root
gid = root
use chroot = yes #禁锢在源目录
address = 192.168.80.20 #监听地址
port = 873 #监听端口tcp/udp873,可通过cat /etc/services | grep rsync查看
log file = /var/log/rsyncd.log #日志文件位置
pid file = /var/run/rsyncd.pid #存放进程ID的文件位置
hosts allow = 192.168.80.0/24 #允许访问的客户机地址
dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z #同步时不再压缩的文件类型
[wwwroot] #共享模块名称
path = /var/www/html #源目录的实际路径
comment = Document Root of www.kgc.com
read only = yes #是否为只读
auth users = backuper #授权账户,多个账号以空格分隔
secrets file = /etc/rsyncd_users.db #存放账户信息的数据文件
#如采用匿名的方式,只要将其中的“auth users”和“secrets file”配置项去掉即可。
#为备份账户创建数据文件
----------------------------------------------------------------------------------------------------------
vim /etc/rsyncd.conf
###添加并修改如下内容
uid = root
gid = root
use chroot = yes
address = 192.168.80.20
port = 873
max connections = 4
pid file = /var/run/rsyncd.pid
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
hosts allow = 192.168.80.0/24
[gzy520]
path = /data
comment = gay rsync test dir
read only = yes
auth users = cli
secrets file = /opt/rsyncd_userlist