rsync+sersync实现数据实时双向同步

1、部署规划

|---------------|----------------------|-----|---------------|
| ip地址 | 同步目录 | 端口 | 安装软件 |
| 192.168.52.15 | /data/ftp /data/sftp | 873 | rsync、sersync |
| 192.168.52.16 | /data/ftp /data/sftp | 873 | rsync、sersync |

2、安装rsync

yum -y install rsync

vim /etc/rsyncd.conf

uid=root

gui=root

auth users = rsyncuser

secrets file = /etc/rsync.password

port=873

tongbu

comment = tongbu

path = /data

read only = no

3、创建密码文件,启动rsync

vi /etc/rsync.password

rsyncuser:123456

chmod 600 /etc/rsync.password

systemctl restart rsyncd

4、客户端配置

yum -y install rsync

vi /etc/rsyncd_users.pas

123456

chmod 600 /etc/rsyncd_users.pas

验证同步:

rsync -avz /data rsyncuser@192.168.52.15::tongbu --password-file=/etc/rsyncd_users.pas

rsync -avz /data rsyncuser@192.168.52.16::tongbu --password-file=/etc/rsyncd_users.pas

5、双向同步部署

1.安装sersync

cd /root

sersync下载地址:

wget --no-check-certificate https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz

tar -xzf sersync2.5.4_64bit_binary_stable_final.tar.gz

mv GNU-Linux-x86 sersync

mv sersync /usr/local/

2.配置sersync

cd /usr/local/sersync/

cp confxml.xml confxml.xml-bak

192.168.52.15配置:

复制代码
vi /usr/local/sersync/confxml.xml<?xml version="1.0" encoding="ISO-8859-1"?><head version="2.5">    <host hostip="localhost" port="8008"></host>    <debug start="false"/>    <fileSystem xfs="false"/>    <filter start="false"> <exclude expression="(.*)\.svn"></exclude> <exclude expression="(.*)\.gz"></exclude> <exclude expression="^info/*"></exclude> <exclude expression="^static/*"></exclude>    </filter>    <inotify> <delete start="true"/> <createFolder start="true"/> <createFile start="true"/> <closeWrite start="true"/> <moveFrom start="true"/> <moveTo start="true"/> <attrib start="true"/> <modify start="true"/>    </inotify>     <sersync> <localpath watch="/data">     <remote ip="192.168.52.16" name="tongbu"/>     <!--<remote ip="192.168.8.39" name="tongbu"/>-->     <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync>     <commonParams params="-artuz"/>     <auth start="true" users="rsyncuser" passwordfile="/etc/rsyncd_users.pas"/>     <userDefinedPort start="false" port="874"/><!-- port=874 -->     <timeout start="false" time="100"/><!-- timeout=100 -->     <ssh start="false"/> </rsync> <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> <crontab start="false" schedule="600"><!--600mins-->     <crontabfilter start="false">  <exclude expression="*.php"></exclude>  <exclude expression="info/*"></exclude>     </crontabfilter> </crontab> <plugin start="false" name="command"/>    </sersync>     <plugin name="command"> <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix--> <filter start="false">     <include expression="(.*)\.php"/>     <include expression="(.*)\.sh"/> </filter>    </plugin>     <plugin name="socket"> <localpath watch="/opt/tongbu">     <deshost ip="192.168.138.20" port="8009"/> </localpath>    </plugin>    <plugin name="refreshCDN"> <localpath watch="/data0/htdocs/cms.xoyo.com/site/">     <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>     <sendurl base="http://pic.xoyo.com/cms"/>     <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> </localpath>    </plugin></head>

192.168.52.16配置:

复制代码
vi /usr/local/sersync/confxml.xml<?xml version="1.0" encoding="ISO-8859-1"?><head version="2.5">    <host hostip="localhost" port="8008"></host>    <debug start="false"/>    <fileSystem xfs="false"/>    <filter start="false"> <exclude expression="(.*)\.svn"></exclude> <exclude expression="(.*)\.gz"></exclude> <exclude expression="^info/*"></exclude> <exclude expression="^static/*"></exclude>    </filter>    <inotify> <delete start="true"/> <createFolder start="true"/> <createFile start="true"/> <closeWrite start="true"/> <moveFrom start="true"/> <moveTo start="true"/> <attrib start="true"/> <modify start="true"/>    </inotify>     <sersync> <localpath watch="/data">     <remote ip="192.168.52.15" name="tongbu"/>     <!--<remote ip="192.168.8.39" name="tongbu"/>-->     <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync>     <commonParams params="-artuz"/>     <auth start="true" users="rsyncuser" passwordfile="/etc/rsyncd_users.pas"/>     <userDefinedPort start="false" port="874"/><!-- port=874 -->     <timeout start="false" time="100"/><!-- timeout=100 -->     <ssh start="false"/> </rsync> <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> <crontab start="false" schedule="600"><!--600mins-->     <crontabfilter start="false">  <exclude expression="*.php"></exclude>  <exclude expression="info/*"></exclude>     </crontabfilter> </crontab> <plugin start="false" name="command"/>    </sersync>     <plugin name="command"> <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix--> <filter start="false">     <include expression="(.*)\.php"/>     <include expression="(.*)\.sh"/> </filter>    </plugin>     <plugin name="socket"> <localpath watch="/opt/tongbu">     <deshost ip="192.168.138.20" port="8009"/> </localpath>    </plugin>    <plugin name="refreshCDN"> <localpath watch="/data0/htdocs/cms.xoyo.com/site/">     <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>     <sendurl base="http://pic.xoyo.com/cms"/>     <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> </localpath>    </plugin></head>

3、设置sersync监控开机自动执行

cat /etc/rsyncd_users.pas #sersync密码文件

123456

chmod 600 /etc/rsyncd_users.pas

启动sersync:

/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml

4、配置systemd启动sersync服务

vim /etc/systemd/system/sersync.service

Unit

Description=Sersync File Synchronization Service

After=network.target

Service

Type=simple

User=root

ExecStart=/usr/local/sersync/sersync2 -r -o /usr/local/sersync/confxml.xml

Restart=on-failure

RestartSec=5

Install

WantedBy=multi-user.target

systemctl daemon-reload

systemctl start sersync

systemctl enable sersync

systemctl status sersync

5、在客户机监测数据同步

yum install strace -y

strace /usr/local/sersync/sersync2 -r -o /usr/local/sersync/confxml.xml

6、验证文件同步

192.168.52.15服务器:

192.168.52.16服务器:

相关推荐
礼拜天没时间.2 个月前
Rsync + Rsyncd 从入门到项目实战:自动化备份全攻略
linux·centos·rsync·文件传输·rsyncd
❀͜͡傀儡师2 个月前
对于Linux下的海量文件传输,rsync 是远比 scp 更优。
linux·运维·网络·rsync
神秘人X7072 个月前
Linux高效备份:rsync + inotify实时同步
linux·服务器·rsync
小任今晚几点睡2 个月前
防火墙环境下的全网服务器数据自动化备份平台搭建:基于 rsync 的完整实施指南
服务器·shell·rsync·自动化备份
Johny_Zhao2 个月前
Rsync + Sersync 实时数据同步方案
linux·网络安全·信息安全·云计算·rsync·系统运维·sersync
chen_note3 个月前
Linux网络信息(含ssh服务和rsync)
linux·运维·服务器·网络·ssh·远程工作·rsync
虔诚的教徒3 个月前
Sersync和Rsync部署
rsync·sersync
孙克旭_4 个月前
day033-备份服务rsync
linux·运维·rsync
遇见火星5 个月前
【运维实战】Rsync将一台主Web服务器上的文件和目录同步到另一台备份服务器!
运维·服务器·github·rsync