背景:测试环境静态文件经常会因为找不到,需要将线上的静态文件实时同步至测试环境;
测试环境地址:192.168.0.1
线上环境地质:192.168.0.2
由192.168.0.2地址向192.168.0.1实时同步文件
系统:centos7.6
一:目标节点安装rsync
1、在192.168.0.1安装rsync,yum install -y rsync
编辑/etc/rsyncd.conf配置文件
#/etc/rsyncd.conf
#静态资源图片文件线上同步至测试环境
uid = root
gid = root
use chroot = no
max connections = 200
timeout = 600
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
ignore errors
read only = false
list = yes
#允许同步节点
hosts allow = 192.168.0.2/32
host deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
transfer logging = yes
#Module definitions
#定义模块名
[betastatic]
comment = beta-static
path = /static/public
备注:/etc/rsync.password如下,且chmod 600 /etc/rsync.password
启动命令:/usr/bin/rsync --daemon /etc/rsyncd.conf
二、源节点安装sersync2
下载sersync http://sersync.googlecode.com/files/sersync2.1_64bit_binary.tar.gz
解压文件至/opt/sersync/目录下
编辑/opt/sersync/confxml.xml,红色框内地址,模块名,同步用户,及密钥文件对应
备注:/etc/rsync.password1如下,chmod 600 /etc/rsync.password1 不需要用户,只需填写密码即可:
启动命令:/opt/sersync/sersync2 -r -d -o /opt/sersync/confxml.xml