天天看點

Linux 下架設 rsync 伺服器

  rsync 是一個unix系統下的檔案同步和傳輸工具。rsync是用 “rsync 算法”提供了一個客戶機和遠端檔案伺服器的檔案同步的快速方法。

rsync 包括如下的一些特性:

* can update whole directory trees and filesystems

能更新整個目錄和樹和檔案系統;

* optionally preserves symbolic links, hard links, file ownership, permissions, devices and times

有選擇性的保持符号鍊鍊、硬連結、檔案屬于、權限、裝置以及時間等;

* requires no special privileges to install

對于安裝來說,無任何特殊權限要求;

* internal pipelining reduces latency for multiple files

對于多個檔案來說,内部流水線減少檔案等待的延時;

* can use rsh, ssh or direct sockets as the transport

能用rsh、ssh 或直接端口做為傳輸入端口;

* supports anonymous rsync which is ideal for mirroring

支援匿名rsync 同步檔案,是理想的鏡像工具;

安裝配置過程:

一、建相應的檔案及檔案夾

二、修改 rsyncd.conf 和rsyncd.secrets 和rsyncd.motd

rsyncd.conf 是rsync伺服器主要配置檔案,我們來個簡單的示例;

比如我們要備份伺服器上的 /nsn_talko_production/talko/var/www/html/talko/talko.next/repository/

rsyncd.secrets的内容如下類似

root:123456 yofee:123456

rsyncd.motd 檔案

  它是定義rysnc 伺服器資訊的,也就是使用者登入資訊。比如讓使用者知道這個伺服器是誰提供的等。

三、啟動rsync伺服器

[root@estals60:~]#/usr/bin/rsync --daemon  --config=/etc/rsyncd/rsyncd.conf

四、防火牆的設定

[root@estals60:~]#iptables -a input -p tcp -m state --state new  -m tcp --dport 873 -j accept [root@estals60:~]#iptables -l  檢視一下防火牆是不是打開了 873端口;

五、執行同步指令

rsync -avzp root@estals60::p_repositor /nsn_talko/talko/var/www/html/talko/talko.next/

這時會要求輸入root的密碼,然後就沒啥問題了。

另外其實也可以考慮把他建在系統任務裡面定時運作。道理都是一樣的,用crontab,這裡就不再重述了。

<b> 原文釋出時間為:2013-03-20</b>

<b>本文來自雲栖社群合作夥伴“linux中國”</b>

繼續閱讀