安装配置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. Mq的介绍

    1.使用场景 异步处理 日志收集 流量削峰 应用解耦 2.通信协议 高级消息队列协议(AMQP). 参考文档:http://www.huangxiaobai.com/archives/1267

  2. java实体转json忽略属性

    1: import com.alibaba.fastjson.annotation.JSONField; fastjson 过滤指定字段 @JSONField(serialize=false)priv ...

  3. 域名解析到Nginx服务器项目上

    第一步:先将域名解析到 IP 上 解析完后,如下 第二步:Nginx服务器配置servername 修改 /usr/local/nginx/conf/nginx.conf (你的配置文件可能不在这个目 ...

  4. 通过pyqt5实现俄罗斯方块游戏例子

    # *_* coding:utf-8 *_* # 开发团队:中国软件开发团队# 开发人员:Administrator# 开发时间:2019/3/17 2:13# 文件名称:RussiaBoard# 开 ...

  5. codeforces 854C.Planning 【贪心/优先队列】

    Planning time limit per test 1 second memory limit per test 512 megabytes input standard input outpu ...

  6. POJ 1375 Intervals 光源投影【平面几何】

    <题目链接> <转载于> 题目大意: 给一个光源点s,给一些圆,源点和s相切会形成阴影,求每一段阴影在横轴上的区间. 解题分析: 这道其实不需要点与圆切线的板子来求解,完全可以 ...

  7. python 入门总结(一)

    自然语言用双引号,机器语言用单引号 例如dict的key 单行注释 # 多行注释 ''' ''' 输入print %s 字符串的占位符 %d 数字的占位符 如语句中有占位符那么所有的%都是占位符,可以 ...

  8. Shiro笔记(二)身份验证

    Shiro笔记(二)身份验证 一.核心代码 @Test public void helloWorldTest(){ IniSecurityManagerFactory factory = new In ...

  9. [USACO08DEC]Secret Message

    OJ题号: 洛谷2922 思路: 字典树,每个结点记录经过该节点的字符串数cnt和以该结点结尾的字符串数量val. 每次询问时累加经过节点的val值和结尾结点的cnt值. #include<cs ...

  10. Educational Codeforces Round 19 题解【ABCDE】

    A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...