需要同步的机器我们搭建RSYNC服务器

yum -y install rsync

yum -y install xinetd

vim /etc/xinetd.d/rsync

disabled=no

创建rsync配置文件

vim /etc/rsyncd.conf

uid = root

gid = root

max connections = 200

timeout = 600

use chroot = no

read only = no

[etc]

path = /etc/

ignore errors

write only = no

hosts allow = 192.168.0.2

hosts deny=*

list = false


启动服务

service xinetd restart

在主服务器上安装inotify和rsync

yum -y install rsync

yum -y install inotify-tools

编写脚本用来监控

vim tongbu.sh

#!/bin/bash

host=192.168.0.3

src=/etc/nginx

dst=etc

user=root

/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \

| while read files

do

/usr/bin/rsync -vzrtopg --delete --progress $src $user@$host::$dst

echo "${file} was rsynced" >> /tmp/rsync.log 2>&1

done

赋予脚本执行权限

chmod +x tongbu.sh

运行脚本即可

./tongbu.sh

添加到启动项中

vim /etc/rc.local

/root/tongbu.sh