1.1.架构规划

1.1.1架构规划准备

服务器系统 角色 IP

  • Centos6.7 x86_64 NFS服务器端(NFS-server-inotify-tools) 192.168.1.14
  • Centos6.7 x86_64 rsync服务器端(rsync热备服务器) 192.168.1.17

1.1.2架构图

2.1 部署前检查

2.1.1 检查rsync热备服务器daemon是否起来

复制代码
1 [root@backup data]# lsof -i:873
2 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
3 rsync 3071 root 3u IPv4 18684 0t0 TCP *:rsync (LISTEN)
4 rsync 3071 root 5u IPv6 18685 0t0 TCP *:rsync (LISTEN)
5 [root@backup data]# ps -ef|grep rsync|grep -v grep
6 root 3071 1 0 Dec02 ? 00:00:00 rsync --daemon
7 [root@backup data]#
复制代码
2.1.2 NFS服务器相对于rsync服务器来说是客户端,所以要配置一个客户端密码

    1 [root@nfs-server ~]# echo "zhurui" >>/etc/rsync.password2 [root@nfs-server ~]# cat /etc/rsync.password 3 zhurui4 [root@nfs-server ~]# chmod 600 /etc/rsync.password 5 [root@nfs-server ~]# ll /etc/rsync.password 6 -rw-------. 1 root root 7 Jan 31 00:49 /etc/rsync.password7 [root@nfs-server ~]#

2.1.3 NFS客户端手动推/data/目录下数据到rsync热备服务器/backup目录下

--------------------------------------------------------------------
注:如果你对python感兴趣,我这有个学习Python基地,里面有很多学习资料,感兴趣的+Q群:895817687
--------------------------------------------------------------------1 [root@nfs-server data]# showmount -e localhost ##检查共享目录2 Export list for localhost:3 /data 192.168.1.0/244 [root@nfs-server ~]# cd /data/5 [root@nfs-server data]# ll6 total 127 -rw-r--r--. 1 nfsnobody nfsnobody    0 Jan 30 03:05 beautiful.txt8 -rw-r--r--. 1 nfsnobody nfsnobody    9 Jan 30 04:33 f11.txt9 -rw-r--r--. 1 root      root         0 Jan 30 04:41 fs.txt10 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Jan 30 03:05 huang11 -rw-r--r--. 1 nfsnobody nfsnobody    0 Jan 30 03:17 reew.txt12 -rw-r--r--. 1 root      root         0 Jan 30 02:51 test1.txt13 -rw-r--r--. 1 nfsnobody nfsnobody    0 Jan 30 04:41 wd.txt14 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Jan 30 02:57 zhurui15 -rw-r--r--. 1 nfsnobody nfsnobody    0 Jan 30 02:47 zhurui1.txt16 -rw-r--r--. 1 nfsnobody root         0 Jan 30 02:10 zhurui.txt17 [root@nfs-server /]# rsync -avz /data/ rsync_backup@192.168.1.17::backup/ --password-file=/etc/rsync.password   ##推送数据命令18 sending incremental file list19 ./20 beautiful.txt21 f11.txt22 fs.txt23 reew.txt24 test1.txt25 wd.txt26 zhurui.txt27 zhurui1.txt28 huang/29 zhurui/30 31 sent 572 bytes  received 171 bytes  114.31 bytes/sec32 total size is 9  speedup is 0.0133 [root@nfs-server /]#

2.1.4 rsync服务器端检查/backup目录下数据

3.1 服务部署

3.1.1 NFS服务端安装inotify工具

inofity-tools下载地址:http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

1)查看当前系统是否支持inotify

    1 [root@nfs-server tools]# uname -r   ##内核版本,从kernel2.6.13开始支持2 2.6.32-573.el6.x86_64   3 [root@nfs-server tools]# ls -l /proc/sys/fs/inotify/  ##查看是否支持4 total 05 -rw-r--r-- 1 root root 0 Jan 31 01:34 max_queued_events6 -rw-r--r-- 1 root root 0 Jan 31 01:34 max_user_instances7 -rw-r--r-- 1 root root 0 Jan 31 01:34 max_user_watches8 ##显示当前三个文件表示支持

2)下载inotify源码包

    1 [root@nfs-server tools]# ll2 total 3523 -rw-r--r--. 1 root root 358772 Mar 14  2010 inotify-tools-3.14.tar.gz

3)编译安装inotify

    1 [root@nfs-server tools]# tar zxf inotify-tools-3.14.tar.gz 2 [root@nfs-server tools]# cd inotify-tools-3.143 [root@nfs-server inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify-tools-3.144 [root@nfs-server inotify-tools-3.14]# make&&make install复制代码1 [root@nfs-server inotify-tools-3.14]# ln -s /usr/local/inotify-tools-3.14/ /usr/local/inotify-tools  ##创建软链接2 [root@nfs-server inotify-tools-3.14]# cd ..3 [root@nfs-server local]# ll4 total 445 drwxr-xr-x. 2 root root 4096 Sep 23  2011 bin6 drwxr-xr-x. 2 root root 4096 Sep 23  2011 etc7 drwxr-xr-x. 2 root root 4096 Sep 23  2011 games8 drwxr-xr-x. 2 root root 4096 Sep 23  2011 include9 lrwxrwxrwx. 1 root root   30 Jan 31 01:58 inotify-tools -> /usr/local/inotify-tools-3.14/10 drwxr-xr-x. 6 root root 4096 Jan 31 01:55 inotify-tools-3.1411 drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib12 drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib6413 drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexec14 drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbin15 drwxr-xr-x. 5 root root 4096 Nov 25 02:40 share16 drwxr-xr-x. 2 root root 4096 Sep 23  2011 src17 [root@nfs-server local]# cd inotify-tools18 [root@nfs-server inotify-tools]# ll19 total 16

复制代码
提示编译成功后会生成4个目录,分别是:

    1 [root@nfs-server /]# cd /usr/local/inotify-tools2 [root@nfs-server inotify-tools]# ll3 total 164 drwxr-xr-x. 2 root root 4096 Jan 31 01:55 bin    ##inotify执行命令(二进制)5 drwxr-xr-x. 3 root root 4096 Jan 31 01:55 include   ##inotify程序所需用的头文件6 drwxr-xr-x. 2 root root 4096 Jan 31 01:55 lib  ##动态链接的库文件7 drwxr-xr-x. 4 root root 4096 Jan 31 01:55 share  ##帮助文档

工具集合介绍:

一共安装了2个工具(命令),即inotifywait和inotifywatch

inotifywait:在被监控的文件或目录上等待特定文件系统事件(open、close、delete等)发生,执行后处于阻塞状态,适合在shell脚本中使用。

inotifywatch:收集被监视的文件系统使用度统计数据,指定文件系统事件发生的次数统计。

4)inotify命令常用参数详解

     1 [root@nfs-server inotify-tools]# ./bin/inotifywait --help2 inotifywait 3.143 Wait for a particular event on a file or set of files.4 Usage: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ ... ]5 Options:6  -r|--recursive  Watch directories recursively.  ##递归查询目录7  -q|--quiet      Print less (only print events)   ##打印很少的信息,仅仅打印监控相关的信息8 -m|--monitor    Keep listening for events forever.  Without9                         this option, inotifywait will exit after one10                         event is received.   ##始终保持事件监听状态11 --excludei <pattern>12                         Like --exclude but case insensitive.   ##排除文件或目录时,不区分大小写13 --timefmt <fmt> strftime-compatible format string for use with14                         %T in --format string.   ##指定时间的输出格式

复制代码

5)测试监控事件

开启两个窗口

1.测试create

     1 第一步:2 [root@nfs-server inotify-tools]# /usr/local/inotify-tools/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e create /data  ##实行当前命令后,界面处于阻塞状态,只有在另外一个客户端测试时,才会显示监控状态3 31/01/16 10:23 /data/ceshi.txt4 31/01/16 10:24 /data/what5 31/01/16 10:27 /data/a6 31/01/16 10:27 /data/b7 31/01/16 10:27 /data/c8 31/01/16 10:27 /data/d9 31/01/16 10:27 /data/e10 31/01/16 10:27 /data/f11 12 第二步:13 克隆一个NFS客户端切换到/data目录下,新建ceshi.txt、what文件,观察监控的变化14 [root@nfs-server data]# touch ceshi.txt15 [root@nfs-server data]# mkdir /who16 [root@nfs-server data]# touch what17 [root@nfs-server data]# 18 [root@nfs-server data]# touch {a..f}

2、测试delete

    1 [root@nfs-server inotify-tools]# /usr/local/inotify-tools/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e delete /data   ##监控/data目录删除时间2 3 监控如下:4 5 31/01/16 10:31 /data/reew.txt6 31/01/16 10:31 /data/test1.txt7 8 [root@nfs-server data]# rm -f reew.txt test1.txt   ##删除这两个文件9 [root@nfs-server data]#

3、同时测试create、delete

     1 第一步:2 [root@nfs-server inotify-tools]# /usr/local/inotify-tools/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e delete,create /data3 监控输出信息:4 31/01/16 10:35 /data/hero.sh5 31/01/16 10:35 /data/a6 31/01/16 10:35 /data/f7 31/01/16 10:36 /data/b8 31/01/16 10:36 /data/c9 31/01/16 10:36 /data/d10 31/01/16 10:36 /data/e11 第二步:12 [root@nfs-server data]# touch hero.sh13 [root@nfs-server data]# ll14 [root@nfs-server data]# rm -f [a..f]15 [root@nfs-server data]# rm -f {a..f}16 [root@nfs-server data]#

复制代码
一般工作中使用到:[root@nfs-server inotify-tools]# /usr/local/inotify-tools/bin/inotifywait -mrq --timefmt ‘%d/%m/%y %H:%M’ --format ‘%T %w%f’ -e delete,create,close_write /data

工作环境中通过脚本实时同步:

     1 #!/bin/bash2 inotify=/usr/local/inotify-tools/bin/inotifywait3 $inotify -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e delete,create,close_write /data4  \5 |while read file6 do7   cd / &&8   rsync -az /data --delete rsync_backup@192.168.1.17::backup \9   --password-file=/etc/rsync.password10 done

测试:

     1 脚本属于开启状态:2 [root@nfs-server scripts]# sh -x inotify.sh 3 + inotify=/usr/local/inotify-tools/bin/inotifywait4 + read file5 + /usr/local/inotify-tools/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e delete,create,close_write /data6 + cd /7 + rsync -az /data --delete rsync_backup@192.168.1.17::backup --password-file=/etc/rsync.password8 + read file9 + cd /10 + rsync -az /data --delete rsync_backup@192.168.1.17::backup --password11 接着在NFS客户端/data目录下创建文件12 [root@nfs-server data]# touch {a..z}13 [root@nfs-server data]# echo i am best >a  ##修改a中的内容,查看热备服务器是否同步14 15 rsync热备服务器端显示如下:16 [root@backup //]# cd /backup/17 [root@backup backup]# cd data/18 [root@backup data]# ll19 total 020 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 a21 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 b22 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 c23 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 d24 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 e25 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 f26 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 g27 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 h28 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 i29 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 j30 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 k31 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 l32 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 m33 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 n34 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 o35 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 p36 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 q37 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 r38 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 s39 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 t40 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 u41 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 v42 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 w43 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 x44 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 y45 -rw-r--r--. 1 rsync rsync 0 Mar  4  2016 z46 [root@backup data]# cat a47 i am best   ##显示已经实时同步过来48 [root@backup data]#

复制代码

6)优化

    1 [root@nfs-server scripts]# echo "50000000" >/proc/sys/fs/inotify/max_user_watches 2 [root@nfs-server scripts]# echo "50000000" >/proc/sys/fs/inotify/max_queued_events

inotify+rsync实现实时同步部署相关推荐

  1. 【Linux下Inotify + Rsync文件实时同步】

    Linux下Inotify + Rsync文件实时同步 一.使用前言* 随着公司业务的发展,单web服务器不能满足用户的访问,需要增加多台web服务器实现均衡高可用性访问.为了统一各web服务器之间的 ...

  2. inotify+rsync实现实时同步

    1.1 什么是实时同步:如何实现实时同步 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 发现目录中数据产生变化,就利用rsync服务推送到备份服务器上 1.2 实现实时同步的方 ...

  3. inotify+rsync 实现实时同步

    为什么80%的码农都做不了架构师?>>>    实现实时同步(也就是源一变化,它就会触发同步) inotify+rsync   源服务器:172.16.12.167 同步服务器:17 ...

  4. rsync下行同步和inotify实时同步部署

    rsync下行同步和inotify实时同步部署 一.rsync概述:一款快速增量备份工具 1.Remote Sync,远程同步 2.rsync同步源 二.配置rsync源 1.基本思路 2.配置文件r ...

  5. rsync+inotfy实时同步

    rsync+inotfy实时同步 目录 一.服务器端 二.客户端 一.服务器端 1.安装网站服务,启动,但是不写首页文件 yum -y install httpd 2.安装raync服务 yum -y ...

  6. Rsync+Sersync实时同步详细配置

    Rsync+Sersync实时同步 一.基本介绍  1.什么是Rsync? Rsync(Remote Synchronize)是一款开源的.快速的.多功能的.可以实现全量及增量的本地或远程数据同步备份 ...

  7. rsync+sersync实时同步数据

    前言 rsync+sersync实时同步数据. 简介 rsync+sersync实时同步数据的原理是在客户端安装sersync监控目录的变化,一般是增删改,检测到变化以后,将变化的文件同步到服务端. ...

  8. rsync同步+inotify实时同步部署

    目录 一.rsync简介 二.rsync同步源 三.配置rsync源 1.基本思路 2.rsync命令 3.配置源的两种表达方式 4.免交互格式 四.配置rsync远程同步 1.关防火墙.安装相应的软 ...

  9. rsync下行同步+inotify实时同步部署

    目录 rsync简介 rsync同步方式 rsync特性 rsync与cp.scp对比 rsync同类服务 rsync源服务器的关系 配置rsync源 rsync命令 rsync本地复制实例 配置源的 ...

最新文章

  1. php登录注册demo,PHP实现登录功能DEMO
  2. Hologres揭秘:如何支持超高QPS在线服务(点查)场景
  3. unity 阳光插件_网络广告,阳光创信保驾护航
  4. docker java 最小镜像_Docker多步构建更小的Java镜像
  5. java路径在那_Java 路径
  6. 用HTML5做一个个人网站,此文仅展示个人主页界面。内附源代码下载地址
  7. 搭建steam游戏服务器
  8. c#开发环境下用Directx载入3D模型
  9. 构筑“数据连接器”,腾讯云大数据推出“开源开放”战略
  10. 【CSS】1340- CSS 渲染原理以及优化策略
  11. html 图片上面显示文字,Html 让文字显示在图片的上面
  12. tp5.1 保利威视 云课堂 三分屏 PC直播DEMO(不适合普通直播)
  13. 如何在patform中加入自己的工程
  14. dds文件怎么在linux查看,Linux 环境编译 OpenDDS 全记录
  15. 定位神器:1秒定位DOM元素绑定的事件代码的位置
  16. 纪念尼古拉·特斯拉---一个伟大却很少被普罗大众认识的科学家
  17. One PUNCH Man——线性回归算法
  18. oracle中distance用法,distance的用法和短语例句
  19. 适合 Ubuntu的8款最佳录屏软件
  20. 使用延时队列搞定超时订单处理

热门文章

  1. mfc 判断文件夹复制完成_Python办公自动化|自动整理文件,一键完成!
  2. cad布局教程_CAD制图初学入门之常见的CAD打印设置汇总
  3. spring boot一个模块加载不到引用另一个模块的mapper.xml报错org.apache.ibatis.binding.BindingException: Invalid bound sta
  4. Visual C++——黄维通《 Visual C++面向对象与可视化程序设计》——例题9-3
  5. OpenWrt——Could not lock /var/lock/opkg.lock: Resource temporarily unavailable.
  6. java需要知道的计算机底层
  7. ActiveMq消费端实现集群部署
  8. hadoop-1.1.2 在centos环境下的部署
  9. 数据库查询近七天的数据
  10. 2021暑假实习-SSM超市积分管理系统-day05笔记