[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 ...
随机推荐
- dijkstra基础
#include<iostream> #include<queue> #include<cstdio> #include<cstring> #inclu ...
- java实体转json忽略属性
1: import com.alibaba.fastjson.annotation.JSONField; fastjson 过滤指定字段 @JSONField(serialize=false)priv ...
- 论maven release的必要性
大多数java开发的小伙伴都用过maven来对包进行管理.在自己写项目的过程中,对自己的项目也会进行groupdId,artifactId,version的配置.下面我们来对着3个配置进行简单说明. ...
- Spring Boot 入门详细分析
推荐阅读: 我们为什么要学习 Spring Boot 我们搭建 Spring Boot 项目,可以使用 Spring 为我们提供的初始化网站,那个可能不太方便,今天呢,我们就来说说如何使用 IDEA ...
- C# 重启程序本身
private static void Restart() { Thread thtmp = new Thread(new ParameterizedThreadStart(run)); object ...
- window10 还原精灵 破解版 冰点
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha=======
- bzoj4237: 稻草人 cdq分治 单调栈
目录 题目链接 题解 代码 题目链接 bzoj4237: 稻草人 题解 暴力统计是n^2的 考虑统计一段区间对另一端的贡献 对于y值cdq分治,降调一维 对于当前两个分治区间统计上面那部分对下面那部分 ...
- android TextView如何换行?
具体代码是: rb_zuotian.setText("第一行"+"\n"+"第二行"); rb_jintian.setText(DateUt ...
- 2016年3月3日android实习笔记
1: android自定义控件时,通常需要重写父类构造函数.这三个够找函数具体啥时调用? public View (Context context) 是在java代码创建视图的时候被调用,如果是从xm ...
- Java多线程:AQS
在Java多线程:线程间通信之Lock中我们提到了ReentrantLock是API级别的实现,但是没有说明其具体实现原理.实际上,ReentrantLock的底层实现使用了AQS(AbstractQ ...
