Chinaunix首页 | 论坛 | 博客
  • 博客访问: 242829
  • 博文数量: 55
  • 博客积分: 2160
  • 博客等级: 大尉
  • 技术积分: 598
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-08 14:36
文章分类

全部博文(55)

文章存档

2013年(1)

2012年(5)

2010年(49)

我的朋友

分类: 系统运维

2013-01-09 11:48:14

rsync+inotify优势[引用]

1、服务器性能:rsync只能实现定时更新,无论网站有无文件更新,rsync都会按着定时任务去检查文件是否有更新,当数据文件较大时会使服务器性能下降;而rsync+inotify为触发式更新,也就是说只有当某个文件发生改动时才会更新,这样一来对服务器性能影响较小

2、数据实时性:如果选择rsync,每隔多长时间同步一次数据是个问题,时间越短,对性能影响就越大。时间太长,用户/编辑无法接受。采用rsync+inotify可实现实时更新,当源服务器文件有更新时,其它服务器立即更新

 

server端:192.168.128.10

client端:192.168.128.11

 

1, client服务器rsync配置

uid = root

gid = root

use chroot = no

max connections = 20

strict modes = yes

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log format = %t %a %m %f %b

 

[web]

path = /var/www/html/

auth users = root

read only = no

hosts allow = 192.168.128.0/24

list = no

uid = root

gid = root

secrets file = /etc/rsync.secrets

ignore errors = yes

 

[root@localhost ~]# vi /etc/rsyncd.secrets

root:111111

[root@localhost ~]# chmod 600 /etc/rsyncd.secrets

[root@localhost ~]# /usr/bin/rsync --daemon --config=/etc/rsyncd.conf

 

2,server端inotifyrsync配置

[root@localhost ~]# cd /usr/local/src/

[root@localhost src]# tar zxf inotify-tools-3.13.tar.gz

[root@localhost src]# cd inotify-tools-3.13

[root@localhost inotify-tools-3.13]# ./configure

[root@localhost inotify-tools-3.13]# make && make install

[root@localhost inotify-tools-3.13]# cd

 

[root@localhost ~]# vi /etc/rsyncd.secrets

111111

[root@localhost ~]# chmod 600 /etc/rsyncd.secrets

[root@localhost ~]# vi /etc/rsync.sh

#!/bin/bash

src="/var/www/html"     #server端监控的目录

dst=web                  #client端rsync模块名

ip="192.168.128.11"       #client服务器IP,可添加多台同步服务器

#ip="192.168.128.11 192.168.128.12 192.168.128.13"  #加入多台client

#如果client数量众多,可以将所有服务器IP写入一个IP列表文件,比如:

#ip=`cat ip.txt|grep -v "#"|awk '{print $1}'  //第一列为IP

 

/usr/local/bin/inotifywait -mrq -e create,move,delete,modify ${src} | while read

 file

do

      for i in $ip

      do

          rsync -avz --password-file=/etc/rsyncd.secrets --delete --progress ${src}/* root@${ip}::${dst}

      done

done

[root@localhost ~]# chmod +x /etc/rsync.sh

[root@localhost ~]# nohup /etc/rsync.sh &

 

inotify命令参数:

m 是保持一直监听

r 是递归查看目录

q 是打印出事件

e create,move,delete,modify,attrib

监听 创建 移动 删除 写入  事件

 

--timefmt指定输出时的输出格式  例:--timefmt '%d/%m/%y-%H:%M'

--format'%T %w%f'指定输出的格式  例:--format '%T %w%f'

create:创建文件

move:文件移动

delete:文件被删除

modify:是监控文件被write

attrib:文件属性被修改

 

3,测试

启动rsync.sh监控脚本之后,server目录/var/www/html下有增、添、改、删文件操作时,将会实时同步到client服务器的/var/www/html目录。

阅读(1495) | 评论(0) | 转发(0) |
0

上一篇:Discu 社交论坛环境搭建

下一篇:没有了

给主人留下些什么吧!~~