安装配置inotify

参考

  1. yum install inotify* -y
  2. [root@n2 shell]# rpm -qa|grep inotify
  3. inotify-tools-3.14-8.el7.x86_64
  4. inotify-tools-devel-3.14-8.el7.x86_64
  5. [root@n2 shell]# rpm -ql inotify-tools-3.14-8.el7.x86_64
  6. /usr/bin/inotifywait # 监控目录变换的
  7. /usr/bin/inotifywatch # 统计次数的

搞清楚inotify的原理

参考


  1. inotifywait -h #查看参数
  2. --format <fmt> Print using a specified printf-like format
  3. string; read the man page for more details.
  4. --timefmt <fmt> strftime-compatible format string for use with
  5. %T in --format string.
  6. --excludei <pattern> #排除不监控哪些
  7. -e|--event <event1> [ -e|--event <event2> ... ] #这个是核心
  8. Listen for specific event(s). If omitted, all events are
  9. listened for.
  10. Exit status:
  11. 0 - An event you asked to watch for was received.
  12. 1 - An event you did not ask to watch for was received
  13. (usually delete_self or unmount), or some error occurred.
  14. 2 - The --timeout option was given and no events occurred
  15. in the specified interval of time.
  16. Events:
  17. access file or directory contents were read
  18. modify file or directory contents were written
  19. attrib file or directory attributes changed
  20. close_write file or directory closed, after being opened in
  21. writeable mode
  22. close_nowrite file or directory closed, after being opened in
  23. read-only mode
  24. close file or directory closed, regardless of read/write mode
  25. open file or directory opened
  26. moved_to file or directory moved to watched directory
  27. moved_from file or directory moved from watched directory
  28. move file or directory moved to or from watched directory
  29. create file or directory created within watched directory
  30. delete file or directory deleted within watched directory
  31. delete_self file or directory was deleted
  32. unmount file system containing file or directory unmounted
  1. - 同时开两个窗口, 客户端启动inotifywait监控本地的/data目录
  2. inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T%w%f' -e create /data
  3. -m|--monitor 保持监控monitor
  4. -r|--recursive 递归监控
  5. -q|--quiet 仅打印简单事件
  6. -e|--event 指定监控事件
  7. - 在本地/data目录新建目录
  8. 可以看到日志:
  9. 17/03/18 10:56/data/11.md
  10. 思路是写shell,每次发生一次变更就执行rsync

生产中使用inotify同步

  1. #!/usr/bin/env bash
  2. /usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data |\
  3. while read file;do
  4. cd / && rsync -az ./data/ --delete rsync_backup@192.168.14.11::data --password-file=/etc/rsync.password
  5. done
  1. sh inotify.sh & #这样即可
  2. /bin/sh /root/shell/inotify.sh -& #放在rc.local里

生产rsync参数优化

  1. [root@n2 shell]# ls -l /proc/sys/fs/inotify/
  2. total 0
  3. -rw-r--r-- 1 root root 0 Mar 17 10:53 max_queued_events # 设置单进程可监控的文件数
  4. -rw-r--r-- 1 root root 0 Mar 17 10:53 max_user_instances # 设置每个用户可运行的iniotifywait或iniotifywatch命令的进程数
  5. -rw-r--r-- 1 root root 0 Mar 17 10:53 max_user_watches # 设置inotify实例时间队列可容纳的事件数量
  6. echo "50000000" > /proc/sys/fs/inotify/max_user_watches
  7. echo "50000000" > /proc/sys/fs/inotify/max_queued_events

inotify性能测试:

  1. 10-300K 每秒200-300个并发,基本不会延迟.如果每s同步1000个,则nfsbackup会有延迟
  2. 1,如果能接受延迟,可以用
  3. 2,可以用多个目录多个脚本同时同步.
  4. 3,可以针对文件同步,每一次只同步变化的文件,而已.但是想归想,但效果不好
  5. 4,可以用别的方案,如drbd

[svc]inotify+rsync解决nfs单点问题的更多相关文章

  1. NFS +inotify+rsync 实现数据的远程挂载与实时增量备份

    NFS 网络文件系统 功能: 用户可以像访问自己的本地文件系统一样使用网络中的远端系统上的文件 原理: 用户进程-->RPC服务(portman)-->tcp/ip协议栈-->远端主 ...

  2. 【集群实战】共享存储实时备份(解决nfs共享存储的单点问题)

    1. nfs存储的单点问题 如果nfs服务器宕机了,则所有的nfs客户机都会受到影响.一旦宕机,会丢失部分用户的数据.为了解决单点问题,需要实现共享存储的实时备份,即:将nfs服务端共享目录下的数据实 ...

  3. 项目cobbler+lamp+vsftp+nfs+数据实时同步(inotify+rsync)

    先配置好epel源 [root@node3 ~]#yum install epel-release -y 关闭防火墙和selinux [root@node3 ~]#iptables -F [root@ ...

  4. 【转载】inotify+rsync实时同步 解决同步慢问题 (转载备记)

    原文地址:http://www.ttlsa.com/web/let-infotify-rsync-fast/ 背景 我们公司在用inotify+rsync做实时同步,来解决分布式集群文件一致性的问题. ...

  5. 真正的inotify+rsync实时同步 彻底告别同步慢

    真正的inotify+rsync实时同步 彻底告别同步慢       http://www.ttlsa.com/web/let-infotify-rsync-fast/     背景 我们公司在用in ...

  6. 第2章 rsync(二):inotify+rsync详细说明和sersync

    本文目录: inotify+rsync 1.1 安装inotify-tools 1.2 inotifywait命令以及事件分析 1.3 inotify应该装在哪里 1.4 inotify+rsync示 ...

  7. 实时同步inotify+rsync

    目的,要求 nfs储存服务器与backup备份服务器,数据同步,万一nfs储存服务器挂了,数据还在 实时同步备份软件服务 1)inotify 实时同步软件 2)sersync 实时同步软件 实时同步原 ...

  8. rsync(二):inotify+rsync详细说明和sersync

    以下是rsync系列篇: inotify+rsync 如果要实现定时同步数据,可以在客户端将rsync加入定时任务,但是定时任务的同步时间粒度并不能达到实时同步的要求.在Linux kernel 2. ...

  9. CentOS 6.x Inotify+Rsync

    CentOS 6.x Inotify+Rsync yum -y install lrzsz [root@rsync ~]# mount -t nfs 10.6.100.75:/volume1/pace ...

随机推荐

  1. 067 Flume协作框架

    一:介绍 1.概述 ->flume的三大功能 collecting, aggregating, and moving 收集 聚合 移动 数据源:web service              ...

  2. NIO 中的读和写

    概述 读和写是I/O的基本过程.从一个通道中读取很简单:只需创建一个缓冲区,然后让通道将数据读到这个缓冲区中.写入也相当简单:创建一个缓冲区,用数据填充它,然后让通道用这些数据来执行写入操作. 从文件 ...

  3. 618大促微服务、web、redis等的超时时间

    1. 最近因为大促原因线上服务不稳定,不稳定主要是redis经常超时并且数据为定时mGet方式获得 节点一多,所有服务节点同时获取数据访问量变大导致get取数据变慢因mGet会对数据进行锁住操作, 此 ...

  4. python-docx

    pip install python-docx 注意不要直接下载docx包 from docx import Document from docx.shared import RGBColor,Inc ...

  5. BZOJ.4361.isn(DP 树状数组 容斥)

    题目链接 长度为\(i\)的不降子序列个数是可以DP求的. 用\(f[i][j]\)表示长度为\(i\),结尾元素为\(a_j\)的不降子序列个数.转移为\(f[i][j]=\sum f[i-1][k ...

  6. 潭州课堂25班:Ph201805201 第四课:Linux的命令以及VIM的使用 (课堂笔记)

    Linux的常用命令 引入 1:如果我们要在Linux里面实现一些比如查看文件和文件夹.新建文件夹之类的操作,应该是通过什么来实现 2:讲解Linux目录树 3:讲解Linux只区分文件名,Linux ...

  7. 面向对象&网络编程

    1 接口与归一化设计 1.1 归一化概念: 归一化的好处: 1.归一化让使用者无需关心对象的类是什么,只需要知道这些对象都具备某些功能就可以了,这极大降低了使用者的使用难度. 2.归一化使得高层的外部 ...

  8. PHPMailer 使用方法(支持群发):

    一.下载函数包 地址:https://github.com/PHPMailer/PHPMailer 二.测试服务器环境 通过phpinfo()函数打印出是否支持Sockets(Socket属于php的 ...

  9. j2me必备之网络开发数据处理

    第9章 无线网络开发MIDP提供了一组通用的网络开发接口,用来针对不同的无线网络应用可以采取不同的开发接口.基于CLDC的网络支持是由统一网络连接框架(Generic Connection Frame ...

  10. SimpleDateFormat 格式化参数说明

    字母 日期或时间元素 表示 示例 G Era 标志符 Text AD y 年 Year 1996; 96 M 年中的月份 Month July; Jul; 07 w 年中的周数 Number 27 W ...