rsync 服務搭建
rsync 服務搭建
服務端部署操作內容:
- 創建rsync用戶和用戶組
eg:
useradd -s /sbin/nologin -M rsync
- 創建需要備份的指定目錄,并修改權限
eg:
mkdir -p /backup/
chown -R rsync:rsync /backup
- 創建rsync密碼文件,錄入密碼并修改權限為600
eg:
echo "rsync_backup:passwd@123" >/etc/rsync.password ###注意:服務端的密碼文件中包含認證用戶和密碼
chmod 600 /etc/rsync.password
- 修改配置文件/etc/rsyncd.conf
eg:
cat /etc/rsyncd.conf
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.217.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup ###認證用戶
secrets file = /etc/rsync.password ###密碼文件路徑
[backup]
path = /backup
###可加其它模塊###
服務端啟動服務并加入開機啟動項
啟動服務:
rsync --daemon
rsync --daemon --config=/etc/rsyncd.conf
檢查服務啟動情況:
# netstat -anltup |grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 68849/rsync
tcp6 0 0 :::873 :::* LISTEN 68849/rsync
加入開機啟動項:
echo "/usr/bin/rsync --daemon" >> /etc/rc.local
客戶端部署操作內容:
創建rsync密碼文件,錄入密碼并修改權限為600
eg:
echo "passwd@123" >/etc/rsync.paasword ###客戶端密碼文件只包含密碼
chmod 600 /etc/rsync.paasword
完成部署后,創建文件測試:
服務端備份路徑下文件檢查:
cd /backup/ && ll
total 0
客戶端創建測試文件:
echo "rsync file test 123" > rsync-test.txt
執行備份:
# rsync -avz -P rsync-test.txt rsync_backup@192.168.217.114::backup --password-file=/etc/rsync.password
sending incremental file list
rsync-test.txt
20 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/1)
rsync: chgrp ".rsync-test.txt.8p4xO9" (in backup) failed: Operation not permitted (1)
sent 121 bytes received 133 bytes 508.00 bytes/sec
total size is 20 speedup is 0.08
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]
服務端檢查備份情況:
# ll
total 4
-rw------- 1 rsync rsync 20 Aug 18 15:20 rsync-test.txt
# cat rsync-test.txt
rsync file test 123

浙公網安備 33010602011771號