Rootop 服务器运维与web架构

通过inotify+rsync实时同步(推送)多台服务器

| 暂无评论

在之前的《inotify+rsync实现实时同步》基础之上进行修改脚本,实现多台服务器推送数据。之前文章配置请参考:https://www.rootop.org/pages/2142.html

#!/bin/bash
DESTHOST=/root/hosts.txt
SRCDIR=/root/test/
INOTIFYWAIT=/usr/local/inotify/bin/inotifywait

$INOTIFYWAIT -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $SRCDIR \
| while read files

do

cat $DESTHOST | while read line
do
rsync -avz --delete --password-file=/etc/rsync.passwd $SRCDIR root@$line::test
echo "${files} was rsynced to $line" >> /tmp/rsync.log 2>&1
done
done

DESTHOST=/root/hosts.txt    //要推送的服务器ip地址,一行一个。
SRCDIR=/root/test/                 //源文件夹

所有的rsync客户端,认证用户及密码必须一样。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/2221.html

作者:Venus

服务器运维与性能优化

发表回复