[svc]inotify+rsync解决nfs单点问题
安装配置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个,则nfsbackup会有延迟
1,如果能接受延迟,可以用
2,可以用多个目录多个脚本同时同步.
3,可以针对文件同步,每一次只同步变化的文件,而已.但是想归想,但效果不好
4,可以用别的方案,如drbd
[svc]inotify+rsync解决nfs单点问题的更多相关文章
- NFS +inotify+rsync 实现数据的远程挂载与实时增量备份
NFS 网络文件系统 功能: 用户可以像访问自己的本地文件系统一样使用网络中的远端系统上的文件 原理: 用户进程-->RPC服务(portman)-->tcp/ip协议栈-->远端主 ...
- 【集群实战】共享存储实时备份(解决nfs共享存储的单点问题)
1. nfs存储的单点问题 如果nfs服务器宕机了,则所有的nfs客户机都会受到影响.一旦宕机,会丢失部分用户的数据.为了解决单点问题,需要实现共享存储的实时备份,即:将nfs服务端共享目录下的数据实 ...
- 项目cobbler+lamp+vsftp+nfs+数据实时同步(inotify+rsync)
先配置好epel源 [root@node3 ~]#yum install epel-release -y 关闭防火墙和selinux [root@node3 ~]#iptables -F [root@ ...
- 【转载】inotify+rsync实时同步 解决同步慢问题 (转载备记)
原文地址:http://www.ttlsa.com/web/let-infotify-rsync-fast/ 背景 我们公司在用inotify+rsync做实时同步,来解决分布式集群文件一致性的问题. ...
- 真正的inotify+rsync实时同步 彻底告别同步慢
真正的inotify+rsync实时同步 彻底告别同步慢 http://www.ttlsa.com/web/let-infotify-rsync-fast/ 背景 我们公司在用in ...
- 第2章 rsync(二):inotify+rsync详细说明和sersync
本文目录: inotify+rsync 1.1 安装inotify-tools 1.2 inotifywait命令以及事件分析 1.3 inotify应该装在哪里 1.4 inotify+rsync示 ...
- 实时同步inotify+rsync
目的,要求 nfs储存服务器与backup备份服务器,数据同步,万一nfs储存服务器挂了,数据还在 实时同步备份软件服务 1)inotify 实时同步软件 2)sersync 实时同步软件 实时同步原 ...
- rsync(二):inotify+rsync详细说明和sersync
以下是rsync系列篇: inotify+rsync 如果要实现定时同步数据,可以在客户端将rsync加入定时任务,但是定时任务的同步时间粒度并不能达到实时同步的要求.在Linux kernel 2. ...
- 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 ...
随机推荐
- 使用numpy产生随机数
numpy中的random模块包含了很多方法可以用来产生随机数,这篇文章将对random中的一些常用方法做一个总结. 1.numpy.random.rand(d0, d1, ..., dn) 作用:产 ...
- poj 1797 最大最小路段【dijkstra】 (经典)
<题目链接> 题目大意: Hugo Heavy要从城市1到城市N运送货物,有M条道路,每条道路都有它的最大载重量,问从城市1到城市N运送最多的重量是多少. 解题分析: 感觉这道题用dijk ...
- python数据分析之pandas数据选取:df[] df.loc[] df.iloc[] df.ix[] df.at[] df.iat[]
1 引言 Pandas是作为Python数据分析著名的工具包,提供了多种数据选取的方法,方便实用.本文主要介绍Pandas的几种数据选取的方法. Pandas中,数据主要保存为Dataframe和Se ...
- 使用js生成二维码和条形码
1.生成二维码 使用github开源项目qrcode. 1.引入方式一(js cdn引入): ①.引入qrcode cdn: 自行下载..没有合适的cdn,地址 <script src=&quo ...
- LoRaWAN 1.1 网络协议规范 - 3 物理层帧格式
LoRaWAN 1.1 网络协议规范 LoRaWAN 1.1 版本封稿很久了也没有完整啃过一遍,最近边啃边翻译,趁着这个机会把它码下来. 如果觉得哪里有问题,欢迎留言斧正. 翻译不易,转载请申明出处和 ...
- 【WIN32编程】利用汇编写cs1.6辅助
这篇文章本来在2018.5.1号就写完发圈子去了,这两天跟朋友在网吧打单击才想起来,就顺便把内容发上去把 作者:admin-神风 用CE找到功能的地址 CS1.6下载地址:https://pan.ba ...
- 潭州课堂25班:Ph201805201 第十五课 迭代器,生成器 (课堂笔记)
推导表达式 li1 = list() for i in range(10): # 迭代循环内容 li1.append(i) print( li1 ) ---->>> [0, 1, 2 ...
- 图的 储存 深度优先(DFS)广度优先(BFS)遍历
图遍历的概念: 从图中某顶点出发访遍图中每个顶点,且每个顶点仅访问一次,此过程称为图的遍历(Traversing Graph).图的遍历算法是求解图的连通性问题.拓扑排序和求关键路径等算法的基础.图的 ...
- 总结的U3D面试题
1.配置Unity 3d调试环境? 1) Visual Studio Tools for Unity 2) 访问http://unityvs.com 3) ...
- C#高级编程9-第12章 动态语言扩展
C#高级编程9-第12章 动态语言扩展 dynamic t = new ExpandoObject(); t.Abc = "abc"; t.Value = ; Console.Wr ...