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已知
1.2把共享目錄/backup
推到本地的/yunwei
目錄相下
1.3檢驗
2.刪
2.1首先查看目錄/backup
里有以下內容
2.2首先查看目錄/yunwei
里有以下內容
2.3備份
2.4檢查/yunwei
目錄
Rsync--兩台不同IP服務器之間的傳輸
1.查看數據
1.1查看本地
共享目錄/backup
目錄下
1.2查看備份Web服務器/yangwenbo
目錄下
2.從本地
掛載備份
3.從備份Wbo服務器
檢查
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.創建程序用戶
3.創建它的共享目錄
4.啟動進程
5.查看端口
6.修改共享目錄backup的屬主與屬組
7.創建rsync虛擬賬號名與密碼
8.修改rsync.password的權限
9.加入開機自啟動
客戶端(本地):##
1.創建密碼
2.加權限
實驗如下:
1.一般模式
由客戶端操作:
1.1客戶端如下:
1.2服務端如下:
1.3實驗備份
1.4實驗結果(服務端檢查):
2.不想輸密碼,一次過
2.1已知客戶端目錄
2.2已知服務端目錄
2.3由客戶端操作
2.4服務端檢查
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]
說明:原數據目錄里沒有數據存在