Discuz! Board

标题: rsync+inotify实时同步部署 [打印本页]

作者: zhangdong    时间: 2015-11-27 17:58
标题: rsync+inotify实时同步部署
系统平台环境:

            操作系统:Centos6.5_64位            安装包:inotify-tools-3.14.tar.gz
                          rsync
业务场景:有3台服务器,需要从node1指定目录的数据同步到node2、node3

配置:

     Node1:

            inotify配置:

#!/bin/bash
src=/data/www/
des=pic2
ip=10.6.18.42
ip2=10.10.146.17
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,create,attrib $src | while read file
do
rsync -vzrtopg --port=872 --progress $src pic2user@$ip:des --password-file=/etc/server.pass > /dev/null 2>&1 && echo "$src was rsynced"
rsync -vzrtopg --port=872 --progress $src pic2user@$ip2:des --password-file=/etc/server.pass > /dev/null 2>&1 && echo "$src was rsynced"
echo "${files} was rsynced" >>/data/log/rsync.log 2>&1
done


安装rsync客户端

Node2:

      rsync服务端配置:
root@Moretv-BJUC-nginx-pic-server-02 www]# cat /etc/rsyncd_server.conf
uid = root
gid = root
use chroot = no
max connections = 10
port = 872
##config file
pid file = /var/run/rsyncd_server.pid
lock file = /var/run/rsync.lock
log file = /data/logs/rsyncd.log

##global config
[pic2]
path =/data/www/
comment = pic2 file
read only = no
ignore errors
read only = false
write only = no
hosts allow = 10.6.24.218
##client sync config
auth users =pic2user
secrets file = /etc/server.pass


密码文件:
[root@Moretv-BJUC-nginx-pic-server-02 www]# cat /etc/server.pass
pic2user:pic2user123456


node3

rsync服务端配置:

同Node2配置一样










欢迎光临 Discuz! Board (http://123.59.83.120:8080/) Powered by Discuz! X3.2