一、服务器性能:rsync只能实现定时更新,不管网站有无文件更新,rsync都会按着定时任务去检查文件是否有更新,当数据文件较大时会使服务器性能降低;而rsync+inotify 为触发式更新,也就是说只有当某个文件发生改动时才会更新,这样一来对服务器性能影响较小。 二、数据实时性:若是选择rsync,每隔多长时间同步一次数据是个问题,时间越短,对性能影响就越大。时间太长,用户/编辑没法接受。采用rsync+inotify可实现实时更新, 当A服务器文件有更新时,其它服务器当即更新
A:192.168.1.101 B:192.168.1.102 C:192.168.1.103 D:192.168.1.104 注:数据源服务器为A,目标服务器为B、C、D
cd /data/software wget https://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz tar zxvf rsync-3.0.9.tar.gz cd rsync-3.0.9 ./configure make make install
mkdir -p /usr/local/bin /usr/bin/install -c -m 755 rsync /usr/local/bin mkdir -p /usr/local/share/man/man1 mkdir -p /usr/local/share/man/man5 if test -f rsync.1; then /usr/bin/install -c -m 644 rsync.1 /usr/local/share/man/man1; fi if test -f rsyncd.conf.5; then /usr/bin/install -c -m 644 rsyncd.conf.5 /usr/local/share/man/man5; fi
uid = root gid = root use chroot = no max connections = 20 strict modes = yes log file = /data/logs/rsyncd/rsyncd.log pid file = /data/logs/rsyncd/rsyncd.pid lock file = /data/logs/rsyncd/rsync.lock log format = %t %a %m %f %b [web] path = /data/vhosts/it121net/ auth users = username read only = no hosts allow = 192.168.1.0/24 #能够是IP段,也能够是IP地址 list = no uid = root gid = root secrets file = /etc/rsync.passwd ignore errors = yes
mkdir /data/logs/rsyncd
username:passwd
# rsync --daemon --config=/etc/rsync.conf
# echo "rsync --daemon --config=/etc/rsync.conf" >>/etc/rc.local
killall rsync
cd /data/software wget https://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz tar zxvf rsync-3.0.9.tar.gz cd rsync-3.0.9 ./configure make make install
cd /data/software wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz tar zxvf inotify-tools-3.14.tar.gz cd inotify-tools-3.14 ./configure make make install
#!/bin/sh SRC=/data/vhosts/it121net/ DES=web WEB2=192.168.1.102 WEB3=192.168.1.103 WEB4=192.168.1.104 USER=username /usr/local/bin/inotifywait -mrq -e create,move,delete,modify $SRC | while read D E F do rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB2::$DES rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB3::$DES rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB4::$DES done #注意:网络上面大部分都是显示一个中杠,多是编码的事情,实际是应该是两个杠。
#chmod +x /etc/rsync-web.sh
#nohup /etc/rsync-web.sh & //必须使用nohup放入后台执行,不然关闭终端后此脚本进程会自动结束 /etc/rsync-web.sh &
sudo pkill rsync sudo pkill inotifywait
setsebool -P rsync_disable_trans on
/usr/bin/rsync /usr/local/bin/rsync /etc/xinetd.d/rsync