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. jQuery跨域调用WebService

    jQuery跨域调用WebService举例html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...

  2. iOS-MPMoviePlayerController视频播放

    视频MPMoviePlayerController 在iOS中播放视频可以使用MediaPlayer.framework种的MPMoviePlayerController类来完成,它支持本地 视频和网 ...

  3. iOS——使用FMDB进行数据库操作(转载)

    iOS 使用FMDB进行数据库操作 https://github.com/ccgus/fmdb [摘要]本文介绍iOS 使用FMDB进行数据库操作,并提供详细的示例代码供参考. FMDB 使用方法 A ...

  4. oracle jdk和openjdk区别;idea如何加载jdk源码并调试jdk代码

    两个jdk的区别 oracle jdk是sun/oracle(甲骨文)公司的,部分jdk开源:相对比较稳定,使用的比较多. openjdk是完全开源的,据说是官方oracle唯一承认的开源版本. id ...

  5. idea的enable auto-import/内存设置

    设置pom.xml依赖的自动导入 设置idea的memory heap On the Help menu, click Edit Custom VM Options. Set the -Xmx opt ...

  6. javascript正则总结

    目录 1. 正则基础知识 2. 正则实例 3. 正则常见问题 4. 开发常用validate 5. 网上整理的正则 1. 正则基础知识 精确匹配: /test/ 匹配一类字符:匹配a,b,c任一字符/ ...

  7. c# 如何给 dataGridView里添加一个自增长列(列名为序号)

    System.Data.DataTable table = new DataTable();                System.Data.DataColumn column = new Da ...

  8. Linux与windows的对比

    Linux与windows的对比 声明:下面的内容总结自实验楼的linux教程,特在此说明. Linux与windows一样,是一个操作系统. Linux与Windows的区别 软件与支持 windo ...

  9. PHP去除html的宽高属性的正则表达式

    PHP去除html的宽高属性的正则表达式 <pre><?php/** * 清除宽高样式 * @param String $content 内容 * @return String */ ...

  10. php 获取文件mime类型的方法

    php 获取文件mime类型的方法 使用fileinfo需要安装php_fileinfo扩展. 如已安装可以在extension_dir目录下找到php_fileinfo.dll(windows),f ...