linux 综合架构实时同步服务
实时同步服务原理/概念
需要部署好rsync守护进程服务,实现数据传输
需要部署好inotify服务,实现目录中数据变化监控
将rsync服务和inotify服务建立联系,将变化的数据进行实时备份传输
实现实时同步的原理
- 
监控目录数据变化 --- inotify
 - 
将数据进行传输 --- rsync
 - 
将监控和传输进行整合 --- sersync
 
实现实时同步部署方法
- 
1. 部署rsync守护进程
 - 
2. 部署inotify软件
 - 
3. 部署sersync软件
 
实时同步服务部署 inotify
部署rsync守护进程
- 
服务端配置操作
 - 
客户端配置操作
 
部署inotify监控服务
yum install -y inotify-tools
熟悉命令的使用
- 
/usr/bin/inotifywait --- 监控目录数据信息变化
 - 
/usr/bin/inotifywatch --- 对监控的变化信息进行统计
 
rpm -ql inotify-tools

inotifywait [参数] 监控的目录
- 
-m|--monitor --- 实现一直监控目录的数据变化
 - 
-r|--recursive --- 进行递归监控
 - 
-q|--quiet --- 尽量减少信息的输出
 - 
--format <fmt> --- 指定输出信息的格式
 - 
--timefmt --- 指定输出的时间信息格式
 - 
-e|--event --- 指定监控的事件信息
 - -d 守护进程
 
监控的事件

企业 inotify 监控命令格式
inotifywait -mrq --timefmt "%F" --format "%T %w %f 事件信息:%e" /data -e C
部署sersync同步服务
第一个里程:需要下载,保留上传到linux服务器中
https://github.com/wsgzao/sersync
第二个里程:解压软件压缩包,将解压的数据进行保存
unzip sersync_installdir_64bit.zip tree sersync_installdir_64bit

移动到用户自定义安装第三方程序目录
mv sersync_installdir_64bit/sersync/ /usr/local/
第三个里程:编写配置文件 conf/confxml.xml
6 <filter start="false"> 7 <exclude expression="(.*)\.svn"></exclude> 8 <exclude expression="(.*)\.gz"></exclude> 9 <exclude expression="^info/*"></exclude> 10 <exclude expression="^static/*"></exclude> 11 </filter> 说明:排除指定数据信息不要进行实时传输同步 12 <inotify> 13 <delete start="true"/> 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"/> 21 </inotify> 说明:定义inotify程序需要监控的事件 24 <localpath watch="/opt/tongbu"> 25 <remote ip="127.0.0.1" name="tongbu1"/> 26 <!--<remote ip="192.168.8.39" name="tongbu"/>--> 27 <!--<remote ip="192.168.8.40" name="tongbu"/>--> 28 </localpath> 29 <rsync> 30 <commonParams params="-artuz"/> 31 <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> 32 <userDefinedPort start="false" port="874"/><!-- port=874 -->
配置文件格式参考图

第四个里程:启动sersync服务程序
sersync 参数
- 
参数-d: 启用守护进程模式
 - 
参数-r: 在监控前,将监控目录与远程主机用rsync命令推送一遍
 - 
进行同步测试
 - 
参数-o: 指定配置文件,默认使用confxml.xml文件
 - 
-o /usr/local/sersync/conf/confxml.xml
 - 
-o /usr/local/sersync/conf/confxml02.xml
 
添加命令路径
export PATH="$PATH:/usr/local/sersync/bin"

启动实时同步服务
sersync -dro /usr/local/sersync/conf/confxml.xml
停止实时同步服务
centos7 默认没有 killall 命令需要安装包,查找 kill 属于哪个大礼包
yum provides killall

安装 psmics 包
yum install -y psmisc
停止 sersync 服务
killall sersync
设置开机自动启动
/etc/rc.local <-- sersync -dro /usr/local/sersync/conf/confxml.xml

                
            
        
浙公网安备 33010602011771号