rsync+inotify簡單搭建實時同步

一、rsync環境搭建

    1、服務端

(1)、安裝rsync

yum install -y rsync

(2)、編輯/etc/rsyncd.conf配置文件

uid = rsync 

gid = rsync 

use chroot = no

max connections = 200

timeout = 300

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

[data]

path = /data/

ignore errors

read only = false

list = false

hosts allow = 192.168.1.0/24

hosts deny 0.0.0.0/32

auth users = rsync_backup

secrets file = /etc/rsync.password

(3)、啓動rsync,病修改文件屬性

rsync --daemon

netstat -lntp  

useradd rsync -s /sbin/nologin

chown -R rsync.rsync /data

echo "rsync_backup:password" > /etc/rsync.password

chmod 600 /etc/rsync.password

    2、客戶端

(1)、配置密碼文件

echo "password" > /etc/rsync.password

(2)、傳輸文件

rsync -avz /dara [email protected]::data 

二、inotify實現同步

(1)、安裝inotify-tools

wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

tar xf inotify-tools-3.14.tar.gz

cd inotify-tools-3.14

./configure --prefix=/usr/local/inotify

make

make install

或者

yum install -y inotify-tools

(2)、編寫腳本實現實時同步

腳本內容:

                   #!/bin/sh
                   rsync -az /data/ [email protected]::data --password-file=/etc/rsync.password
                   /usr/local/inotify/bin/inotifywait -mrq --timefmt '%d%m%y %H:%M' --format '%T %w%f' -e create /data|\
                   while read line
                   do

                       rsync -az `echo $line|cut -f3 -d' '` [email protected]::data\

                        --password-file=/etc/rsync.password

                   done

        (3)、後臺運行inotify同步腳本;

                sh inotify.sh &

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章