一、场景应用:                           

        客户通过url访问资源(查询,下载等),并发量是非常高的,所以运用负载均衡分担web服务器的压力,在后端连接不同的NFS备份服务器,同样也是分担压力;那么在同步nfs服务器上的资源的时候,我们需要实时的同步到备份服务器上,这样用户才能使用这些资源,传统的定时任务,我们知道最快1分钟,同步一次,这是无法忍受的,所以我们用inotity进行实时的同步。

二、inotify+rsync组合的起源

Rsync远程同步工具可以进行数据的同步,但是在数据量非常庞大的今天,如果要实现两边的数据一致,rsync是支持的,那么就要进行数据的对比,但是在对比中发现,变化的数据只是一小部分,而且对比又是比较耗时,所以这里就出现了rsync的瓶颈,inotify的出现,缓解rsync的不足之处,实现实时同步。

三、Inotify的工作机制

        Inotify是一种强大的,细粒度的,异步的文件系统事件监控机制。

 四、启发:inotify可以监控目录的变化,那么变化后,既然可以触发同步rsync,那么同样可以触发发送邮件、打电话等,用处多多!!!

五、安装inotify

   1.首先inotify的实现软件有很多,这里说两种:

1)inotify自身    简单                          2)sercync 国内软件开发,功能强大,可以做过滤

在性能上intofy大于sersyrc

2.安装前置条件:

1)版本必须大于2.6.13

2)有/proc/sys/fs/inotify

 

3.源码下载,源码安装:

  • mkdir -p /home/oldboy/tools/
  • cd  /home/oldboy/tools/
  • wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz --no-check-certificate
  • tar xf inotify-tools-3.14.tar.gz
  •      cd inotify-tools-3.14
  • ./configure --prefix=/usr/local/inotify-tools-3.14(安装出错,因为没有安装yum install gcc)-----》配置参数的安装和安装目录的指定
  •       [root@djw1 inotify-tools-3.14]# echo $?      0   ====》检查没有出错了!!!!
  •       make&&make install  -->编译成机器认识的语言 make成功在进行make install 安装
  • ls  -s   /usr/local/inotify-tools-3.14   /usr/local/inotify   ---->软链接

 六、配置参数 :cd /usr/local/inotify

   

1)bin   inotify执行命令     2)include  inotify头文件    3)lib  动态链接的库文件(系统调用)    4)share 帮助文档

       有两个命令要注意;inotifywait(监听事件)、inotifywatch

       inotifywait配置参数:建议用的时候熟练,多多看帮忙文档,如下:

文档参数:

 [root@djw1 inotify]# ./bin/inotifywait --help

inotifywait 3.14
Wait for a particular event on a file or set of files.
Usage: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ ... ]
Options:
        -h|--help       Show this help text.
        @<file>         Exclude the specified file from being watched.
        --exclude <pattern>
                        Exclude all events on files matching the
                        extended regular expression <pattern>.
        --excludei <pattern>
                        Like --exclude but case insensitive.
        -m|--monitor    Keep listening for events forever.  Without
                        this option, inotifywait will exit after one
                        event is received.
        -d|--daemon     Same as --monitor, except run in the background
                        logging events to a file specified by --outfile.
                        Implies --syslog.
        -r|--recursive  Watch directories recursively.
        --fromfile <file>
                        Read files to watch from <file> or `-' for stdin.
        -o|--outfile <file>
                        Print events to <file> rather than stdout.
        -s|--syslog     Send errors to syslog rather than stderr.
        -q|--quiet      Print less (only print events).
        -qq             Print nothing (not even events).
        --format <fmt>  Print using a specified printf-like format
                        string; read the man page for more details.
        --timefmt <fmt> strftime-compatible format string for use with
                        %T in --format string.
        -c|--csv        Print events in CSV format.
        -t|--timeout <seconds>
                        When listening for a single event, time out after
                        waiting for an event for <seconds> seconds.
                        If <seconds> is 0, inotifywait will never time out.
        -e|--event <event1> [ -e|--event <event2> ... ]
                Listen for specific event(s).  If omitted, all events are
                listened for.
Exit status:
        0  -  An event you asked to watch for was received.
        1  -  An event you did not ask to watch for was received
              (usually delete_self or unmount), or some error occurred.
        2  -  The --timeout option was given and no events occurred
              in the specified interval of time.
Events:
        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           file 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
        move            file or directory moved to or from 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
七、人工测试监听事件:inotifywait
     命令:   /usr/local/inotify/bin/inotifywait  -mrq --timefmt '%Y/%m/%d %H:%M' --format '%T %w%f' -e create,delete,close_write  /backup
 

这里要注意:close_write 监控的是写入文件的内容,只要写入就会被监听到,但是如果创造文件,也是一种写入,所以有create存在,就会有两个事件,如下:

八、简单脚本:

[root@djw1 scripts]# vim inotify.sh  
#!/bin/bash
path="/usr/local/inotify/bin/inotifywait"
$path -mrq --format '%w%f' -e create,delete,close_write  /backup |\
while read line
do
  rsync -az $line  rsync_backup@192.168.0.103::oldboy --password-file=/etc/rsync.password
done

测试成功!!!

九、inotity的缺点:

1)并发不能大于200个文件(10-100k的文件)

二十九、rsync+inotity实时监控同步工具的更多相关文章

  1. VMwarevSphere 服务器虚拟化之二十九 桌面虚拟化之安装View副本服务器

    VMwarevSphere 服务器虚拟化之二十九  桌面虚拟化之安装View副本服务器 VMware View中高可用性可是一个必须要考虑的问题.在整个虚拟桌面环境中View Connection S ...

  2. rsync+inotify实时数据同步多目录实战

    rsync+inotify实时数据同步多目录实战       inotify配置是建立在rsync服务基础上的配置过程 操作系统 主机名 网卡eth0 默认网关 用途 root@58server1 1 ...

  3. rsync+inotify实时数据同步单目录实战

    rsync+inotify实时数据同步单目录实战   rsync+inotify实时数据同步单目录实战 inotify是一个强大的.细粒度的.异步的文件系统事件监控机制,linux内核从2.6.13起 ...

  4. Web 开发人员和设计师必读文章推荐【系列二十九】

    <Web 前端开发精华文章推荐>2014年第8期(总第29期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各类能够提升网站用户体验的优秀 jQuery 插件,展示前沿的 HTML5 ...

  5. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】原创教程连载导读【连载完成,共二十九章】

    前言: 无数昼夜的来回轮替以后,这本<驱动篇I>终于编辑完毕了,笔者真的感动到连鼻涕也流下来.所谓驱动就是认识硬件,还有前期建模.虽然<驱动篇I>的硬件都是我们熟悉的老友记,例 ...

  6. 使用Typescript重构axios(二十九)——添加baseURL

    0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...

  7. Bootstrap <基础二十九>面板(Panels)

    Bootstrap 面板(Panels).面板组件用于把 DOM 组件插入到一个盒子中.创建一个基本的面板,只需要向 <div> 元素添加 class .panel 和 class .pa ...

  8. WCF技术剖析之二十九:换种不同的方式调用WCF服务[提供源代码下载]

    原文:WCF技术剖析之二十九:换种不同的方式调用WCF服务[提供源代码下载] 我们有两种典型的WCF调用方式:通过SvcUtil.exe(或者添加Web引用)导入发布的服务元数据生成服务代理相关的代码 ...

  9. Bootstrap入门(二十九)JS插件6:弹出框

    Bootstrap入门(二十九)JS插件6:弹出框 加入小覆盖的内容,像在iPad上,用于存放非主要信息 弹出框是依赖于工具提示插件的,那它也和工具提示是一样的,是需要初始化才能够使用的 首先我们引入 ...

随机推荐

  1. 关于构造函数中的this()和super()

    今天看到一个这段代码 public DataSourcePool(String driver, String url, String user, String pwd) throws Exceptio ...

  2. offsetof宏与container_of宏

    offsetof宏与container_of宏1.由结构体指针进而访问各元素的原理(1)通过结构体整体变量来访问其中各个元素,本质上是通过指针方式来访问的,形式上是通过.的方式来访问的(这个时候其实是 ...

  3. 81.常用的返回QuerySet对象的方法使用详解:values和values_list

    values: 指定提取的数据库表中的字段值,如果不指定任何的字段名的话,默认情况下会提取所有的字段值.但是需要注意的是使用values返回的QuerySet对象中包括的是一个个的字典. 1.提取与A ...

  4. 当我们进行综合和I/O布局后会发生什么QwQ

    基于的平台是Vivado 2018.2 本文主要以一个简单的半加器加器(组合逻辑为例)学习vivado的综合,I/O配置的一些内容. 本人小白,记一些自己的理解. 任务: 分析Log文件. 布局I/O ...

  5. 《打造扛得住的MySQL数据库架构》第4章 MySQL数据库结构优化

    4-1 数据库结构优化介绍 良好的数据库逻辑设计和物理设计是数据库获得高性能的基础. 1.减少不必要的数据冗余. 2.尽量避免数据维护中出现更新,插入和删除异常. 插入异常:如果表中的某个实体随着另一 ...

  6. Python—异步任务队列Celery简单使用

    一.Celery简介 Celery是一个简单,灵活,可靠的分布式系统,用于处理大量消息,同时为操作提供维护此类系统所需的工具.它是一个任务队列,专注于实时处理,同时还支持任务调度. 中间人boker: ...

  7. UVa-679 Dropping Balls 二叉树

    题目链接:https://vjudge.net/problem/UVA-679 题意: 有一棵二叉树,所有节点从上至下,从左到右依次编号为1.2...2D-1,叶子深度都相同,有I个小球,从根节点依次 ...

  8. OpenMP笔记(六)

    OpenMP有三种常见的加锁操作: critical是OpenMP的指令,它规定其后的代码为临界块,任何时候只允许一个线程访问: omp_set_lock是OpenMP的库函数,要跟omp_unset ...

  9. 1. laravel 学习 环境搭建

    1. 项目环境 vagrant + laradock  (因为 自己手动搭建环境太麻烦了 自己弄了一下 感觉还是有些漏洞 所以采用 laradock) 2. Vagrantfile 备注 : box  ...

  10. POP3、SMTP和IMAP基础概念

    POP3 POP3是Post Office Protocol 3的简称,即邮局协议的第3个版本,它规定怎样将个人计算机连接到Internet的邮件服务器和下载电子邮件的电子协议.它是因特网电子邮件的第 ...