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