# Debian/Ubuntu
apt-get install rsync
# RHEL/CentOS/Fedora
yum install rsync
# 或 rpm -ivh rsync.rpm
# 源碼編譯
tar xf rsync-xxx.tar.gz && cd rsync-xxx
./configure --prefix=/usr && make && make install
# 全局參數
pid file = /var/run/rsyncd.pid
port = 873
address = 192.168.1.171
uid = root
gid = root
use chroot = yes
read only = yes
hosts allow = 192.168.1.0/24 10.0.1.0/24
hosts deny = *
max connections = 5
motd file = /etc/rsyncd.motd
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
# 模組: 備份 /home (排除 easylife/, samba/)
[rhel4home]
path = /home
list = yes
ignore errors
auth users = root
secrets file = /etc/rsyncd.secrets
comment = RHEL 4 Home Data
exclude = easylife/ samba/
# 模組: 備份 /opt
[rhel4opt]
path = /opt
list = no
ignore errors
auth users = easylife
secrets file = /etc/rsyncd.secrets
comment = RHEL 4 Opt Data
| 參數 | 說明 |
|---|---|
| use chroot | 傳輸前 chroot 到 path,增強安全,但需 root 權限且忽略符號鏈接實體 |
| read only | yes=只允許下載;no=允許上傳 |
| auth users | 認證用戶 (需系統真實存在),多用戶逗號分隔 |
| secrets file | 密碼文件路徑,格式 user:pass,權限必須 600 |
| exclude | 排除模式,相對於 path |
# /etc/rsyncd.secrets (權限 600)
root:mike
easylife:keer
# /etc/rsyncd.motd
++++++++++++++++++++++++++++++++++++
Welcome to use rsync services!
2024-2025
++++++++++++++++++++++++++++++++++++
# 從服務器拉取 (備份)
rsync -avzP --delete root@192.168.1.171::rhel4home /local/backup/home/
# 推送到服務器 (需服務端 read only = no)
rsync -avzP /local/data/ easylife@192.168.1.171::rhel4opt
# 通過 SSH 隧道 (更安全)
rsync -avzP -e ssh /src/ user@host:/dest/
-a:歸檔模式 (遞歸、保留屬性、時間、鏈接等)-v:詳細輸出-z:傳輸壓縮-P:顯示進度 + 斷點續傳--delete:刪除目標端源端不存在的文件 (鏡像同步)--exclude=PATTERN:排除模式--bwlimit=KBPS:限制頻寬使用 cwRsync (含 OpenSSH) 或 DeltaCopy (圖形界面)。
Rsync 以增量傳輸、豐富過濾、多協議支援成為 Linux 系統備份、同步、鏡像的標準工具。合理配置模組認證、chroot、排除規則,可構建安全高效的異地災備體系。