1. 配置rysnc server:同步机,同步被同步机更新的文件,很多台
vi /etc/rsyncd.conf
uid=root
gid=root
use chroot=no
max connections=10
timeout=600
strict modes=yes
port=873
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
log file=/var/log/rsyncd.log
[module_pk10]
path=/data/www/DePK10
comment=rsync pk10 unity
auth users=pk10
uid=root
gid=root
secrets file=/etc/rsyncd.secrets
read only=no
list=no
hosts allow=103.x.x.x
hosts deny=0.0.0.0/32

vi /etc/rsyncd.secrets
pk10:Lishen@123
chmod 600 /etc/rsyncd.secrets

启动:rsync --daemon

添加防火墙开放 873端口
-A INPUT -m state --state NEW -m tcp -p tcp -s 103.x.x.x --dport 873 -j ACCEPT

2. 客户端:被同步机一台,更新文件只需要更新到这台
vi /etc/rsync_client.pwd
Lishen@123
chmod 600 /etc/rsync_client.pwd

mkdir  /etc/rsyncd.d/
touch  /etc/rsyncd.d/rsync_exclude.lst

安装inotify:yum install -y inotify-tools

监控和同步脚本:
vi rsync.sh
#rsync auto sync script with inotify

#variables
current_date=$(date +%Y%m%d_%H%M%S)
source_path=/data/www/DePK10/
log_file=/var/log/rsync_client.log

#rsync
rsync_server="xxx.xxx.xxx.xxx

xxx.xxx.xxx.xxx"

rsync_user=pk10
rsync_pwd=/etc/rsync_client.pwd
rsync_module=module_pk10
INOTIFY_EXCLUDE='(.*/*\.log|.*/*\.swp)$'
RSYNC_EXCLUDE='/etc/rsyncd.d/rsync_exclude.lst'

#rsync client pwd check
if [ ! -e ${rsync_pwd} ];then
    echo -e "rsync client passwod file ${rsync_pwd} does not exist!"
    exit 0
fi
#inotify_function
inotify_fun(){
    /usr/bin/inotifywait -mrq --timefmt '%Y/%m/%d-%H:%M:%S' --format '%T %w %f' \
          --exclude ${INOTIFY_EXCLUDE}  -e modify,delete,create,move,attrib ${source_path} \
          | while read file
      do
          for server in $rsync_server
          do
              /usr/bin/rsync -auvrtzopgP --delete --exclude-from=${RSYNC_EXCLUDE} --progress --bwlimit=200 --password-file=${rsync_pwd} ${source_path} ${rsync_user}@${server}::${rsync_module}
          done
      done
}
#inotify log
inotify_fun >> ${log_file} 2>&1 &

参考:http://seanlook.com/2014/12/12/rsync_inotify_setup/

rsync + inotify 同步的更多相关文章

  1. Rsync+Inotify同步

    rsync服务安装与<rsync+sersync同步>环境一样! 安装inotify-tools 在源服务器10.10.2.191上操作: 1.查看服务器内核是否支持inotify ll ...

  2. 使用rsync+inotify同步两台服务器文件

    目标功能:将B服务器文件同步到A服务器 A服务器rsyncd.conf配置 权限600 A服务器rsyncd.pas文件配置  权限600 同步文件路径 /data/wwwroot/shen/  权限 ...

  3. rsync+inotify同步备份

    1.rsync与scp区别 scp无法备份大量数据,先统计文件信息,后进行拷贝,如果文件大小超出磁盘空间,则无法拷贝 rsync边复制,边比较,边统计 2.rsync特点 (1.)支持增量备份 (2. ...

  4. rsync+inotify同步备份文件

    前言 rsync作用:man rsync可以看到解释为a fast, versatile, remote (and local) file-copying tool,主要进行文件的同步. inotif ...

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

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

  6. Rsync+inotify实现实时同步

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

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

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

  8. Centos 6.5 rsync+inotify 两台服务器文件实时同步

    rsync和inotify是什么我这里就不在介绍了,有专门的文章介绍这两个工具. 1.两台服务器IP地址分别为: 源服务器:192.168.1.2 目标服务器:192.168.1.3 @todo:从源 ...

  9. 通过rsync+inotify实现数据实时备份同步

    一.环境描述 测试环境 需求:服务器A与服务器B为主备服务模式,需要保持文件一致性,现采用sersync基于rsync+inotify实现数据实时同步 环境描述: 主服务器172.26.7.50 ,从 ...

随机推荐

  1. node express 登录拦截器 request接口请求

    1.拦截器 拦截器可以根据需要 做权限拦截 登录只是权限的一种, 思路是req.session.user判断用户session是否存在,是否是需要拦截的地址, 如果是就跳转登录页,或其他页, 如果非需 ...

  2. Python列表深浅复制详解

    转自:https://www.cnblogs.com/blaomao/p/7239203.html 在文章<Python 数据类型>里边介绍了列表的用法,其中列表有个 copy() 方法, ...

  3. 三 APPIUM GUI讲解(Windows版)

    本文本转自:http://www.cnblogs.com/sundalian/p/5629386.html APPIUM GUI讲解(Windows版)   Windows版本的APPIUM GUI有 ...

  4. 孤荷凌寒自学python第三天 初识序列

    孤荷凌寒自学python第三天 初识序列 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) Python的序列非常让我着迷,之前学习的其它编程语言中没有非常特别关注过序列这种类型的对象,而pyt ...

  5. Vue打包app

    前言 公司之前用的app就是一个套壳挂个链接就能用的app,后来需要添加微信分享方便传播,没办法只好做成混合式的app了, 因为之前做.net用vs可以创建cordova项目也试着玩过,就决定用cor ...

  6. 第三节 MVC应用程序架构和测试

    在查看如何测试单个功能之后,您可能会问,整个Web应用程序如何? 如前所述,有以下级别的测试: 单元测试 集成测试 功能测试 在开始编写测试时考虑这一点很重要. 可能还有其他类型的测试,但现在让我们关 ...

  7. HDU 1937 F - Finding Seats 枚举

    F - Finding Seats Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. vue cli 3 & webpack-merge & webpack 3 & bug

    vue cli 3 & webpack-merge & webpack & bug bug webpack-merge & bug webpack-merge ??? ...

  9. POJ 3974 Palindrome | 马拉车模板

    给一个字符串,求最长回文字串有多长 #include<cstdio> #include<algorithm> #include<cstring> #define N ...

  10. Redis安装 java中的连接 序列化 反序列化

    安装路径 /webapp/redis/redis- #启动redis /webapp/redis/redis-/src/redis-server & #关闭redis /webapp/redi ...