1、根据之前一篇关于rsync的随笔部署好rsync服务后,可以开始inotify的部署

2、inotify的部署使用

  ①、检查系统是否支持inotify

[root@iZ25w1kdi5zZ ~]# ls -lsart /proc/sys/fs/inotify
total
dr-xr-xr-x root root Sep : ..
-rw-r--r-- root root Jan : max_user_watches
-rw-r--r-- root root Jan : max_user_instances
-rw-r--r-- root root Jan : max_queued_events
dr-xr-xr-x root root Jan : .

如果出现上面结果说明系统支持inotify。

  ②、安装

tar -zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14/
./configure --prefix=/usr/local/inotify-tools-3.14
make && make install
ln -s /usr/local/inotify-tools-3.14/ /usr/local/inotify-tools

  ③、inotify参数

  * 说明:

    max_user_instances:每个用户创建inotify实例最大值

    max_queued_events:inotify队列最大长度,如果值太小,会出现错误,导致监控文件不准确

    max_user_watches:要知道同步的文件包含的目录数

  * 查看默认参数

[root@ scripts]# sysctl -a|egrep "inotify.max_queued_events|inotify.max_user_watches|epoll.max_user_watches|inotify.max_user_instances"
fs.epoll.max_user_watches =
fs.inotify.max_queued_events =
fs.inotify.max_user_instances =
fs.inotify.max_user_watches =
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.enp0s3.stable_secret"
sysctl: reading key "net.ipv6.conf.enp0s8.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
sysctl: reading key "net.ipv6.conf.virbr0.stable_secret"
sysctl: reading key "net.ipv6.conf.virbr0-nic.stable_secret"

  * 修改参数

  -命令修改

  sysctl -w fs.inotify.max_user_instances=130

[root@ scripts]# sysctl -w fs.inotify.max_user_instances=
fs.inotify.max_user_instances =
[root@ scripts]# sysctl -w fs.inotify.max_user_watches=
fs.inotify.max_user_watches =
[root@ scripts]# sysctl -w fs.inotify.max_queued_events=
fs.inotify.max_queued_events =

  -配置文件修改

[root@tmp]# vi /etc/sysctl.conf
#添加如下代码
fs.inotify.max_user_instances=

  ④、创建实时监控脚本

##例一
[root@ scripts]# cat inotify.sh
#!/bin/sh
cmd="/usr/local/inotify-tools/bin/inotifywait"
$cmd -mrq --format '%w%f' -e create,close_write,delete /backup|\
while read line
do
cd /backup &&\
rsync -az --delete --timeout= ./ rsync_user@10.0.0.10::www --password-file=/etc/rsync.password
done
##例子二
[root@iZ25w1kdi5zZ ~]# mkdir -p /opt/scripts [root@iZ25w1kdi5zZ ~]# cd /opt/scripts [root@iZ25w1kdi5zZ scripts]# vi inotify_start.sh
/usr/local/inotify/bin/inotifywait -mrq -e modify,create,move,delete \
--fromfile '/opt/scripts/ffile' \
--timefmt '%y-%m-%d %H:%M' --format '%T %f %e' \
--outfile '/tmp/rsync.log' inotifywait常用参数:
--timefmt 时间格式
%y年 %m月 %d日 %H小时 %M分钟
--format 输出格式
%T时间 %w路径 %f文件名 %e状态
-m 始终保持监听状态,默认触发事件即退出。
-r 递归查询目录
-q 打印出监控事件
-e 定义监控的事件,可用参数:
open 打开文件
access 访问文件
modify 修改文件
delete 删除文件
create 新建文件
attrb 属性变更

rsync & inotify-tools 实时同步的更多相关文章

  1. linux rsync +inotify 实现 实时同步

    前言:     rsync可以实现触发式的文件同步,但是通过crontab守护进程方式进行触发,同步的数据和实际数据会有差异,而inotify可以监控文件系统的各种变化,当文件有任何变动时,就触发rs ...

  2. rsync + inotify 数据实时同步

    一.rsync介绍 rsync英文全称为Remote synchronization,从软件的名称就可以看出来,Rsync具有可是本地和远程两台主机之间的数据快速复制同步镜像.远程备份的功能,这个功能 ...

  3. rsync+inotify实现实时同步案例--转

    转自:http://chocolee.blog.51cto.com/8158455/1400596 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐 ...

  4. rsync+inotify实现实时同步案例

    转自:http://chocolee.blog.51cto.com/8158455/1400596 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐 ...

  5. Rsync+inotify实现实时同步

    1.1 inotify介绍 inotify是一种强大的.细粒度的.异步的文件系统事件控制机制.linux内核从2.6.13起,加入了inotify支持,通过inotify可以监控文件系统中添加.删除. ...

  6. rsync+inotify实现实时同步案例【转】

    1.1 inotify介绍 inotify是一种强大的.细粒度的.异步的文件系统事件控制机制.linux内核从2.6.13起,加入了inotify支持,通过inotify可以监控文件系统中添加.删除. ...

  7. rsync简介与rsync+inotify配置实时同步数据

    rsync简介 rsync是linux系统下的数据镜像备份工具.使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主机同步. rsync特性 rsync ...

  8. CentOS 7 rsync+inotify实现实时同步

    测试环境如下: inotify-slave IP : 172.16.0.222 inotify-master IP : 172.16.0.233 对两台机的要求: 安装依赖包gcc: yum inst ...

  9. centos 配置rsync+inotify数据实时同步2

    一.Rsync服务简介 1. 什么是Rsync 它是一个远程数据同步工具,它在同步文件的同时,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的“rsync算法”来使本地和远程两个主机 ...

  10. centos 配置rsync+inotify数据实时同步

    何为rsync? 定义: rsync是一个开源的快速备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,保持链接和权限,非常适用于异地备份 何为源端和发起端? 在远程同步过程中,负责发起rs ...

随机推荐

  1. 【Leetcode_easy】665. Non-decreasing Array

    problem 665. Non-decreasing Array 题意:是否能够将数组转换为非减数组. solution: 难点在于理解如何对需要修改的元素进行赋值: class Solution ...

  2. 【Leetcode_easy】645. Set Mismatch

    problem 645. Set Mismatch 题意: solution1: 统计每个数字出现的次数了,然后再遍历次数数组,如果某个数字出现了两次就是重复数,如果出现了0次,就是缺失数. 注意:如 ...

  3. iOS技术面试04:数据存储

    如果后期需要增加数据库中的字段怎么实现,如果不使用CoreData呢? 编写SQL语句来操作原来表中的字段 1> 增加表字段 ALTER TABLE 表名 ADD COLUMN 字段名 字段类型 ...

  4. 【c# 学习笔记】封装

    封装 指的是把类内部的数据隐藏起来,不让对象实例直接对其操作.c#中提供了属性机制来对类内部的状态进行操作. 在c#中,封装可以通过Public.Private.Protected和Internal等 ...

  5. 给定一个字符串str,将str中连续两个字符为a的字符替换为b(一个或连续超过多个字符a则不替换)

    需求:给定一个字符串str,将str中连续两个字符为a的字符替换为b(一个或连续超过多个字符a则不替换) 如: a 不替换 b 不替换  ab 不替换 ba 不替换 aba 不替换  aab 替换为 ...

  6. cv2---imread---error

    when I use the cv2.imred() which is absolute path  path = r'C:\\Users\\hp\\Desktop\\常用Python代码\\mycv ...

  7. iText输出中文

    使用iTextAsian.jar中的字体 BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont ...

  8. uwp,c#,listView与gridView列表控件进阶

    listView与gridView使用类似,这里讲解gridView的一些数据绑定(x:Bind)基础知识. 顺便学习下如何使用属性通知.(后台中的数据变化会直接显示在UI上,实现动态变化,默认是没有 ...

  9. MakeFile文件是什么——内容、工作原理、作用、使用

    MakeFile文件是什么?它里面包含什么内容.具有什么作用.怎么使用?下面就来具体说说. 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你 ...

  10. [转帖]阿里的JDK预热warmup过程

    预热warmup过程 https://blog.csdn.net/wabiaozia/article/details/82056520 Jwarmup 原理是记录上一次运行时已经变成native co ...