歡迎您光臨本站 註冊首頁

rsync inotify-tools ssh實現觸髮式遠程實時同步

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0

1安裝

[root@server ~]# wget ftp://ftp.samba.org/pub/rsync/rsync-3.0.8.tar.gz

[root@server ~]# tar xzvf rsync-3.0.8.tar.gz

[root@server ~]# cd rsync-3.0.8

[root@server ~]# ./configure

[root@server ~]# make

[root@server ~]# make install

[root@server~]#

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

[root@server ~]# tar xzvf inotify-tools-3.14.tar.gz

[root@server ~]# cd inotify-tools-3.14

[root@server ~]# ./configure

[root@server ~]# make

[root@server ~]# make install

2.配置

ssh key信任

伺服器

[root@server ~]# useradd -m rsync

[root@server ~]# passwd rsync

客戶機

[root@client ~]# useradd -m rsync

[root@client ~]# passwd rsync

伺服器

[root@server ~]# su - rsync

[rsync@server ~]$ ssh-keygen -t rsa (所有選項回車,使用默認設置)

[rsync@server ~]$ ssh-copy-id -i .ssh/id_rsa.pub rsync@172.16.10.253

分別重啟sshd服務

[root@server ~]# /etc/init.d/sshd restart

[root@client ~]# /etc/init.d/sshd restart


3.添加同步腳本

[root@Server ~]# vim inotify_rsync.sh

#!/bin/sh

SRC=/home/rsync/test/

DST=rsync@172.16.10.253:/home/rsync/test

INWT=/usr/local/bin/inotifywait

RSYNC=/usr/local/bin/rsync

$INWT -mrq -e create,move,delete,modify $SRC | while read D E F;do

rsync -aHqzt --delete $SRC $DST

done

[root@Server ~]# chmod x inotify_rsync.sh

[root@Server ~]# cp inotify_rsync.sh /home/rsync/

[root@Server ~]# su - rsync

[rsync@server ~]$ ./inotify_rsync.sh &

[rsync@server ~]$ mkdir test

測試

[rsync@server ~]$ cd test

[rsync@server text]$ touch a.txt

驗證

[rsync@client ~]$ cd test

[rsync@client test]$ ls

a.txt

(這個腳本里在

rsync用戶裡面執行的,可以在root下試下,設為開機啟動的話:

echo "/root/inotify_rsync.sh &" >> /etc/rc.local )


本文出自 「對月當歌」 博客,請務必保留此出處http://zhang101527.blog.51cto.com/3639673/846852


[火星人 ] rsync inotify-tools ssh實現觸髮式遠程實時同步已經有408次圍觀

http://coctec.com/docs/linux/show-post-45800.html