萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Windows 下 rsync 完整部署指南:從安裝到自動同步

rsync(remote sync)是類 Unix 系統的資料鏡像備份神器,Windows 移植版 cwRsync 同樣強大。特性:保留權限、時間、軟硬連結;傳輸效率高;支援 SSH、Socket、匿名傳輸。本文詳解 Windows 2003 環境下 Server/Client 端安裝、配置、測試與常見問題。

1. 環境與軟體

  • OS:Windows Server 2003
  • 軟體:cwRsync_2.0.10_Installer(Client)、cwRsync_Server_2.0.10_Installer(Server)
  • 硬體:Dell 2950, CPU 1.6G×4, 4G RAM, 1G×6 RAID5

2. 安裝

Server 端運行 cwRsync_Server_2.0.10_Installer,Client 端運行 cwRsync_2.0.10_Installer,步驟一致,一路下一步。

3. Server 端配置 rsyncd.conf

pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
uid = administrator
gid = administrator
use chroot = no
max connections = 4
syslog facility = local5

[test]
path = /cygdrive/d/wlk
comment = BACKUP CLIENT IS SOLARIS 8 E250
ignore errors
read only = yes
list = no
auth users = inburst
secrets file = etc/inburst.pas
  • 建立密碼檔 etc/inburst.pas:inburst:hack
  • 服務中啟動 RsyncServer 並設為自動。

4. Client 端測試

rsync -av 10.0.0.16::401 /cygdrive/h/401

參數解析:-v 詳細、-z 壓縮、-r 遞歸、-topg 保留屬性、--progress 顯示進度、--delete 刪除異步檔案。可加 -e ssh 加密傳輸,--password-file 實現腳本無交互驗證(注意權限 600)。

5. 常見問題 FAQ

  • SSH 免密同步:Server A 生成 key → 複製 identity.pub 到 Server B ~/.ssh/authorized_keys。
  • 防火牆策略:Server 在內網 → 限制 Client IP、僅開 SSH 22;Client 在內網 → 放行外發 22。
  • 備份變更/刪除檔案:--backup-dir=./backup-$(date +%F)。
  • 端口修改:--port 8730 或 -e 'ssh -p 2002'。
  • 僅同步目錄結構:rsync -av --include '*/' --exclude '*' src/ dest/。
  • Read-only file system:檢查 read only = no。
  • invalid gid:系統無 nobody 組,改 gid = nogroup。
  • 綁定 873 失敗:非 root 權限不可用 1024 以下端口,用 --port 改端口。
  • 認證失敗:命令加用戶名 rsync -a user@host::module dest。

6. Windows 雙機同步實戰(Server 192.168.0.201 / Client 192.168.0.202)

Server 端

  1. 安裝 cwRsync_Server,啟動 opensshd 服務。
  2. 編輯 C:/Program Files/cwRsyncServer/rsyncd.conf:
    use chroot = false
    strict modes = false
    hosts allow = *
    log file = rsyncd.log
    pid file = rsyncd.pid
    [rsync]
    path = /cygdrive/f/rsync
    read only = yes
    transfer logging = yes
    secrets file = /cygdrive/f/rsyncd.secrets
    
  3. 啟動 RsyncServer 服務。

Client 端

  1. 安裝 cwRsync_Client。
  2. CMD 測試連通性:telnet 192.168.0.201 22、telnet 192.168.0.201 873。
  3. 執行同步:rsync -vzrtopg --progress --delete 192.168.0.201::rsync /cygdrive/d/test(輸入 administrator 密碼)。
  4. 加入任務計劃實現定時同步。

至此,Windows 雙機 rsync 同步環境搭建完成。

copyright © 萬盛學電腦網 all rights reserved