当前位置: 首页 > news >正文

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服务器:

      图片

      http://www.dtcms.com/a/507491.html

      相关文章:

    • ppt模板去哪个网站下载德州核酸检测最新公告
    • 迅为RK3568开发板OpenHarmony系统南向驱动开发手册-UART应用开发编译源码
    • java面试-0216-HashMap和LinkedHashMap、TreeMap、HashTable√、ConcurrentHashMap区别?
    • 【文献分享】KADAIF:一种针对复杂微生物组数据的异常检测方法
    • React Native开发AndroidIOS流程完整指南
    • 身份证实名认证接口在金融领域的应用:筑牢风控第一道防线
    • 视频图像数据接入指南
    • STM32H743-ARM例程24-USB_MSC
    • asp网站防注入代码有源码搭建网站难不难
    • go语言每日3题
    • Mysql 坏表修复
    • 烟台专业网站建设湘潭网页设计
    • 网站按抓取手机软件贵阳wordpress 编程模式
    • Rust 结构体
    • 【2026计算机毕业设计】基于Springboot的微信小程序的古诗词在线学习系统
    • 基于微信小程序的运动康复中心预约系统的设计与实现(SpringBoot+Vue+Uniapp)
    • 微信小程序中使用 Vant Weapp 组件库
    • JAVA无人共享台球杆台球柜系统球杆柜租赁系统源码支持微信小程序
    • c 网站开发程序员网站建设 收费明细
    • dockerfile中CMD和ENTRYPOINT指令
    • 用服务器自建一套无界白板 + 文档协作平台 —— Affine
    • docker可视化面板portainer忘记密码的解决方案
    • Spring 4.1新特性:深度优化与生态整合
    • 湛江网站建设外包网站开发公司报价单模板
    • 画册设计公司网站优书网注册
    • 中国风手机网站模板html自动播放视频
    • 汇编与底层编程笔记
    • 酒店网站建设的需求分析报告做外贸网站赚钱吗
    • 物联网异构设备协同运维中的服务依赖动态解析与容错机制
    • 技术人互助:城市级充电系统(Java 微服务)的落地细节,含 demo 和设备适配经验