安装配置inotify

参考

yum install inotify* -y

[root@n2 shell]# rpm -qa|grep inotify
inotify-tools-3.14-8.el7.x86_64
inotify-tools-devel-3.14-8.el7.x86_64 [root@n2 shell]# rpm -ql inotify-tools-3.14-8.el7.x86_64
/usr/bin/inotifywait # 监控目录变换的
/usr/bin/inotifywatch # 统计次数的

搞清楚inotify的原理

参考


inotifywait -h #查看参数
--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. --excludei <pattern> #排除不监控哪些 -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监控本地的/data目录
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T%w%f' -e create /data -m|--monitor 保持监控monitor
-r|--recursive 递归监控
-q|--quiet 仅打印简单事件
-e|--event 指定监控事件 - 在本地/data目录新建目录
可以看到日志:
17/03/18 10:56/data/11.md 思路是写shell,每次发生一次变更就执行rsync

生产中使用inotify同步

#!/usr/bin/env bash

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

生产rsync参数优化

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

inotify性能测试:

10-300K 每秒200-300个并发,基本不会延迟.如果每s同步1000个,则nfsbackup会有延迟
1,如果能接受延迟,可以用
2,可以用多个目录多个脚本同时同步.
3,可以针对文件同步,每一次只同步变化的文件,而已.但是想归想,但效果不好
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. js获取宽度

    alert(window.screen.width );//浏览设备的分辨率(电脑.手机.平板等) alert(window.screen.availWidth );//浏览设备的实际可用宽度(电脑. ...

  2. Qt学习之信号与槽(一)

    Qt学习之信号与槽(一) 目录 QT的信号与槽机制 在窗口的UI设计中操作添加信号和槽     QT的信号与槽机制   QT的两种机制 在Qt和PyQt中有两种通信机制: 低级事件处理机制(low-l ...

  3. P1025 数的划分

    P1025 数的划分f[i][j]表示把数i分成j份的方案数,分成两种情况,第一种是最小值是1,另一种是最小值不是1,对于不是1的情况,先都放一个1,那么f[i][j]=f[i-1][j-1]+f[i ...

  4. 不一样的go语言-不同的语法之type

    前言   在go语言中,type用于类型定义(type definition)与类型别名(type alias).这两者的差别从名字上已经可以初见端倪.   类型定义即定义新类型,是一个全新的类型,但 ...

  5. SQLite中的SELECT子句

    SQLite中的SELECT子句 目前为止,最常见的SELECT语句由三个子句组成,分别为SELECT.FROM与WHERE.本小节我们首先讲解SELECT子句.SELECT子句可以用来定义最终结果表 ...

  6. iOS html5使用缓存并及时更新方案总结

    最近一段时间研究了一下H5在iOS移动端表现时使用缓存并可及时更新方案,总结如下: 一.使用Webview自带缓存机制 当我们使用webview加载html资源时的,本质上就是一个向服务器索取资源的h ...

  7. 细解javascript中的this关键字

    JavaScript函数中的this指向并不是在函数定义的时候确定的,而是在调用的时候确定的.换句话说,函数的调用方式决定了this指向. 一. 全局上下文 在函数外部,无论是否在严格模式下,this ...

  8. Luogu3163 [CQOI2014]危桥 ---- 网络流 及 一个细节的解释

    Luogu3163 [CQOI2014]危桥 题意 有$n$个点和$m$条边,有些边可以无限次数的走,有些边这辈子只能走两次,给定两个起点和终点$a_1 --> a_2$(起点 --> 终 ...

  9. POJ.1769.Minimizing maximizer(线段树 DP)

    题目链接 /* 题意:有m个区间,问最少要多少个区间能覆盖[1,n] 注:区间要按原区间的顺序,不能用排序贪心做 设dp[i]表示最右端端点为i时的最小值 dp[e[i]]=min{dp[s[i]]~ ...

  10. iOS主流机型更新

    主流机型更新后,舍弃了原有的iPhone 4 ,iPhone 4s, iPhone 5 ,iPhone 5s.增加了iPhone X,iPhone 8和iPhone 8 plus. 总体上屏幕趋于一个 ...