-
rsync備份服務(wù)傳輸數(shù)據(jù)原理
-
rsync備份服務(wù)命令參數(shù)說(shuō)明
-
rsync備份服務(wù)企業(yè)應(yīng)用方式
-
rsync備份服務(wù)常見(jiàn)異常問(wèn)題
1.rsync守護(hù)進(jìn)程模式備份數(shù)據(jù)原理(用戶身份轉(zhuǎn)換過(guò)程)
第一步:
客戶端——>服務(wù)端 發(fā)送請(qǐng)求傳輸數(shù)據(jù)信息(執(zhí)行命令、有認(rèn)證用戶信息、傳輸數(shù)據(jù))
第二步:
服務(wù)端——>客戶端 接收到傳輸數(shù)據(jù)信息(審核認(rèn)證用戶:發(fā)送回復(fù)信息嘀掸,需要認(rèn)證密碼)
第三步:
客戶端——>服務(wù)端(發(fā)送請(qǐng)求傳輸數(shù)據(jù)信息塑荒,發(fā)送認(rèn)證密碼信息)
第四步:
服務(wù)端——>客戶端(發(fā)送確認(rèn)信息)
第五步:
客戶端——>服務(wù)端(用戶攜帶數(shù)據(jù)通過(guò)網(wǎng)絡(luò)進(jìn)行傳輸铁材,需要對(duì)用戶身份進(jìn)行轉(zhuǎn)換-->rsync(配置文件指定))
第六步:
服務(wù)端——>客戶端(發(fā)送數(shù)據(jù)存儲(chǔ)完畢確認(rèn)信息碗暗,將數(shù)據(jù)保存到備份目錄中探熔,備份目錄權(quán)限屬主為rsync)
修改備份數(shù)據(jù)屬主和屬組信息 rsync用戶身份修改文件權(quán)限
錯(cuò)誤說(shuō)明:
chgrp ".hosts.Zb1kyS" (in backup) failed: Operation not permitted (1)
chgrp change group ownership(修改數(shù)據(jù)屬組信息)
[oldboy@backup ~]$ chgrp oldgirl oldboy
chgrp: changing group of 'oldboy': Operation not permitted
[oldboy@backup ~]$ chgrp oldgirl /etc/hosts
chgrp: changing group of '/etc/hosts': Operation not permitted
解釋說(shuō)明:
普通用戶無(wú)法修改文件的屬組信息
ps:可以修改文件配置參數(shù)中
fake super = yes ----讓指定虛擬用戶偽裝成管理員用戶亩鬼,可以強(qiáng)行修改文件屬主屬組權(quán)限信息
2.rsync命令參數(shù)說(shuō)明
-a(archive) archive mode; equals -rlptgoD (no -H,-A,-X)
歸檔模式參數(shù)殖告,等價(jià)于 -rlptgoD
-r(recursive) recurse into directorie
遞歸傳輸目錄
-l(links) copy symlinks as symlinks
備份傳輸軟鏈接文件保持屬性不變
-L(copy-links) transform symlink into referent file/dir
備份傳輸軟連接文件時(shí),會(huì)將源文件內(nèi)容信息進(jìn)行傳輸備份
-p(perms) preserve permissions
保持權(quán)限信息不變 644 755
-t(times) preserve modification times
保持文件修改時(shí)間不變
-g(group) preserve group
保持文件屬組信息不變
-o(-owner) preserve owner (super-user only)
保持文件屬主信息不變
-D same as --devices --specials
保持設(shè)備文件屬性信息不變 c b s
-v(verbose) increase verbosity
傳輸備份數(shù)據(jù)詳細(xì)過(guò)程信息
-P same as --partial --progress
傳輸進(jìn)度信息
--exclude=PATTERN exclude files matching PATTERN
根據(jù)指定數(shù)據(jù)信息進(jìn)行排除
--exclude-from=FILE read exclude patterns from FILE
根據(jù)指定文件進(jìn)行批量排除數(shù)據(jù)信息
--delete delete extraneous files from destination dirs
進(jìn)行無(wú)差異同步傳輸數(shù)據(jù)
同步目錄數(shù)據(jù)信息時(shí), 保證目錄中數(shù)據(jù)信息一模一樣
-z, --compress compress file data during the transfer
在傳輸數(shù)據(jù)時(shí),對(duì)文件進(jìn)行壓縮傳輸
--bwlimit=RATE limit socket I/O bandwidth
限制傳輸速率
--password-file 實(shí)現(xiàn)免交互傳輸數(shù)據(jù)信息
3.rsync守護(hù)進(jìn)程備份服務(wù)企業(yè)應(yīng)用
守護(hù)進(jìn)程模式:
??推: 客戶端 -- 數(shù)據(jù)備份 -- 備份服務(wù)器
??拉: 客戶端 -- 數(shù)據(jù)恢復(fù) -- 備份服務(wù)器
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
SRC: 備份服務(wù)器上模塊信息
DEST: 本地保存數(shù)據(jù)路徑信息
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
企業(yè)多模塊應(yīng)用過(guò)程:
1.守護(hù)進(jìn)程模式多模塊創(chuàng)建
第一個(gè)里程:配置文件中創(chuàng)建多個(gè)模塊信息
[sa_backup]
comment = "backup dir by oldboy"
path = /backup/sa_dir/
[dev_backup]
comment = "backup dir by oldboy"
path = /backup/dev_dir/
[dba_backup]
comment = "backup dir by oldboy"
path = /backup/dba_dir/
第二個(gè)里程: 確認(rèn)指定模塊路徑是否存在/權(quán)限是否正確
第三個(gè)里程: 重啟rsync服務(wù)
2.守護(hù)進(jìn)程模式數(shù)據(jù)排除功能
創(chuàng)建測(cè)試環(huán)境:客戶端創(chuàng)建
[root@nfs01 oldboy]# mkdir /oldboy/oldboy{01..03}
[root@nfs01 oldboy]# touch /oldboy/oldboy{01..03}/{a..c}.txt
[root@nfs01 oldboy]# tree /oldboy
/oldboy
├── oldboy01
│?? ├── a.txt
│?? ├── b.txt
│?? └── c.txt
├── oldboy02
│?? ├── a.txt
│?? ├── b.txt
│?? └── c.txt
└── oldboy03
├── a.txt
├── b.txt
└── c.txt
3 directories, 9 files
需求1:備份/oldboy目錄數(shù)據(jù)時(shí),將oldboy01目錄進(jìn)行排除,將oldboy03目錄中的b.txt文件進(jìn)行排除
方法一:利用rsync命令參數(shù)實(shí)現(xiàn)(--exclude)
[root@nfs01 ~]# rsync -avz /oldboy/ --exclude=oldboy01/ --exclude=oldboy03/b.txt rsync_backup@172.16.1.41::sa_backup --password-file=/etc/rsync.password
sending incremental file list
./
oldboy02/
oldboy02/a.txt
oldboy02/b.txt
oldboy02/c.txt
oldboy03/
oldboy03/a.txt
oldboy03/c.txt
sent 420 bytes received 134 bytes 1,108.00 bytes/sec
total size is 12,288 speedup is 22.18
ps: 利用--exclude排除數(shù)據(jù)信息,需要利用相對(duì)路徑指定需要排除的數(shù)據(jù),相對(duì)路徑是相對(duì)于同步目錄而言
需求02: 備份/oldboy目錄數(shù)據(jù)時(shí),將oldboy01目錄進(jìn)行排除a.txt oldboy02/b.txt oldboy03/c.txt
方法一: 利用rsync命令參數(shù)實(shí)現(xiàn):
--exclude-from
第一個(gè)里程: 編寫(xiě)排除數(shù)據(jù)信息文件
[root@nfs01 oldboy]# cat execlude.txt
oldboy01/a.txt
oldboy02/b.txt
oldboy03/c.txt
第二個(gè)里程: 利用命令參數(shù)進(jìn)行排除多個(gè)數(shù)據(jù)
[root@nfs01 oldboy]# rsync -avz /oldboy/ --exclude-from=/oldboy/execlude.txt rsync_backup@172.16.1.41::sa_backup --password-file=/etc/rsync.password
sending incremental file list
./
execlude.txt
oldboy01/
oldboy01/b.txt
oldboy01/c.txt
oldboy02/
oldboy02/a.txt
oldboy02/c.txt
oldboy03/
oldboy03/a.txt
oldboy03/b.txt
sent 601 bytes received 180 bytes 1,562.00 bytes/sec
total size is 12,333 speedup is 15.79
方法三: 利用服務(wù)端配置文件參數(shù)
exclude --- 指定數(shù)據(jù)進(jìn)行排除同步 == 客戶端命令參數(shù) --exclude
exclude from --- 指定多個(gè)數(shù)據(jù)排除文件信息,排除多個(gè)數(shù)據(jù) == 客戶端命令參數(shù) --exclude-from
[sa_backup]
comment = "backup dir by oldboy"
path = /backup/sa_dir/
exclude = oldboy01/ oldboy03/b.txt
[sa_backup]
comment = "backup dir by oldboy"
path = /backup/sa_dir/
exclude from = /backup/sa_dir/execlude.txt
ps: rsyncd.conf配置文件說(shuō)明
全局配置: 在模塊上面配置的信息,為全局配置,會(huì)影響所有模塊
局部配置: 在模塊里面配置的信息,為局部配置,只會(huì)影響指定模塊
3.守護(hù)進(jìn)程模式數(shù)據(jù)無(wú)差異同步
--delete
企業(yè)應(yīng)用:保證數(shù)據(jù)同步一致
存儲(chǔ)服務(wù)器數(shù)據(jù) == 備份服務(wù)器數(shù)據(jù)
ps: --delete參數(shù)一定要慎用,容易造成誤刪除數(shù)據(jù)
4.守護(hù)進(jìn)程模式創(chuàng)建子目錄功能
[root@nfs01 oldboy]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::sa_backup/oldboy/ --password-file=/etc/rsync.password
sending incremental file list
created directory oldboy
hosts
sent 219 bytes received 72 bytes 582.00 bytes/sec
total size is 335 speedup is 1.15
5.守護(hù)進(jìn)程模式訪問(wèn)策略功能
黑名單與白名單配置
6.守護(hù)進(jìn)程模式列表功能說(shuō)明
list = false --- 可以實(shí)現(xiàn)客戶端列表顯示備份服務(wù)端所有模塊信息
[root@nfs01 oldboy]# rsync rsync_backup@172.16.1.41::
sa_backup "sa backup dir"
dev_backup "dev backup dir"
dba_backup "dba backup dir"
4.rsync備份服務(wù)常見(jiàn)異常問(wèn)題
1. rsync服務(wù)端開(kāi)啟的iptables防火墻
【客戶端的錯(cuò)誤】
No route to host
【錯(cuò)誤演示過(guò)程】
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
rsync: failed to connect to 172.16.1.41: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
【異常問(wèn)題解決】
關(guān)閉rsync服務(wù)端的防火墻服務(wù)(iptables)
[root@backup mnt]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@backup mnt]# /etc/init.d/iptables status
iptables: Firewall is not running.
2. rsync客戶端執(zhí)行rsync命令錯(cuò)誤
【客戶端的錯(cuò)誤】
The remote path must start with a module name not a /
【錯(cuò)誤演示過(guò)程】
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::/backup
ERROR: The remote path must start with a module name not a /
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
【異常問(wèn)題解決】
rsync命令語(yǔ)法理解錯(cuò)誤雳锋,::/backup是錯(cuò)誤的語(yǔ)法黄绩,應(yīng)該為::backup(rsync模塊)
3. rsync服務(wù)認(rèn)證用戶失敗
【客戶端的錯(cuò)誤】
auth failed on module oldboy
【錯(cuò)誤演示過(guò)程】
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
Password:
@ERROR: auth failed on module backup
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
【異常問(wèn)題解決】
1. 密碼真的輸入錯(cuò)誤,用戶名真的錯(cuò)誤
2. secrets file = /etc/rsync.password指定的密碼文件和實(shí)際密碼文件名稱不一致 信息復(fù)制粘貼
3. /etc/rsync.password文件權(quán)限不是600 服務(wù)端
4. rsync_backup:123456 密碼配置文件后面注意不要有空格
如何看出文件結(jié)尾空格信息:
方法一:在vim編輯中查看
底行模式---:set list
方法二:在cat命令中查看
[root@backup ~]# cat -A /etc/rsync.password
rsync_backup:oldboy123 $
5. rsync客戶端密碼文件中只輸入密碼信息即可玷过,不要輸入虛擬認(rèn)證用戶名稱
4. rsync服務(wù)位置模塊錯(cuò)誤
【客戶端的錯(cuò)誤】
Unknown module 'backup'
【錯(cuò)誤演示過(guò)程】
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
@ERROR: Unknown module 'backup'
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
【異常問(wèn)題解決】
1. /etc/rsyncd.conf配置文件模塊名稱書(shū)寫(xiě)錯(cuò)誤
5. rsync服務(wù)權(quán)限阻止問(wèn)題
【客戶端的錯(cuò)誤】
Permission denied
【錯(cuò)誤演示過(guò)程】
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
Password:
sending incremental file list
hosts
rsync: mkstemp ".hosts.5z3AOA" (in backup) failed: Permission denied (13)
sent 196 bytes received 27 bytes 63.71 bytes/sec
total size is 349 speedup is 1.57
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
【異常問(wèn)題解決】
1. 備份目錄的屬主和屬組不正確爽丹,不是rsync
2. 備份目錄的權(quán)限不正確筑煮,不是777
6. rsync服務(wù)備份目錄異常
【客戶端的錯(cuò)誤】
chdir failed
【錯(cuò)誤演示過(guò)程】
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
Password:
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
【異常問(wèn)題解決】
1. 備份存儲(chǔ)目錄沒(méi)有建立
2. 建立的備份存儲(chǔ)目錄和配置文件定義不一致
說(shuō)明:如果沒(méi)有備份存儲(chǔ)目錄
7. rsync服務(wù)無(wú)效用戶信息
【客戶端的錯(cuò)誤】
invalid uid rsync
【錯(cuò)誤演示過(guò)程】
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
Password:
@ERROR: invalid uid rsync
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
【異常問(wèn)題解決】
rsync服務(wù)對(duì)應(yīng)rsync虛擬用戶不存在了
8. 客戶端已經(jīng)配置了密碼文件,但免秘鑰登錄方式粤蝎,依舊需要輸入密碼
【客戶端的錯(cuò)誤】
password file must not be other-accessible
【錯(cuò)誤演示過(guò)程】
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
password file must not be other-accessible
continuing without password file
Password:
sending incremental file list
sent 26 bytes received 8 bytes 5.23 bytes/sec
total size is 349 speedup is 10.26
【異常問(wèn)題解決】
rsync客戶端的秘鑰文件也必須是600權(quán)限
9. rsync客戶端連接慢問(wèn)題
【錯(cuò)誤日志信息】 名稱或者域名 --- IP dns解析
錯(cuò)誤日志輸出 IP --- 名稱或者域名 反向dns解析
2017/03/08 20:14:43 [3422] params.c:Parameter() - Ignoring badly formed line in configuration file: ignore errors
2017/03/08 20:14:43 [3422] name lookup failed for 172.16.1.31: Name or service not known
2017/03/08 20:14:43 [3422] connect from UNKNOWN (172.16.1.31)
2017/03/08 20:14:43 [3422] rsync to backup/ from rsync_backup@unknown (172.16.1.31)
2017/03/08 20:14:43 [3422] receiving file list
2017/03/08 20:14:43 [3422] sent 76 bytes received 83 bytes total size 349
正確日志輸出
2017/03/08 20:16:45 [3443] params.c:Parameter() - Ignoring badly formed line in configuration file: ignore errors
2017/03/08 20:16:45 [3443] connect from nfs01 (172.16.1.31)
2017/03/08 20:16:45 [3443] rsync to backup/ from rsync_backup@nfs02 (172.16.1.31)
2017/03/08 20:16:45 [3443] receiving file list
2017/03/08 20:16:45 [3443] sent 76 bytes received 83 bytes total size 349
【異常問(wèn)題解決】
查看日志進(jìn)行分析真仲,編寫(xiě)rsync服務(wù)端hosts解析文件
客戶端 10.0.0.31 ---> 服務(wù)端 識(shí)別源地址 10.0.0.31 - RDNS(反向dns解析)
10 rsync服務(wù)沒(méi)有正確啟動(dòng)
【錯(cuò)誤日志信息】
Connection refused (111)
【錯(cuò)誤演示過(guò)程】
[root@oldboy-muban ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
rsync: failed to connect to 172.16.1.41: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
【異常問(wèn)題解決】
[root@oldboy-muban ~]# rsync --daemon
[root@oldboy-muban ~]# ss -lntup |grep rsync
tcp LISTEN 0 5 :::873 :::* users:(("rsync",1434,5))
tcp LISTEN 0 5 *:873 *:* users:(("rsync",1434,4))
[root@oldboy-muban ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
Password:
sending incremental file list
hosts
sent 196 bytes received 27 bytes 49.56 bytes/sec
total size is 349 speedup is 1.57