rsync服務配置和使用

rsync使用系統賬號在服務器之間同步文件時,默認一般是22端口,一般建議加上-e參數指定端口,特別是使用非22端口時,如:
rsync -avuz -e 'ssh -p 2222' user@remote-server:/path/to/remote/folder /path/to/local/folder

rsync以服務方式運行時,默認監聽端口是873,而且一般是創建虛擬用戶,而非使用系統用戶。

參考:rsync服務介紹和配置 https://www.cnblogs.com/cocowool/p/6548476.html

 

其他參考——傳輸大文件報錯:

https://serverfault.com/questions/570837/how-to-fix-corrupt-packet-error-for-with-rsync-for-relatively-large-files

問題:
嘗試使用rsync命令更新服務器上的文件:
rsync -ravq -e "ssh -o ConnectTimeout=2 -o ServerAliveInterval=2 -ServerAliveCountMax=2" --delete ./local_dir user@$SERVER:/dest_dir
數據包損壞的錯誤不斷被拋出,具體來說:
rsync: writefd_unbuffered failed to write 4092 bytes to socket [sender]: Broken pipe (32)
rsync: connection unexpectedly closed (11337 bytes received so far) [sender]
rsync error: unexplained error (code 255) at /home/lapo/package/rsync-3.0.9-1/src/rsync-3.0.9/io.c(605) [sender=3.0.9]

這可能與ssh超時有關,因爲它似乎發生在大(r)文件中。此外,我使用WinSCP持續出現超時。這隻發生在我身上,使用這個服務器的幾個人沒有同樣的問題.

在Windows 7中使用Cygwin終端的rsync,對接Centos 6.3服務器。

評論:
我不確定是什麼可能導致數據包損壞從而丟失連接,但你可能會發現rsync的–partial或–partial-dir選項在傳輸大文件時很有用,這樣當你重新啓動傳輸時它將繼續從上次中斷處接着傳輸而不必重新開始發送整個文件:
--partial-DIR=.rsync-partial

所以你可以像這樣修改原始命令:

rsync -rav --progress --partial -e "ssh -o ConnectTimeout=2 -o ServerAliveInterval=2 -ServerAliveCountMax=2" --delete ./local_dir user@$SERVER:/dest_dir
或者
rsync -rav --progress --partial-dir=.rsync-partial -e "ssh -o ConnectTimeout=2 -o ServerAliveInterval=2 -ServerAliveCountMax=2" --delete ./local_dir user@$SERVER:/dest_dir

請注意,對於此示例,我刪除了-q(--quiet)選項,並在第一個示例中添加了--progress選項,在第二個示例中添加了--partial-dir=.rsync-partial。

--partial和--partial-dir=.rsync-partial之間的區別在於,後者會創建一個目錄,使得未完成的文件與完成傳輸的文件分開(如果這對你的接收(服務器端)端很重要的話)。

rsync manpage(http://rsync.samba.org/ftp/rsync/rsync.html)將進一步詳細解釋這一點,但我還要從手冊頁中指出一個重要的安全說明:
IMPORTANT: the --partial-dir should not be writable by other users or it is a security risk. E.g. AVOID “/tmp”.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章