码迷,mamicode.com
首页 > 其他好文 > 详细

rsync+inotify部署

时间:2014-10-28 15:46:54      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:nobody   网站   file   主机   

为了满足需要,之前的rsync定时推送服务,无法满足现实需要,在次更新网站架构

环境介绍:

网站Nginx集群搭建的,因为网站的数内容时常更新,但是一台一台的更新数据非常消耗时间。因此采用rsync+inotify,将数据实时的推送到集群主机上去。

远程网站IP172.16.100.99  /usr/html 

远程网站IP:172.16.100.97  /usr/html

本地推送IP:172.16.100.98  /web/data

环境:

RedHat5.9

rsync-3.1.1.tar.gz

inotify-tools-3.14.tar.gz


远程端IP99安装:

1.编译安装rsync-3.1.1.tar.gz

  tar  zxvf  rsync-3.1.1.tar.gz

  cd rsync-3.1.1

  ./configre

  make

  make install

2.编写rsyncd.conf配置文件

  uid = nobody

  gid = nobody

  max connections = 10

  use chroot = no

  strict mode = no

  pid file = /var/run/rsyncd.pid

  lock file = /var/lock/rsync.lock

  log file = /var/log/rsyncd.log

  [web99]

  path = /usr/html

  comment = Nginx‘s page comment

  read only = no

  write only = no

  ignore errors

  uid = root

  gid = root

  host deny = *

  host allow = 172.16.100.98

  list = false

  auth users = backup99

  secrets file = /etc/server.pass

3.编写可访问推送端主机的密码文件

  vi /etc/server.pass

  backup99:123456

4.更改密码文件权限

  chmod  600  /etc/server.pass

远程端IP97安装:

1.编译安装rsync-3.1.1.tar.gz

  tar  zxvf  rsync-3.1.1.tar.gz

  cd rsync-3.1.1

  ./configre

  make

  make install

2.编写rsyncd.conf配置文件

  uid = nobody

  gid = nobody

  max connections = 10

  use chroot = no

  strict mode = no

  pid file = /var/run/rsyncd.pid

  lock file = /var/lock/rsync.lock

  log file = /var/log/rsyncd.log

  [web97]

  path = /usr/html

  comment = Nginx‘s page comment

  read only = no

  write only = no

  ignore errors

  uid = root

  gid = root

  host deny = *

  host allow = 172.16.100.98

  list = false

  auth users = backup97

  secrets file = /etc/server.pass

3.编写可访问推送端主机的密码文件

  vi /etc/server.pass

  backup97:123456

4.更改密码文件权限

  chmod  600  /etc/server.pass

远程端IP98安装

1.编译安装rsync-3.1.1.tar.gz

  tar  zxvf  rsync-3.1.1.tar.gz

  cd rsync-3.1.1

  ./configre

  make

  make install

2.编译安装inotify-tools-3.14.tar.gz

  tar zxvf inotify-tools-3.14.tar.gz

  cd  inotify-tools-3.14

  ./configure

  make

  make intall

3.编写inotify同步脚本

 vi inotify-sync.sh

 #!/bin/bash
 host1=172.16.100.99
 host2=172.16.100.97
 src=/web/data/
 dst1=web99
 dst2=web97
 #dst2=images
 user1=backup99
 user2=backup97
 inotifywait -mrq --timefmt ‘%d/%m/%y %H:%M‘ --format ‘%T %w%f%e‘ -e     modify,create,delete,attrib $src |while read files
 do
 rsync -vzrtopg  --delete  --progress  --exclude "*access*" --exclude "*debug*"  --password-file=/etc/server.pass  $src $user1@$host1::$dst1
 rsync -vzrtopg  --delete  --progress  --exclude "*access*" --exclude "*debug*"  --password-file=/etc/server.pass  $src $user2@$host2::$dst2
 echo "${files} was rsyncd" >> /var/log/rsync.log 2>&1
 done


本文出自 “常用文档” 博客,请务必保留此出处http://yujianglei.blog.51cto.com/7215578/1568742

rsync+inotify部署

标签:nobody   网站   file   主机   

原文地址:http://yujianglei.blog.51cto.com/7215578/1568742

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!