Inotify + rsync

博客已经搬家,请访问如下地址:http://www.czhphp.com

Inotify + rsync:

需求:
rsync3.x
inotify-tools

条件:
需要实时同步的两台主机:

10.3.0.173  server

10.3.0.215  分发服务器

 

同步的网站目录: /home/rsync/

 

 

1 install:

 

# cd /usr/local/src
# wget http://www.samba.org/ftp/rsync/s ... nc-3.0.6pre1.tar.gz
# wget http://jaist.dl.sourceforge.net/ ... y-tools-3.13.tar.gz

 

Server安装:

# tar zxvf rsync-3.0.6pre1.tar.gz
# cd rsync-3.0.6pre1
# ./configure --prefix=/usr && make && make install

 

分发安装:
# tar zxvf inotify-tools-3.13.tar.gz
# cd inotify-tools-3.13
# ./configure && make && make install

# ln -sv /usr/local/lib/libinotify* /usr/lib/

Server配置文件:

Vim /etc/rsyncd.conf

 

 

Chmod 600 /etc/rsyncd.conf 

 

分发脚本:

Vim /etc/rsync.pass

 

 

 

Chmod 600 /etc/rsync.pass

 

 

Vim /etc/inotify.sh

 

  1 #!/bin/sh                                                                                                                              

  2 src=/home/wwwroot/rsync/

  3 des=log

  4 ip=10.3.0.173

  5

  6 /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w%f' \

  7 -e modify,delete,create,attrib \

  8 ${src} \

  9 | while read files

 10     do

 11    rsync -vzrtopg --delete --progress --password-file=/etc/rsync.pass ${src} root@${ip}::${des}

 12         echo "${src} was rsynced"

 13         echo "-----------------------------------------------------"

 14     done

~              

 

chmod a+x /etc/inotify.sh

 

/etc/inotify.sh &

 

echo “/etc/inotify.sh &” >> /etc/rc.local

博客已经搬家,请访问如下地址:http://www.czhphp.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值