分类: 系统运维
2013-01-26 12:32:31
主服务器需安装配置,用于实时监控服务器文件变化。
inotify-tool实时监控并发送文件到rsync从服务器脚本:
cat sync.sh
#!/bin/bash host=webbak (从服务器) src=/var/www/html dst=www user=web passwd=******* echo "$passwd" > /etc/rsyncd.secrets chmod 600 /etc/rsyncd.secrets inotifywait -mrq -e close_write,create,delete,attrib --timefmt '%d/%m/%y %H:%M' --format '%T %w%f %e' $src\ |while read files do rsync -vzrtopg --delete --progress $src $user@$host::$dst --password-file=/etc/rsyncd.secrets echo "$files was rsynced" >> /var/log/rsyncd.log done
启动脚本:
nohup ./sync.sh &
从服务器配置rsync:
read only = yes list = no uid = nobody gid = nobody use chroot = no max connections = 10 strict modes = yes log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock motd file = /etc/rsyncd.motd [www] path = /var/www comment = www file ignore errors hosts allow = webhost (主服务器) list = no auth users = web secrets file = /etc/rsyncd.secrets read only = no write only = no uid = root gid = root
建立验证文件,root权限可查看:
echo "web:passwd" > /etc/server.pass chmod 600 /etc/rsyncd.secrets
启动rsync进程:
rsync --daemon echo "rsync --daemon" >> /etc/rc.local 目录同步时查看nohup.log发现rsync的一些错误解决办法:
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1296) [receiver=2.6.8]
原因及解决办法:
SELinux;
setsebool -P rsync_disable_trans=1
@ERROR: auth failed on module GacErrLog
rsync error: error starting client-server protocol (code 5) at main.c(1296) [sender=2.6.8]
原因:
rsyncd里面配置passwd是
username:password 这样的格式
客户端使用的时候,不能用这种格式,文件里面只能有password
解决方法:
1. 文件内容修改
2. rsync -av --password-file <(echo PASSWORD) src dest
参考自:
http://blog.onovps.com/archives/rsync-inotify.html
http://rickie622.blog.163.com/blog/static/212388112011102193025502/