源主机和目的主机都要安装rsync,需要检测文件变化的主机安装lsyncd
yum install epel-release -y && yum install rsync -y
yum install epel-release -y && yum install lsyncd -y
rsync 用于同步文件
lsyncd 用于监控文件变化
目的主机需要开启rsync,并采用后台守护方式进行启动
uid = root
gid = root
use chroot = no
max connections = 20
pid file = /var/run/rsyncd.pid
log file = /var/log/rsync.log
lock file = /var/run/rsyncd.lock
exclude = lost+found/
reverse lookup = no
timeout = 900
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
[jenkins]
path = /data/jenkins/
read only = no
auth users = ysrd_backup
secrets file = /etc/rsyncd.password
list = no
格式:账号:密码
文件权限:600
echo '账号:密码' > /etc/rsyncd.password && chmod 600 /etc/rsyncd.password
systemctl start rsyncd
systemctl enable rsyncd
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
pidfile = "/var/run/lsyncd.pid",
statusFile = "/var/log/lsyncd/lsyncd.status",
statusInterval = 5,
nodaemon = false,
inotifyMode = "CloseWrite or Modify",
maxProcesses = 5,
maxDelays = 1,
inist = ture,
}
sync {
default.rsync,
source = "/home/jenkins/",
target = "backup_username@xx.xx.xx.xx::jenkins",
exclude = { "workspace/**", "logs/**" },
delay = 3,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
password_file = "/etc/rsync.password",
}
}
格式:账号:密码
文件权限:600
echo '密码' > /etc/rsync.password && chmod 600 /etc/rsync.password
systemctl start rsyncd
systemctl enable rsyncd
注意:云主机rsync需要开通873端口
两边各自配置rsync和lsync即可,等单向同步结束后再进行配置