您的位置:首页 > 其它

rsync+inotify 实现服务器之间文件实时同步

2012-11-01 12:56 971 查看
- -就是为了同步文件....所以就弄这么一个东西试试效果了.....之前有使用一个 sersync 的...但是好像有时候文件 更改以后...不会同步....有点郁闷.........Inotify 是一种强大的、细粒度的、异步的文件系统事件监控机制,linux内核从2.6.13起,加入了Inotify支持,通过Inotify可以监控文件系统中添加、删除,修改、移动等各种细微事件,利用这个内核接口,第三方软件就可以监控文件系统下文件的各种变化情况,而inotify-tools就是这样的一个第三方软件。rsync 就不介绍了,地球人都知道.... 主服务器安装 rsync + inotify 同步服务器安装 rsync 主服务器ip 10.8.8.9 同步服务器ip 10.8.8.10 一 主服务器:CentOS默认已经安装了rsync 服务.. 输入 rsync 命令可查看是否安装. [root@localhost opt]# rsyncrsync version 3.0.6 protocol version 30Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.Web site: http://rsync.samba.org/.......................................输出以上信息...表示已经安装了........创建rsync 目录 ,用来存放配置文件,密码文件.[root@localhost opt]# mkdir rsync [root@localhost opt]# echo "rsyncpasswd" >/opt/rsync/rsync.passwd[root@localhost opt]# chmod 600 /opt/rsync/rsync.passwd下载 Inotify ....[root@localhost software]# wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz [root@localhost software]# tar zxvf inotify-tools-3.14.tar.gz [root@localhost software]# cd inotify-tools-3.14[root@localhost inotify-tools-3.14]# ./configure --prefix=/opt/local/inotify[root@localhost inotify-tools-3.14]# make && make install 然后创建 rsync 的监控脚本[root@localhost inotify-tools-3.14]# cd /opt/rsync/[root@localhost rsync]# vi rsync.sh------------------------------------------------------------------------- #!/bin/bashhost=10.8.8.10 src=/opt/htdocs/system/des=systemuser=webuser /opt/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \| while read files do /usr/bin/rsync -vzrtopg --delete --progress --password-file=/opt/rsync/rsync.passwd $src $user@$host::$des echo "${files} was rsynced" >>/opt/rsync/rsync.log 2>&1done ------------------------------------------------------------------------------------[root@localhost rsync]# chmod 764 rsync.sh[root@localhost rsync]# /opt/rsync/rsync.sh & 二 同步服务器: [root@localhost opt]# mkdir rsync [root@localhost opt]# echo "webuser:rsyncpasswd" >/opt/rsync/rsync.passwd[root@localhost opt]# chmod 600 /opt/rsync/rsync.passwd接下来就要创建 rsync 的配置文件了...[root@localhost rsync]# vi rsyncd.conf----------------------------------------------------------------------------- #Global Settingsuid = rootgid = rootuse chroot = nomax connections = 10log file = /opt/rsync/log/rsyncd.logpid file = /opt/rsync/rsyncd.pidlock file = /opt/rsync/rsync.lock [system]path = /opt/htdocs/systemcomment = web fileignore errors = yesread only = nowrite only = nohosts allow = 10.8.8.9hosts deny = *list = falseauth users = webusersecrets file = /opt/rsync/rsync.passwd ----------------------------------------------------------------------------- 启动rsync /usr/bin/rsync --daemon --config=/opt/rsync/rsyncd.conf
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  rsync