CentOS服务器网络数据实时同步之 inotify + rsync
分类:CentOS运维 阅读:17308 次
实例:
假设web01与web02是公司的网站,我们在内容发布服务器中添加数据,inotify检测到有数据更新通过rsync实时传输到web01与web02。
一、web配置(web01与web02配置几乎一致,留意红色部分)
# vi /etc/rsyncd.conf
# filename:/etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 10
# set password
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[web_01]
path = /var/www/html
comment = web dir
ignore errors
read only = no
write only = no
hosts allow = 172.16.10.0/255.255.255.0
hosts deny = *
list = false
auth = backup
secrets file = /etc/rsyncd.auth
# echo backup:backup>/etc/rsyncd.auth
# chmod 600 /etc/rsyncd.auth
二、内容发布服务器配置
//安装inotify-tool # tar zxvf inotify-tools-3.14.tar.gz # cd inotify-tools-3.14 # ./configure;make;make install //建立rsync验证文件 # echo backup:backup>/etc/rsyncd.auth # chmod 600 /etc/rsyncd.auth
[root@10.1 ~]# vi inotify_rsync.sh #!/bin/bash # This rsync script based on inotify. export PATH=/bin:/usr/bin:/usr/local/bin src=/var/www/html/ dst=/var/www/html/ client1=172.16.10.101 client2=172.16.10.102 user=backup #password file must not be other-accessible. Passfiles=/etc/rsyncd.auth #Wait for change inotifywait -mrq --timefmt '%d-%m-%y %H:%M' --format '%T %w %fi %e' --event modify,delete,create,attrib $src|while read files do rsync -vzrtopg --progress --delete --password-file=$Passfiles $src $user@$client1::$dst rsync -vzrtopg --progress --delete --password-file=$Passfiles $src $user@$client2::$dst echo "${files} was rsynced" >> /var/log/inotify_web 2>&1 done
后台运行以上shell脚本,并在内容发布服务器上进行文件修改等操作
日志一览
# cat /var/log/inotify_web 12-09-14 14:41 /var/www/html test_01i MODIFY was rsynced 12-09-14 14:42 /var/www/html test_01i MODIFY was rsynced 12-09-14 14:43 /var/www/html auditdi CREATE was rsynced 12-09-14 14:43 /var/www/html auditdi MODIFY was rsynced 12-09-14 14:43 /var/www/html blk-availabilityi CREATE was rsynced 12-09-14 14:43 /var/www/html blk-availabilityi MODIFY was rsynced 12-09-14 14:43 /var/www/html cgconfigi CREATE was rsynced 12-09-14 14:43 /var/www/html cgconfigi MODIFY was rsynced 12-09-14 14:43 /var/www/html cgredi CREATE was rsynced 12-09-14 14:43 /var/www/html cgredi MODIFY was rsynced 12-09-14 14:43 /var/www/html crondi CREATE was rsynced 12-09-14 14:43 /var/www/html crondi MODIFY was rsynced 12-09-14 14:43 /var/www/html drbdi CREATE was rsynced 12-09-14 14:43 /var/www/html drbdi MODIFY was rsynced 12-09-14 14:43 /var/www/html fcoei CREATE was rsynced 12-09-14 14:43 /var/www/html fcoei MODIFY was rsynced 12-09-14 14:43 /var/www/html functionsi CREATE was rsynced 12-09-14 14:43 /var/www/html functionsi MODIFY was rsynced 12-09-14 14:43 /var/www/html halti CREATE was rsynced 12-09-14 14:43 /var/www/html halti MODIFY was rsynced 12-09-14 14:43 /var/www/html htcachecleani CREATE was rsynced 12-09-14 14:43 /var/www/html htcachecleani MODIFY was rsynced
热门推荐
- CentOS6配置tomcat搭建JSP应用服务器
- centos 6.4服务器部署svn+httpd
- Centos 6.4下yum安装简单实现LNMP架构
- centos6.4 LAMP服务器安装配置
- centos6.5配置pptpd搭建VPN服务
- CentOS下更改MySQL默认datadir的方法
- CentOS7 + Apache2.4 + Mysql5.5 + PHP5.5
- CentOS7安装samba4.1.1
- CentOS LAMP环境搭建(基于Apache模块)
- CentOS LAMP环境搭建(基于fastcgi)
- CentOS7环境下ceph安装部署
- centos7下yum快速安装 mariadb(mysql)
- centos搭建rsyslog日志服务器
- CentOS安装DB2数据库
- CentOS6.5系统搭建php服务器
- CentOS6.5下DHCP服务器配置
- centos7.0系统lvs安装部署
- Centos6.4快速构建基于用户名密码验证的openvpn服务器
- Centos6.5重置mysql密码并设置允许远程连接
- CentOS6架构PPTP VPN服务器之实践