centos6.5-rsync+inotify

一、目的

   通过监控192.168.3.10的目录,实现实时同步。

实验环境

centos1       192.168.3.10

centos2       192.168.3.11

 

二、配置

centos1

service iptables stop

 

创建监控目录

mkdir /abc

1.安装intoify

tar xf inotify-tools-3.14.tar.gz

cd inotify-tools-3.14

./configure

make && make install

2.调整系统文件

vim /etc/sysctl.conf

增加以下几行内容

fs.inotify.max_queued_events = 16384

fs.inotify.max_user_instances = 1024

fs.inotify.max_user_watches = 1048576

sysctl -p    #生效配置

 

3.编写触发脚本

vim rsync.sh

#!/bin/bash
inotify_cmd="inotifywait -mrq -e modify,create,move,attrib,delete /abc/"
rsync_cmd="rsync -avzP --delete /abc/ rsync://192.168.3.11/wwwroot"
$inotify_cmd | while read DIRECTORY EVENT FILE
do
    $rsync_cmd &> /dev/null
done

4、配置centos2

service iptables stop

 

创建同步目录

mkdir /abc

chmod -R  777 /abc

 

创建rsync配置文件

vim /etc/rsyncd.conf

uid = nobody

gid = nobody

use chroot = no

address = 192.168.3.11

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

host allow =192.168.3.10

 

[wwwroot]

path = /abc

comment = abc

read only = no

 

 

启动rsync

rsync --daemon

 

测试

启动脚本

sh rsync.sh

 

在centos1的abc目录下创建目录或是文件,查看centos2的abc目录下是否有文件

 

posted @ 2017-03-11 12:00  借风拥你  阅读(192)  评论(0编辑  收藏  举报