CentOS 6.5 rsync服務的安裝與配置

來源:互聯網
上載者:User

標籤:linux   rsync   伺服器   

一、rsync 簡介

  Rsync(remote synchronize)是一個遠端資料同步工具,可通過LAN/WAN快速同步多台主機間的檔案,也可以使用 Rsync 同步本地硬碟中的不同目錄。 

  Rsync 是用於取代rcp的一個工具,Rsync使用所謂的 “Rsync 演算法” 來使本地和遠程兩個主機之間的檔案達到同步,這個演算法只傳送兩個檔案的不同部分,而不是每次都整份傳送,因此速度相當快。您可以參考 How Rsync Works A Practical Overview 進一步瞭解 rsync 的運作機制。

  Rsync支援大多數的類Unix系統,無論是Linux、Solaris還是BSD上都經過了良好的測試。此外,它在windows平台下也有相應的版本,比較知名的有cwRsync和Sync2NAS。

  Rsync 的初始作者是 Andrew Tridgell 和 Paul Mackerras,它當前由 http://rsync.samba.org維護。

  Rsync的基本特點如下:

  1. 可以鏡像儲存整個分類樹和檔案系統;

  2. 可以很容易做到保持原來檔案的許可權、時間、軟永久連結等;

  3. 無須特殊許可權即可安裝;

  4. 最佳化的流程,檔案傳輸效率高;

  5. 可以使用rcp、ssh等方式來傳輸檔案,當然也可以通過直接的socket串連;

  6. 支援匿名傳輸,以方便進行網站鏡像。

  在使用 rsync 進行遠程同步時,可以使用兩種方式:遠程 Shell 方式(建議使用 ssh,使用者驗證由 ssh 負責)和 C/S 方式(即客戶串連遠程 rsync 伺服器,使用者驗證由 rsync 伺服器負責)。

  無論本地同步目錄還是遠程同步資料,首次運行時將會把全部檔案拷貝一次,以後再運行時將只拷貝有變化的檔案(對於新檔案)或檔案的變化部分(對於原有檔案)。

  rsync 在首次複製時沒有速度優勢,速度不如 tar,因此當資料量很大時您可以考慮先使用 tar 進行首次複製,然後再使用 rsync 進行資料同步。


rsync生產常用參數


參數 說明 預設值
exclude 指定多個由空格隔開的多個檔案或目錄(相對路徑),並將其添加到 exclude 列表中。這等同於在用戶端命令中使用 –exclude 來指定模式。
exclude from 指定一個包含 exclude 規則定義的檔案名稱,伺服器從該檔案中讀取 exclude 列表定義。
include 指定多個由空格隔開的多個檔案或目錄(相對路徑),並將其添加到 include 列表中。這等同於在用戶端命令中使用 –include 來指定模式 。
include from 指定一個包含 include 規則定義的檔案名稱,伺服器從該檔案中讀取 include 列表定義。


以守護進程(socket)的方式傳輸資料(這個是rsync自身的重要功能)

二、rsync伺服器應用案例


A、rsync伺服器部署

1.安裝兩種方式

(1)、yum install -y rsync             ###線上安裝rsync        (2)、wget http://pkgs.repoforge.org/rsync/rsync-3.0.9-2.el6.rfx.x86_64.rpm   rpm -ivh rsync-3.0.9-2.el6.rfx.x86_64.rpm    ###下載rsync軟體包之後rpm安裝



2.查看是否安裝成功

[[email protected] data]# rpm -qa rsync              ###查看是否安裝成功      rsync-3.0.6-12.el6.x86_64


3.建立rsync主配置rsyncd.conf檔案

[[email protected] data]# vi /etc/rsyncd.conf #rsync_config___________start#created by donglq 16:01 2016-12-09##rsyncd.conf start##uid = nobodygid = nobodyuse chroot = no    max connections = 200timeout = 300pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log[donglq]path = /donglq/ignore errorsread only = falselist = falsehosts allow = 192.168.0.0/24hosts deny = 0.0.0.0/32auth users = rsync_backupsecrets file = /etc/rsync.password[data]path = /data/gnore errorsread only = falselist = falsehosts allow = 192.168.0.0/24hosts deny = 0.0.0.0/32auth users = rsync_backupsecrets file = /etc/rsync_data.password##rsyncd.conf___________end

4.建立rsync虛擬使用者密碼檔案

echo "rsync_backup:123456" >/etc/rsync.password   chmod 600 /etc/rsync.password           echo "rsync_backup:123456" >/etc/rsync_data.passwordchmod 600 /etc/rsync_data.password

5.建立共用資料夾並將其使用者屬組修改為nobody

[[email protected] data]mkdir /donglq[[email protected] data]mkdir /data[[email protected] data]chmod 600 /donglq /data[[email protected] data]chown nobody.nobody /data /donglq

6.rsync --daemon                        ###daemon模式啟動rsync       

[[email protected] data]# netstat -lntup|grep 873      ###查看rsync是否啟動tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      1380/rsync          tcp        0      0 :::873                      :::*                        LISTEN      1380/rsync


B、rsync用戶端部署

1. 安裝  

yum install -y rsync                ###線上安裝rsync


2. 查看是否安裝成功

netstat -lntup|grep 873


3. 建立密碼檔案

echo "123456" >/etc/rsync.password4chmod 600 /etc/rsync.password echo "123456" >/etc/rsync_data.passwordchmod 600 /etc/rsync_data.password


C、rsync調試

[[email protected] ~]# rsync -avz [email protected]::donglq /data/ --password-file=/etc/rsync.password receiving incremental file list./11023456789.ICE-unix/sent 261 bytes  received 570 bytes  1662.00 bytes/sectotal size is 0  speedup is 0.00[[email protected] data]#  rsync -avz [email protected]::data /data/ --password-file=/etc/rsync_data.password receiving incremental file list./1.txt/1/sent 73 bytes  received 156 bytes  458.00 bytes/sectotal size is 0  speedup is 0.00


配置完畢


注意事項:

在整個安裝過程中,能拷貝的參數盡量不要用手輸,防止出錯。密碼檔案及模組檔案夾許可權要設定好。

謹慎細心一點是不會有問題的。


參考:

http://blog.csdn.net/wjciayf/article/details/51812369

CentOS 6.5 rsync服務的安裝與配置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.