Rsync数据同步

目标端配置:

一、安装

yum -y install rsync

二、配置文件

vi /etc/rsyncd.conf

用户id

uid = rsync

组id

gid = rsync

程序安全设置

use chroot = no

客户端连接数

max connections = 200

进程号文件位置

pid file = /var/run/rsyncd.pid

进程锁文件位置

lock file = /var/run/rsync.lock

日志文件位置

log file = /var/run/rsyncd.log

连接超时时间

timeout = 300

3.1版本以上要加这个

fake super = yes

模块名称

[hw_uat_nfs]

同步数据的目录,源端文件需要保持rsync用户属主属组

path = /data/platform/

有错误时忽略

ignore errors

只读模式(true为只读,false为可读可写)

read only = false

阻止远程列表

list = false

允许访问的IP

hosts allow = *

禁止访问的IP

hosts deny = 0.0.0.0/32

虚拟用户

auth user = rsync_backup

存放用户和密码的文件

secrets file = /etc/rsync.password

三、创建密码文件vi /etc/rsync.password

rsync_backup:123456

四、文件授权

chmod 600 /etc/rsync.password

五、创建程序用户

useradd -M -s /sbin/nologin rsync

mkdir /data/platform/ && chown -R rsync.rsync /data/platform/

六、启动访问

systemctl start rsyncd && systemctl restart rsyncd && systemctl status rsyncd

源端全量同步配置:
yum -y install rsync

一、新增密码文件vi /etc/rsync.password

123456

二、文件授权

chmod 600 /etc/rsync.password

三、传输测试

rsync -zav projectTemplate.zip rsync_backup@152.136.150.253::hw_uat_nfs --password-file=/etc/rsync.password

源端增量同步配置:

一、安装服务

yum -y install lsyncd

二、配置lsyncd.conf

vim /etc/lsyncd.conf

settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
inotifyMode = "CloseWrite",
maxProcesses = 8,
maxDelays = 1,
nodaemon = false,
}
sync {
default.rsync,
source = "/data/platform/", --监控目录
target = "rsync_backup @152.136.150.253::hw_uat_nfs", --rsync的认证用户名、IP、模块
delete = true, --删除时是否也要出发备份事件
delay = 15,
init = false,
rsync = {
binary = "/usr/bin/rsync", --rsync可执行文件路径,必须为绝对路径
password_file = "/etc/rsync.password", --密码认证文件
archive = true,
compress = false,
verbose = false,
_extra = {"--bwlimit=200", "--omit-link-times"}
}
}
三、创建日志文件

touch /var/log/lsyncd/lsyncd.log
touch /var/log/lsyncd/lsyncd.status

chmod 600 /var/log/lsyncd/lsyncd.log
chmod 600 /var/log/lsyncd/lsyncd.status

四、启动lsyncd
systemctl start lsyncd

systemctl restart rsyncd

systemctl enable lsyncd#开机启动

五、查看日志
cat /var/log/lsyncd/lsyncd.log

posted @   weizongze  阅读(15)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示