Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1732680
  • 博文数量: 234
  • 博客积分: 4966
  • 博客等级: 上校
  • 技术积分: 3322
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-13 01:03
文章分类

全部博文(234)

文章存档

2017年(2)

2016年(1)

2015年(8)

2014年(11)

2013年(44)

2012年(27)

2011年(22)

2010年(30)

2009年(37)

2008年(6)

2007年(45)

2006年(1)

分类: 系统运维

2013-01-26 12:32:31

inotify配合rsync实时同步备份服务器数据



主服务器需安装配置,用于实时监控服务器文件变化。
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/



阅读(1952) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~