Rsync


Rsync簡介:

具有可使本地和遠程兩台主機之間的數據快速復制同步鏡像,遠程備份的功能,這個功能類似ssh帶的scp命令,但又優於scp命令的功能,scp每次都是全量拷貝,而rsync可以增量拷貝。當然,Rsync還可以在本地主機的不同分區或目錄之間全量及增量的復制數據,這又類似cp命令,但同樣也優於cp命令,cp每次都是全量拷貝,而rsync可以增量拷貝。


rsync的流氓屬性:我復制給你你所沒有的文件,同時刪除你有我沒有的文件(保存兩台服務器數據的完全同步)

#兩台服務器都必須裝兩個軟件包
[root@yangwenbo /]# yum -y install rsync openssh-clients
[root@yangwenbo /]# rpm -qa rsync openssh-clients
openssh-clients-7.4p1-16.el7.x86_64
rsync-3.1.2-4.el7.x86_64

rsync 命令常用參數選項說明:

v,--verbose 詳細模式輸出,傳輸時的進度等信息
z,--compress 傳輸時進行壓縮以提高傳輸效率,--compress-level=NUM可按級別壓縮。
a,--archive 歸檔模式,表示以遞歸方式傳輸文件,並保持所有文件屬性,等於-rtopgD1(字母1)

Rsync--本地用戶

1.簡單備份

1.1已知

image_1cjnu7uehruoeju1d7810hk18ka1g.png-3.3kB

1.2把共享目錄/backup推到本地的/yunwei目錄相下

image_1cjo2dj4m140rs1e1rr81cvq1sq8cm.png-11.8kB

1.3檢驗

image_1cjnublmu1g5cniqmtd4lp1elm2q.png-2.4kB

2.刪

2.1首先查看目錄/backup里有以下內容

image_1cjnul38n1d703t6jonihg5j241.png-3.6kB

2.2首先查看目錄/yunwei里有以下內容

image_1cjnuifbl167413afv021utr1d743k.png-3.1kB

2.3備份

image_1cjnuni0h12ocf1313qb9651kgh4e.png-12.2kB

2.4檢查/yunwei目錄

image_1cjo2f8jshfu13bpeddfa2rhqd3.png-2.4kB

Rsync--兩台不同IP服務器之間的傳輸

1.查看數據

1.1查看本地共享目錄/backup目錄下

image_1cjnuvh82m0u4t8ujd1d5b1isl58.png-2.5kB

1.2查看備份Web服務器/yangwenbo目錄下

image_1cjo0eiqf1ompea91ke617a4p7e62.png-1.9kB

2.從本地掛載備份

image_1cjo0i2d9qja45t1v3s1c2f1pul6f.png-10.8kB

3.從備份Wbo服務器檢查

image_1cjo14bbma9n1vo2s50qn7vlc6s.png-2.2kB

Rsync--虛擬用戶

服務端(備份):

1.手動編寫配置文件

[root@root ~]# vim /etc/rsyncd.conf
[root@root ~]# 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/log/rcyncd.lock

[backup]
path = /backup/
ignore errors
read only = false
list = false
hosts allow = 192.168.200.0/24
hosts deny = 0.0.0.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password

2.創建程序用戶

image_1cjo1f4jq1lt2tt1149qf5gmr89.png-4.4kB

3.創建它的共享目錄

image_1cjo2i0ss288ejk1m2j1v1b17jbdg.png-1.7kB

4.啟動進程

image_1cjo2j3m4kbtle818ir1f5icskdt.png-1.7kB

5.查看端口

image_1cjo2khiq5mj2hl1pod7mh1qecea.png-6kB

6.修改共享目錄backup的屬主與屬組

image_1cjo2n4ca1usd1u0nrs3hnp1ctcf4.png-5.5kB

7.創建rsync虛擬賬號名與密碼

image_1cjo2pafg2bc1d9b1oru1b382dkfh.png-3.5kB

8.修改rsync.password的權限

image_1cjo2r5c93b05m61s6111cu9kefu.png-4.9kB

9.加入開機自啟動

image_1cjo2u2pn1ivo12cd9p11v051uamgb.png-11.5kB

客戶端(本地):##

1.創建密碼

image_1cjo30s8h1efemus6gsfts1kfmh5.png-4.2kB

2.加權限

image_1cjo32jr81abn1igc13hl1k2r1ll6hi.png-4.9kB

實驗如下:

1.一般模式

由客戶端操作:

1.1客戶端如下:

image_1cjo3dguj1t6l1u5nsjb1c365dshv.png-2.4kB

1.2服務端如下:

image_1cjo3nun2ot71t411dq59qoahsj6.png-1.7kB

1.3實驗備份

image_1cjo3ft891jcasik15oh1t9f191eic.png-13.1kB

1.4實驗結果(服務端檢查):

image_1cjo3navi10cj6qa6bi8juj94ip.png-2.7kB

2.不想輸密碼,一次過

2.1已知客戶端目錄

image_1cjsiqmbqj4dtmf1f01boto1f9.png-2.3kB

2.2已知服務端目錄

image_1cjsis9iss4sm961kae18jn1m94m.png-2.4kB

2.3由客戶端操作

image_1cjsiu5rdadn51q1635pb34n513.png-16.9kB

2.4服務端檢查

image_1cjsj0q46l29n9p1etekj9km03t.png-2.4kB

rsync 常見錯誤與解決方法整理

問題1:

@ERROR: chroot failed 
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:服務器端的目錄不存在或無權限,創建目錄並修正權限可解決問題。

問題2:

@ERROR: auth failed on module tee 
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:服務器端該模塊(tee)需要驗證用戶名密碼,但客戶端沒有提供正確的用戶名密碼,認證失敗。

  • 提供正確的用戶名密碼解決此問題。

問題3:

@ERROR: Unknown module ‘tee_nonexists' 
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:服務器不存在指定模塊。提供正確的模塊名或在服務器端修改成你要的模塊以解決問題。

問題4: 在client上遇到問題: 
4.1

rsync -auzv --progress --password-file=/etc/rsync.pas root@192.168.133.128::backup /home/ 
rsync: could not open password file "/etc/rsync.pas": No such file or directory (2) 
Password: 
@ERROR: auth failed on module backup 
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]

遇到這個問題:client端沒有設置/etc/rsync.pas這個文件,而在使用rsync命令的時候,加了這個參數-- 
password-file=/etc/rsync.pas

4.2

rsync -auzv --progress --password-file=/etc/rsync.pas root@192.168.133.128::backup /home/ 
@ERROR: auth failed on module backup 
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]

遇到這個問題:client端已經設置/etc/rsync.pas這個文件,里面也設置了密碼111111,和服務器一致,但是 
服務器段設置有錯誤,服務器端應該設置/etc/rsync.pas ,里面內容root:111111 ,這里登陸名不可缺少

問題5:

rsync -auzv --progress --password-file=/etc/rsync.pas root@192.168.133.128::backup /home/ 
@ERROR: chdir failed 
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]

遇到這個問題,是因為服務器端的/home/backup 其中backup這個目錄並沒有設置,所以提示:chdir failed

問題6:

rsync: write failed on "/home/backup2010/wensong": No space left on device (28) 
rsync error: error in file IO (code 11) at receiver.c(302) [receiver=3.0.7] 
rsync: connection unexpectedly closed (2721 bytes received so far) [generator] 
rsync error: error in rsync protocol data stream (code 12) at io.c(601) [generator=3.0.7]

磁盤空間不夠,所以無法操作。 
可以通過df /home/backup2010 來查看可用空間和已用空間

問題7:網絡收集問題 
7.1 權限問題 
類似如下的提示:

rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13)

注意查看同步的目錄權限是否為755

7.2 time out

rsync: failed to connect to 203.100.192.66: Connection timed out (110) 
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]

檢查服務器的端口netstat –tunlp,遠程telnet測試。 
可能因為客戶端或者服務端的防火牆開啟 導致無法通信,可以設置規則放行 rsync(873端口) 或者直接關閉防火牆。

還有一種在同步過程中可能會提示沒有權限 (將同步目錄加上SvcwRsync全部權限即可,更簡單的方法就是將SvcwRsync設為管理員即可)

7.3 服務未啟動

rsync: failed to connect to 10.10.10.170: Connection refused (111) 
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]

啟動服務:rsync --daemon --config=/etc/rsyncd.conf

7.4磁盤空間滿

rsync: recv_generator: mkdir "/teacherclubBackup/rsync……" failed: No space left on device (28) 
*** Skipping any contents from this failed directory ***

7.5Ctrl+C或者大量文件

rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [receiver=3.0.5] 
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [generator=3.0.5]

說明:導致此問題多半是服務端服務沒有被正常啟動,到服務器上去查查服務是否有啟動,然后查看下 /var/run/rsync.pid 文件是否存在,最干脆的方法是殺死已經啟動了服務,然后再次啟動服務或者讓腳本加入系統啟動服務級別然后shutdown -r now服務器

問題8.Rsync error: 
錯誤一:

@ERROR: auth failed on module xxxxx 
rsync: connection unexpectedly closed (90 bytes read so far) 
rsync error: error in rsync protocol data stream (code 12) at io.c(150)

說明:這是因為密碼設置錯了,無法登入成功,檢查一下rsync.pwd,看客服是否匹配。還有服務器端沒啟動rsync 服務也會出現這種情況

錯誤二:

password file must not be other-accessible 
continuing without password file 
Password:

說明:這是因為rsyncd.pwd rsyncd.sec的權限不對,應該設置為600。如:chmod 600 rsyncd.pwd

錯誤三:

@ERROR: chroot failed 
rsync: connection unexpectedly closed (75 bytes read so far) 
rsync error: error in rsync protocol data stream (code 12) at io.c(150)

說明:這是因為你在 rsync.conf 中設置的 path 路徑不存在,要新建目錄才能開啟同步

錯誤四:

rsync: failed to connect to 218.107.243.2: No route to host (113) 
rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]

說明:防火牆問題導致,這個最好先徹底關閉防火牆,排錯的基本法就是這樣,無論是S還是C,還有ignore errors選項問題也會導致

錯誤五:

@ERROR: access denied to www from unknown (192.168.1.123)
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(359)

說明:此問題很明顯,是配置選項host allow的問題,初學者喜歡一個允許段做成一個配置,然后模塊又是同一個,致使導致

錯誤六:

rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(244) [generator=2.6.9]
rsync error: received SIGUSR1 (code 19) at main.c(1182) [receiver=2.6.9]

說明:導致此問題多半是服務端服務沒有被正常啟動,到服務器上去查查服務是否有啟動,然后查看下 /var/run/rsync.pid 文件是否存在,最干脆的方法是殺死已經啟動了服務,然后再次啟動服務或者讓腳本加入系統啟動服務級別然后shutdown -r now服務器

錯誤七:

rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(604) [sender=2.6.9]

說明:原數據目錄里沒有數據存在


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM