二、rsync配置
1、分别在三台主机上安装rsync(一般CentOS系统默认都安装了):
yum install rsync
2、slave配置
手动在slave节点 /etc 下添加 rsyncd.conf 内容如下:
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[web]
path = /web/wwwroot/
comment = web file
ignore errors
read only = no
write only = no
hosts allow = *
#hosts deny = *
list = false
uid = root
gid = root
将rsync添加到开机启动
echo "/usr/bin/rsync --daemon" >> /etc/rc.local
三、master同步检测
1、master检测脚本
- #!/bin/bash
- SRC=/web/wwwroot/
- INWT=/usr/local/bin/inotifywait
- host1=(192.168.1.71 192.168.1.72)
- user=webuser
- $INWT -mrq --timefmt '%Y/%m/%d %H:%M:%S' --format '%T %w%f%e' \
- -e close_write,delete,create,attrib,move $SRC \
- | while read files
- do
- for ((i=0;i<${#host1[@]};i++))
- do
- /usr/bin/rsync -vzrtopg --delete --progress $SRC $user@${host1[$i]}::web
- echo "${files} was rsynced ${host1[$i]}" >>/tmp/rsync.log 2>&1
- done
- done
将上述脚本(内容根据自己实际情况修改)保存为 rs.sh,赋予执行权限,并加入到开机启动中,这里不再啰嗦。
2、效果测试
在master上启动脚本
sh rs.sh
在master建立测试文件

master上输出结果:

查看slave结果:

如图所示,测试ok了。
