rsyncinotify实时数据同步 环境 两台Centos6.1 X86 rsync server :192.168.66.128 rsync client :192.168.66.194 一.软件安装 inotify-tools-3.14.tar.gz rsync-3.0.9.tar.gz #rsync server tar -zxvf rsync-3.0.9.tar.gz cd rsync-3.0.9 ./configure && make && make install vim /etc/rsyncd.conf #配置文件默认没有,须要本身建立 uid = root gid = root user chroot = no max connections = 300 timeout = 300 pid file = /var/run/rsyncd.pid log file = /var/log/rsyncd.log lock file = /var/run/rsync.lock [mysql] path =/data/www/mysql ignore errors read only = no list = no auth users = baocheng secrets file = /etc/rsync.secrets hosts allow = 192.168.66.0/24 hosts deny = 10.0.0.0/24 vim /etc/rsync.secrets #用户密码文件 baocheng:redhat #用户必须真实存在 chmod 600 /etc/rsync.secrets #更改权限 rsync --daemon #启动rsync 能够用 netstat -tunlp |grep :873 查看进程端口 ##rsync client #rsync server tar -zxvf rsync-3.0.9.tar.gz cd rsync-3.0.9 ./configure && make && make install rsync -avzP /data/www/mysql/ baocheng@192.168.66.128::mysql/ --password-file=/etc/rsync.secrets #测试是否能同步到服务器 rsync -avzP baocheng@192.168.66.128::mysql/ --password-file=/etc/rsync.secrets /data/ #测试可否从服务器同步到客户端 更新源服务器:192.168.66.194 inotify-tools-3.14.tar.gz tar -zxf inotify-tools-3.14.tar.gz cd inotify-tools-3.14 ./configure --prefix=/usr/local/inotify make && make install ################################监控同步脚本 #!/bin/bash src=/data/www/ /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read file do /usr/bin/rsync -arzuq --delete --progress $src www1@192.168.66.128::web1 --password-file=/etc/www1.pwd && echo " ${file} was rsynced" >>/tmp/rsync.log 2>&1 done