##预备知识
###实时同步概述
#####什么是实时同步
实时同步是一种只要当前目录发生变化则会触发一个事件,事件触发后会将变化的目录同步至远程服务器。
#####为什么要实时同步
保证数据的连续性 ,减少人力维护成本
#####实时同步工具选择 , sersync+RSYNC(√) 、 inotify+rsync Inotify、lsyncd
是一个通知接口,用来监控文件系统的各种变化,如果文件存取,删除,移动。可以非常方便地实现文件异动告警,增量备份,并针对目录或文件的变化及时作出响应。 rsync+inotify可以实触发式实时同步增量备份,sersync是国人基于rsync+inotify‐tools的开发的工具,不仅保留了优点同时还强化了实时监控,文件过滤,简化,配置等功能,帮助用户提高运行效率,节省时间和网络资源。
实时同步实战
案例:实现web上传视频文件,实现是写入NFS至存储,当NFS存在新的数据则会实时的复制到备份服务器
角色 外网IP(NAT) 内网IP(LAN) 安装工具
web01 eth0:10.0.0.7 eth1:172.16.1.7
nfs-server eth0:10.0.0.31 eth1:172.16.1.31 rsync+inotify+sersync
backup eth0:10.0.0.41 eth1L172,16,1.41 rsync-server
配置文件
/app/sersync/conf/confxml.xml
[https://www.processon.com/view/link/5bf911c0e4b006dc83a24929]
[15:53 root@nfs01 ~]#vim /app/sersync/conf/confxml.xml
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <head version="2.5">
3 <host hostip="localhost" port="8008"></host>
4 <debug start="false"/>
5 <fileSystem xfs="false"/> 文件系统\\修改为true
6 <filter start="false"> \\过滤
7 <exclude expression="(.*)\.svn"></exclude> \\排除--exclude
8 <exclude expression="(.*)\.gz"></exclude> \\排除--exclude
9 <exclude expression="^info/*"></exclude> \\排除--exclude
10 <exclude expression="^static/*"></exclude> \\排除--exclude
11 <delete start="true"/>
12 </filter>
13 </inotify> \\配置inotify的监控事件,实时监控目录变量 是否有变化
14 <createFolder start="true"/>
15 <createFile start="false"/>
16 <closeWrite start="true"/>
17 <moveFrom start="true"/>
18 <moveTo start="true"/>
19 <attrib start="false"/> \\文件属性
20 <modify start="false"/> \\mtime修改时间
21 </inotify> \\sersync什么时候用rsync推送
22
23 <sersync>
24 <localpath watch="/opt/tongbu"> \\要监控哪个目录 发生变量
25