一、场景应用:                           

        客户通过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的文件)

转载于:https://www.cnblogs.com/dangjingwei/p/11031195.html

二十九、rsync+inotity实时监控同步工具相关推荐

  1. Rsync+Sersync实时文件同步

    Rsync+Sersync实时文件同步 实时同步方案: 1.rsync+inotify (不推荐,inotify是对本地文件或目录的实时监控) 2.rsync+sersync (推荐,是inotify ...

  2. 【Microsoft Azure 的1024种玩法】二十九.基于Azure VM快速实现网络入侵检测 (IDS) 及网络安全监视 (NSM)

    [简介] 数据包捕获是一个重要组件,可以实施网络入侵检测系统 (IDS) 并执行网络安全监视 (NSM). 我们可以借助开源 IDS 工具来处理数据包捕获,并检查潜在网络入侵和恶意活动的签名. 使用网 ...

  3. (二十九 ~ 三十一)巴菲特与索罗斯的投资习惯:投资习惯

    作者:chen_h 微信号 & QQ:862251340 微信公众号:coderpai (一)巴菲特与索罗斯的投资习惯:思考习惯的力量 (二)巴菲特与索罗斯的投资习惯:七种致命的投资信念 (三 ...

  4. 2021年大数据Hadoop(二十九):​​​​​​​关于YARN常用参数设置

    全网最详细的Hadoop文章系列,强烈建议收藏加关注! 后面更新文章都会列出历史文章目录,帮助大家回顾知识重点. 目录 本系列历史文章 前言 关于yarn常用参数设置 设置container分配最小内 ...

  5. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验二十九:LCD模块

    实验二十九:LCD模块 据说Alinx 301支持 7"TFT,好奇的朋友一定疑惑道,它们3.2"TFT以及7"TFT等两者之间究竟有何区别呢?答案很简单,前者自带控制器 ...

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

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

  7. SAP UI5 应用开发教程之二十九 - SAP UI5 的路由和导航功能介绍试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  8. FreeSql (二十九)Lambda 表达式

    FreeSql 支持功能丰富的表达式函数解析,方便程序员在不了解数据库函数的情况下编写代码.这是 FreeSql 非常特色的功能之一,深入细化函数解析尽量做到满意,所支持的类型基本都可以使用对应的表达 ...

  9. 【零基础学Java】—final关键字与四种用法(二十九)

    [零基础学Java]-final关键字与四种用法(二十九) 一.final关键字 final关键字代表最终.不可改变的 常见的四种用法: 可以用来修饰一个类 可以用来修饰一个方法 可以用来修饰一个局部 ...

最新文章

  1. 个人学习某个系统或平台的3问式的整理和细化指引
  2. ASP.NET页生命周期概述
  3. 数据结构第一次作业——抽象数据类型
  4. 以Blog.Core的方式来打开Abp.vNext
  5. 计算机诞生发展分类特点及应用,计算机的诞生与发展,及其特点
  6. 学python必会英语单词_Python必备常用英语词汇(一)
  7. 打印工资条怎么做到每个人都有表头明细_一分钟生成500人的工资条?还有2种方法?...
  8. Kotlin 一统天下?Kotlin/Native 开始支持 iOS 和 Web 开发
  9. useful websites for constructing your own website
  10. ubuntu16.04耳机没有声音解决办法
  11. P3373 【模板】线段树2 题解
  12. 《编码隐藏在计算机软硬件背后的语言》读感
  13. python中and、or、not、in和not in五种运算用法
  14. 2017国庆 雅礼集训 题解合集
  15. 关于mathtype中的等号=和括号
  16. 数组的push、unshift、pop、shift方法实现
  17. Linux中的echo命令
  18. pandas去除两列中同一行有相同元素的数据——数据分析必备技能(5)
  19. 十一月的Kemin,不是萧邦 2005
  20. 不用任何框架,Java 就能实现定时任务的 3 种方法

热门文章

  1. 新一代 AirPods 充电仓曝光: 入耳式设计看起来更类似 AirPods Pro 的设计
  2. NC65 会计科目调整
  3. 家长如何帮助孩子学习scratch3.0
  4. 视频参考不求人,记住这几个网站就够了~
  5. 实例:利用友盟崩溃统计+mapping.txt文件定位项目的错误
  6. 位移操作符 <<左移 与 >>右移 的基本逻辑
  7. 龙之信条一直显示连接服务器中,游戏新消息:龙之信条黑暗觉者官方直播20分钟实机演示...
  8. 使命召唤ol显示服务器连接超时,使命召唤online无法连接大厅服务怎么办 无法连接大厅解决方法...
  9. 关于App启动加载广告页面思路
  10. 当投票打榜的“饭圈女孩”杀入币圈