歡迎您光臨本站 註冊首頁

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

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

1安裝

[[email protected] ~]# wget ftp://ftp.samba.org/pub/rsync/rsync-3.0.8.tar.gz

[[email protected] ~]# tar xzvf rsync-3.0.8.tar.gz

[[email protected] ~]# cd rsync-3.0.8

[[email protected] ~]# ./configure

[[email protected] ~]# make

[[email protected] ~]# make install

[[email protected]~]#

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

[[email protected] ~]# tar xzvf inotify-tools-3.14.tar.gz

[[email protected] ~]# cd inotify-tools-3.14

[[email protected] ~]# ./configure

[[email protected] ~]# make

[[email protected] ~]# make install

2.配置

ssh key信任

伺服器

[[email protected] ~]# useradd -m rsync

[[email protected] ~]# passwd rsync

客戶機

[[email protected] ~]# useradd -m rsync

[[email protected] ~]# passwd rsync

伺服器

[[email protected] ~]# su - rsync

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

[[email protected] ~]$ ssh-copy-id -i .ssh/id_rsa.pub [email protected]

分別重啟sshd服務

[[email protected] ~]# /etc/init.d/sshd restart

[[email protected] ~]# /etc/init.d/sshd restart


3.添加同步腳本

[[email protected] ~]# vim inotify_rsync.sh

#!/bin/sh

SRC=/home/rsync/test/

[email protected]:/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

[[email protected] ~]# chmod x inotify_rsync.sh

[[email protected] ~]# cp inotify_rsync.sh /home/rsync/

[[email protected] ~]# su - rsync

[[email protected] ~]$ ./inotify_rsync.sh &

[[email protected] ~]$ mkdir test

測試

[[email protected] ~]$ cd test

[[email protected] text]$ touch a.txt

驗證

[[email protected] ~]$ cd test

[[email protected] 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實現觸髮式遠程實時同步已經有271次圍觀

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