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

Centos rsync+inotify 实现数据同步备份

时间:2014-11-14 15:30:31      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   sp   

最近公司做了一??分布式,便于管理安装了

server: 192.168.2.29

client: 192.168.2.230

先来配置client

安装就不介绍了
[root@ser-tracker-230 rsync]# ll
total 16
drwxr-xr-x. 2 root root 4096 Nov 13 04:23 bin
-rw-r--r--. 1 root root  405 Nov 14 01:19 rsyncd.conf
-rw-------. 1 root root   18 Nov 13 04:24 rsync.passwd
drwxr-xr-x. 3 root root 4096 Nov 13 04:23 share

[root@ser-tracker-230 rsync]# vim rsyncd.conf 
rsyncd.conf 

uid = root
gid = root
use chroot = no
max connections =10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[web] #需要同步的文件 
path = /home/rsync/
comment = web file
ignore errors
read only = no
write only = no
hosts allow = 192.168.2.29
hosts deny = *
list = false
uid = root
gid = root
auth users = webuser
secrets file = /usr/local/rsync/rsync.passwd

 

vim rsync.passwd  密码
webuser:rsync-pwd
/usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/rsyncd.conf

[root@ser-tracker-230 rsync]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT   防火qiang

客户端,就安装完了,注意查看日志

/var/log/rsyncd.log
服务器配置:

 

 

[root@localhost test]# ll /proc/sys/fs/inotify
total 0
-rw-r--r-- 1 root root 0 Nov 14 11:37 max_queued_events
-rw-r--r-- 1 root root 0 Nov 14 11:37 max_user_instances
-rw-r--r-- 1 root root 0 Nov 14 11:35 max_user_watches
安装
安装inotify工具inotify-tools
#都安装到 /usr/local/inotify/

主要是sh 文件 

[root@localhost rsync]# ll
total 16
drwxr-xr-x 2 root root  18 Nov 13 16:57 bin
-rw-r--r-- 1 root root 427 Nov 14 14:05 inotifyrsync.sh
-rw------- 1 root root  10 Nov 13 16:59 rsync.passwd
------------------------------------------------------------------------------------------------
vim  rsync.passwd
rsync-pwd

vim inotifyrsync.sh

#!/bin/bash
host1=192.168.2.230

src=/home/rsync/test
dst1=web
user1=webuser
/usr/local/inotify/bin/inotifywait -mrq --timefmt %d/%m/%y %H:%M --format %T %w%f%e -e modify,delete,create,attrib  $src | while read files
    do
                /usr/local/rsync/bin/rsync -vzrtopg --delete --progress --password-file=/usr/local/rsync/rsync.passwd $src $user1@$host1::$dst1
        echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
    done

echo  "/usr/local/rsync/inotifyrsync.sh &" >> /etc/rc.local

这样子,就OK了

参考 http://ixdba.blog.51cto.com/2895551/580280

Centos rsync+inotify 实现数据同步备份

标签:des   style   blog   http   io   color   ar   os   sp   

原文地址:http://www.cnblogs.com/jackluo/p/4097274.html

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