rsync inotify

rsync + inotify 触发式同步
【基本介绍】
rsync :
rsync is a program that behaves in much the same way that rcp does, but has many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file is being updated.

inotify :
The inotify API provides a mechanism for monitoring file system events.Inotify can be used to monitor individual files, or to monitor directo-ries. When a directory is monitored, inotify will return events for the directory itself, and for files inside the directory.

rsync+inotify ,实现监控某个文件或目录,实现实时同步到远程地址。1->n的传输需求(1为客户端,n为服务端,客户端不需要配置rsync服务器,启动inotify监听脚本。服务端启动rsync daemon)

【rsync 安装配置】
rsync 安装---省略几百字

#touch /etc/rsyncd/rsyncd.conf #创建rsync服务器的配置文件;

#touch /etc/rsyncd/rsyncd.secrets 创建用户密码文件;

#chmod 600 /etc/rsyncd/rsyncd.secrets 我们把权限设为600;

rsyncd.conf:
uid=root
gid=nobody
max connections=200
timeout=600
use chroot=no
use chroot=no
read only=false
log file=/var/log/rsyncd.log
pid file=/var/log/rsyncd.pid
lock file=/var/log/rsync.lock
host_allow=xxxx (这个需要传输的服务器地址)
[app]
path=xxxx (这个就是传输的地址)
comment=xxx
list=yes
auth users=web
secrets file=/etc/rsyncd.secrets

rsyncd.secrets: (客户端与服务端一致,客户端不需要用户名)
web:@xxxxxxxxxxxxxxx@

【inotify】
inotify : 安装省略数百字


【rsync+inotify】
rsync.sh:
#!/bin/sh
src1=/xxxx #(监听的路径)
/usr/local/inotify/bin/inotifywait --exclude "xxx" -mrq -e create,move,delete,modify $src1 | while read file
do
rsync -zaq --delete --port=8730 --password-file=/etc/rsyncd.secrets --exclude=log/ $src1 web@xxxx::app #(每个客户端遍历一遍,app是定义的模块名)
rsync -zaq --delete --port=8730 --password-file=/etc/rsyncd.secrets --exclude=log/ $src1 web@xxxx::app
rsync -zaq --delete --port=8730 --password-file=/etc/rsyncd.secrets --exclude=log/ $src1 web@xxxx::app
done

在服务器端运行这个脚本即可实现实时同步。

【基本流程】
1.在服务器端/客户端安装rsync
2.在客户端安装inotify
3.配置服务端的rsync daemon或者rsync服务器监听
4.服务器端和客户端都设置rsyncd.secrets密码文件(客户端只需要密码,服务端用户名:密码)
4.在客户端端实现rsync+inotify脚本


【参考】
[url]http://wenku.baidu.com/link?url=7xvTMZ2IvlMwrjt7-NQvwRNM4tyWcY5TmIvIKZxcCyrdck9x7tBEIgDN7cwM1V-hrC0Wlp8VDFK16pAwEyIanagEj7wnfM0ZYEAbNcnelly[/url]
rsync : [url]http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/[/url]
about exclude: [url]http://www.infoq.com/articles/inotify-linux-file-system-event-monitoring[/url]
[url]http://blog.coocla.org/199.html[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值