您的位置:首页 > 房产 > 家装 > 免费网站免费网站平台_商标注册申请入口_自动外链工具_人工智能培训师

免费网站免费网站平台_商标注册申请入口_自动外链工具_人工智能培训师

2024/10/5 16:09:04 来源:https://blog.csdn.net/qq_38448681/article/details/142638256  浏览:    关键词:免费网站免费网站平台_商标注册申请入口_自动外链工具_人工智能培训师
免费网站免费网站平台_商标注册申请入口_自动外链工具_人工智能培训师

rsync+sersync实现数据文件实时同步

文章目录

    • rsync+sersync实现数据文件实时同步
      • 手动同步
      • 实时同步
        • 备份端主机安装rsync服务
        • 数据源主机安装sersync服务实现实时备份

sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字;

rsync在同步的时候,只同步发生变化的这个文件或者这个目录(每次发生变化的数据相对整个同步目录数据来说是很小的,rsync在遍历查找比对文件时,速度很快),因此,效率很高。

rsync 监听的端口:873

手动同步

备份本机的/var/www/html 目录 到zyj87主机的/web-back目录下

rsync -avzP --delete /var/www/html root@192.168.3.87:/web-back

备份本机的/var/www/html 目录中的文件 到zyj87主机的/web-back目录下

rsync -avzP --delete /var/www/html/ root@192.168.3.87:/web-back

rsync拷备时需要输入密码,可以生成ssh秘钥对免密备份。

注意: 要备份端的目录必须存在,否则报错

实时同步

备份本机的/var/www/html/ 目录中文件 到zyj87主机的/web-back目录下

192.168.3.86 数据源 运行sersync服务 /var/www/html/ —> 192.168.3.87 备份端 运行rsync服务 /web-back

备份端主机安装rsync服务
yum install rsync -y

创建一个新的配置文件,定义模块和同步选项

vim /etc/rsyncd.conf
uid = root
git = root
hosts allow =192.168.3.0/24
use chroot = yes
max connections = 10
pid file = /var/run/rsyncd.pid
lock ifle = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[wwwroot]path = /web-bak/read only = falselist = yesauth users = lixinsecrets file = /etc/lixin.txt

创建密码文件/etc/lixin.txt,其中包含auth users定义的用户和密码。

vim /etc/lixin.txt
#写入用户名和密码
lixin:123456

修改密码文件的权限为600,只有所有者可以读写。

chmod 600 /etc/lixin.txt

以后台启动rsync

/usr/bin/rsync --daemon --config=/etc/rsyncd.conf

数据源端创建密码文件

vim /etc/lixin.txt
#写入lixin的密码
123456

修改密码文件的权限为600,只有所有者可以读写。

chmod 600 /etc/lixin.txt

数据源端手动推送命令,测试能否推送成功

rsync -avzP --port=873 --delete /var/www/html/ lixin@192.168.3.87::wwwroot --password-file=/etc/lixin.txt
数据源主机安装sersync服务实现实时备份
rz sersync2.5.4_64bit_binary_stable_final.tar.gz
tar -xf sersync2.5.4_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86/ sersync && mv sersync /usr/local/
ln -s /usr/local/sersync/sersync2 /usr/bin/sersync2

修改sersync配置文件

vim /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="false"/><closeWrite start="true"/><moveFrom start="true"/><moveTo start="true"/><attrib start="false"/><modify start="false"/></inotify><sersync><localpath watch="/var/www/html/"> #修改文本机要被同步的文件夹,实时监控此文件夹并推送到87主机<remote ip="192.168.3.87" name="wwwroot"/>  #wwwroot为备份端的模块名称<!--<remote ip="192.168.8.39" name="tongbu"/>--><!--<remote ip="192.168.8.40" name="tongbu"/>--></localpath><rsync><commonParams params="-artuz"/>              #设置lixin用户的密码文件<auth start="true" users="lixin" passwordfile="/etc/lixin.txt"/> <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>

以后台启动sersync

sersync2 -rod /usr/local/sersync/confxml.xml

观察是否数据同步

[root@localhost html]# tree /var/www/html/
/var/www/html/
├── 2.txt
├── 3.txt
└── 4.txt#删除数据源端 4.txt ,观察备份端是否也被删除
rm -rf 4.txt#以被删除
[root@localhost web-bak]# ls
2.txt  3.txt  4.txt
[root@localhost web-bak]# ls
2.txt  3.txt

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com