linux設定rsync+inotify即時同步檔案

來源:互聯網
上載者:User


linux設定rsync+inotify即時同步檔案 應用情境:同步接收方:test01接收目錄:/opt/software/test/a/同步發起方:test02同步目錄:/opt/software/test/a/ 在test02的 /opt/software/test/a/ 目錄下做新增、建立、刪除、移動操作都會同步到test01的/opt/software/test/a/目錄   www.2cto.com  第一步:安裝rsync(test01和test02都要安裝)yum install rsync 第二步:安裝inotify(同步發起方test02安裝)解壓inotify [root@test02 software]# tar zxvf inotify-tools-3.14[root@test02 inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify[root@test02 inotify-tools-3.14]# make[root@test02 inotify-tools-3.14]# make install 第三步:配置rsync(同步接收方test01)在/etc 目錄下建立rsyncd.conf,內容如下pid file=/var/run/rsyncd.pidport=873#test01所在ip地址address=192.168.1.114uid=rootgid=rootuse chroot=yes#test02 所在ip地址hosts allow=192.168.1.107hosts deny=*max connections=5motd file=/etc/rsyncd.motdlog file=/var/log/rsync.log#transfer logging=yeslog format=%t %a %m %f %bsyslog facility=local3timeout=300read only=nowrite only=no[ggly]path=/opt/software/test/a/auth users=owenzhanglist=yesigonre errorssecrets file=/etc/rsyncd.secretscomment=ggly rsyc files   www.2cto.com  在/etc 目錄下建立 rsyncd.secrets並賦予600許可權內容如下#使用者:密碼,密碼不一定要和linux使用者的密碼一致,使用者必須是linux使用者owenzhang:123123 在/etc目錄下建立 rsyncd.motd,內容隨便寫,rsync的歡迎資訊 運行test01的rsyncservice xinetd start沒有安裝xinetd 可以使用 yum install xinetd 來安裝 第四步:配置inotify(同步發起方test02)建立檔案 gglyrsync.sh 並賦予執行許可權,檔案名稱、位置隨便,內容如下   www.2cto.com  #!/bin/bash#同步接收方ipclient=192.168.1.114src=/opt/software/test/a/#同步接收方配置的rsync模組名dest=ggly#同步接收方鑒權時的使用者user=owenzhang/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,move,attrib $src | while read filesdo/usr/bin/rsync -vzrtopgq --delete --progress --password-file=/opt/software/rsyncpasswd $src $user@$client::$destdone 在/opt/software/目錄下建立rsyncpasswd檔案,內容為test01中rsyncd.secrets中owenzhang對應密碼即123123並賦予600許可權 最後運行 gglyrsync.sh 就可以了。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.