linux实时同步服务

原理
  • 部署好rsync守护进程服务,实现数据传输备份
  • 部署好inotify服务,实现目录中数据的增量监控
  • 将rsync服务和inotify服务建立联系,实现实时同步

实时同步服务部署

部署rsync守护进程
  • 服务端部署
  • 客户端部署
部署inotify监控服务
1、安装软件  yum install -y inotify-tools
2、查看服务中的文件  rpm -ql inotify-tools
3、熟悉命令
    /usr/bin/inotifywait   ----监控数据变化
    /usr/bin/inotifywatch  ----统计监控信息
    命令结构:   inotifywait 【参数】 监控的目录
            参数:-m|--monitor  ---实时监控目录数据变化
                  -r|--recursive  ---递归监控
                  -q|--quiet  --尽量减少信息输出
                  --format  指定输出的格式
                  --timefmt   ---指定输出时间的格式
                  -e|--event  --指定监控的事件信息
                  
             创建文件监控信息
                1、CREATE   ---文件被创建
                2、OPEN   -----打开创建的文件
                3、ATTRIB  ----修改文件的属性
                4、CLOSE_WRITE,CLOSE   ----保存关闭一个文件
 
 PS:监控的事件:create、delete、move_to移入、close_write修改
inotify参数事件表格说明
事件名称 事件说明
access file or directory contents were read
modify file or directory contents were written
attrib file or directory attributes changed
close_write file or directory closed,after being opened in writeable mode
close_nowrite file or directory closed,after being opened in read-only mode
close fiel or directory closed,regardless of read/write mode
open file or directory opened
moved_to file or directory moved to watched directory
moved_from file or directory moved from watched directory
moved file or directory moved to or form watched directory
create file or directory created within watched directory
delete file or directory deleted within watched directory
delete_self file or directory was deleted
unmount file system containing file or directory unmounted
部署inotify监控服务案例
1、inotifywait -m /data -e CREATE   #只监控create事件

2、inotifywait -mr /data -e CREATE   #递归监控create事件

3、inotifywait -mrq /data -e CREATE   #递归监控create事件,不提示无用的信息

4、inotifywait -mrq --timefmt "%F" --format "%T %w %f" /data -e CREATE   #递归监控create事件+不提示无用的信息+事件格式

5、inotifywait -mrq --timefmt "%F" --format "%T %w %f 事件信息:%e" /data -e CREATE   #递归监控create事件+不提示无用的信息+事件格式+事件说明
                
企业应用
1、防止系统重要的文件被破坏,进行实时监控目录   /etc passwd   /var/spool/cron/root
                
部署sersync同步服务
1、安装sersync软件,不在yum仓库,http://github.com/wsgzao/sersync下载好之后上传  rz -y 要上传的文件   PS:保存在一个专门放置软件包的目录

2、解压,将解压的数据包进行保存    unzip zip包  tree 解压的文件
   mv 解压的文件 /usr/local
   
3、编写配置文件 vim confxml.xml
 
4、启动sersync服务,PS:此处不能使用systemctl启动,因为不是利用yum安装的
    sersync -dro /usr/local/sersync/conf/confxml.xml    #启动服务
    killall 服务名    #停止服务    需要安装使用
    /etc/rc.local <-- /usr/local/sersync/conf/confxml.xml  #开机自启
    
    
    export PATH="$PATH:/usr/local/sersync/bin"   #升级为全局变量
    sersync -h    #帮助文档查看
    参数说明:
            -d:启动守护进程模式
            -r:在监控前,将监控目录与远程主机用rsync命令推送一遍     目的:①保证备份服务器与远程服务器数据一致②同步测试
            -o:指定配置文件,默认使用confxml.xml,可以加载多个配置文件

linux实时同步服务_第1张图片

  • 异常总结
总结

305

你可能感兴趣的:(linux,同步)