歡迎您光臨本站 註冊首頁

使用rsync+inotify配置觸髮式(實時)遠程同步

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  
CentOS 5.3的rsync升級3。X

安裝步驟

  1. wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm   
  2. rpm -ivh rpmforge-release-0.3.6-1.el5.rf.i386.rpm  
  3. yum update rsync  

兩台伺服器 系統均為centos5.3IP為:

192.168.4.167-server1

192.168.4.168-server2

192.168.4.167/disk目錄實時同步到192.168.4.168/disk目錄下

查看是否支持inotify,從kernel 2.6.13開始正式併入內核,RHEL5已經支持。

看看是否有 /proc/sys/fs/inotify/目錄,以確定內核是否支持inotify

[root@RHEL5 Rsync]# ll /proc/sys/fs/inotify

total 0

-rw-r--r-- 1 root root 0 Oct  9 09:36 max_queued_events

-rw-r--r-- 1 root root 0 Oct  9 09:36 max_user_instances

-rw-r--r-- 1 root root 0 Oct  9 09:36 max_user_watches

 

二.具體操作

1  生成SSH KEY server1 SSH server2不需要密碼

(1   Server1ssh-keygen -t rsa

這個命令生成一個密鑰對:id_rsa(私鑰文件)和id_rsa.pub(公鑰文件)。默認被保存在~/.ssh/目錄下。

(2  公鑰添加到遠程主機的 authorized_keys 文件中
將文件上傳到遠程主機中
server1#scp ~/.ssh/id_rsa.pub root@192.168.4.168:/root/
SSH
到登陸到遠程主機,將公鑰追加到 authorized_keys 文件中
server2#cat /root/id_rsa.pub >> /root/.ssh/authorized_keys

(3)server2#service sshd restart

 

2.server1上安裝rsync

Server1# tar –zxvf rsync-3.0.2.tar.gz

Server1# cd rsync-3.0.2

Server1# ./configure

Server1#make

Server1# make install

 

3.安裝inotify

Server1# tar –zxvf inotify-tools-3.13.tar.gz

Server1# cd inotify-tools-3.13

Server1# ./configure

Server1# make

Server1# make install

完成後,注意查看manpageman inotify man inotifywait

·  inotifywait 僅執行阻塞,等待 inotify 事件。您可以監控任何一組文件和目錄,或監控整個目錄樹(目錄、子目錄、子目錄的子目錄等等)。在 shell 腳本中使用 inotifywait

·  inotifywatch 收集關於被監視的文件系統的統計數據,包括每個 inotify 事件發生多少次。

 

4.寫個inotif_rsync.sh腳本

  1. /bin/sh  
  2. src=/disk  
  3. des=/  
  4. ip=192.168.4.168  
  5. /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w%f' /  
  6.  -e modify,delete,create,attrib /  
  7. ${src} /  
  8. while read  file  
  9.         do  
  10.                 rsync -avz --delete --progress ${src} root@${ip}:${des} &&  
  11.                 echo "${file} was rsynced"  
  12.                 echo "---------------------------------------------------------------------------"  
  13.         done  

將其賦予可執行許可權:chmod 755 inotif_rsync.sh

執行此腳本:./ inotif_rsync.sh &


好文,頂一下
(2)
100%
文章真差,踩一下
(0)
0%
------分隔線----------------------------
  • 上一篇:LVS + Keepalived 實現負載均衡
  • 下一篇:Hadoop 0.21.0 集群配置小記
  • 我要評論!
  • 收藏
  • 挑錯
  • 推薦
  • 列印

[火星人 ] 使用rsync+inotify配置觸髮式(實時)遠程同步已經有368次圍觀

http://coctec.com/docs/net/show-post-68196.html