操bb国片四区三区,亚洲一片内射无码,91短视频福利导航,蜜桃臀成人免费在线视频观看

驚!Rsync 文件同步竟遭遇失???手把手教你排查,告別同步煩惱!

2024-08-13 09:10:01 Jinyu

問題

rsync客戶端:拋錯異常退出

發(fā)布失敗截圖如下:

圖片

看報錯信息應該是 rsync 同步文件失敗,并非 salt 問題,為確認這點,我們登錄 salt-master,手工執(zhí)行 rsync 命令,確實無返回,排除 salt 及 salt-api 問題。
登錄同步異常服務器,手工執(zhí)行 rsync 同步命令,可以復現(xiàn):








# rsync -avz --delete --exclude='.git' --exclude='.svn' rsync://<rsync_srv>:<rsync_port>/path/to/folder /tmp/rsync-testreceiving incremental file list...rsync: read error: Connection reset by peer (104)rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.6]rsync: connection unexpectedly closed (99 bytes received so far) [generator]rsync error: error in rsync protocol data stream (code 12) at io.c(600) [generator=3.0.6]

rsync客戶端:進程僵死

周四反饋發(fā)布失敗的同學情況又不一樣了,發(fā)布并未拋明顯異常,但是進度條卡住一直無返回,查詢 salt-master 日志后,rsync 命令成功下發(fā),但確實無結(jié)果返回,懷疑服務器執(zhí)行 rsync 命令失敗,進程僵死,手工上服務器執(zhí)行了把,確實如此,只有當手工終止 rsync 命令后(ctrl+c),才拋異常信息:










# rsync -avzP --delete--exclude='.git' --exclude='.svn' rsync://<rsync_srv>:<rsync_port>/path/to/folder /tmp/rsync-testPassword: receiving incremental file list./<rsync-test-pkg>-SNAPSHOT.jar^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(551) [generator=3.0.9]
rsync error: received SIGUSR1 (code 19) at main.c(1298) [receiver=3.0.9]

執(zhí)行第二,甚至第三次時,才成功:










# rsync -avzP --delete--exclude='.git' --exclude='.svn' rsync://<rsync_srv>:<rsync_port>/path/to/folder /tmp/rsync-testPassword: receiving incremental file list./<rsync-test-pkg>-SNAPSHOT.jar60606801 100% 16.13MB/s0:00:03 (xfer#1, to-check=0/3)
sent 21035 bytesreceived 43167123 bytes5758421.07 bytes/sectotal size is 60607326speedup is 1.40

網(wǎng)上搜了下,發(fā)現(xiàn)已經(jīng)有人發(fā)現(xiàn) rsync 類似問題了,引用其博客:

盡管您可能已經(jīng)在rsyncd服務的后端進程中設置了--timeout選項(即在rsyncd.conf配置中),然而,在某些情況下(under the circumstances),這個選項可能根本不起作用,一些極不穩(wěn)定的網(wǎng)絡導致大量TCP超時連接,進而導致 rsync 進程失敗,雖然斷裂的 TCP 連線已經(jīng)消失,但 rsync 應用進程卻可能因為種種原因(如因等候I/O中斷而處于不可中斷狀態(tài)),而遺留在系統(tǒng)之中,并最終變成為僵尸進程(zombie process)。

按照其手冊頁的解釋,rsync 命令本身的 timeout 預設為0,也就是沒有逾時設置,因此運行中的 rsync 進程將會永久地等待遠端的反應。在rsyncd服務后端進程的 rsyncd.conf中設置timeout選項,同時在rsync客戶端命令行中使用timeout選項,實踐證明是可杜絕此問題的。

于是在服務器上添加 --timeout 參數(shù),再次執(zhí)行后確實能夠異常退出了:

# rsync -avzP --timeout=60 --delete--exclude='.git' --exclude='.svn' rsync://<rsync_srv>:<rsync_port>/path/to/folder /tmp/rsync-testPassword: receiving incremental file list./<rsync-test-pkg>-SNAPSHOT.jar2011425333% 19.18MB/s0:00:02[receiver] io timeout after 60 seconds -- exitingrsync error: timeout in data send/receive (code 30) at io.c(140) [receiver=3.0.9]rsync: connection unexpectedly closed (115 bytes received so far) [generator]rsync error: error in rsync protocol data stream (code 12) at io.c(605) [generator=3.0.9]

rsync服務端:異常日志

懷疑過是不是rsync服務端問題,重啟過服務端rsync服務,問題依然存在;換過rsync服務端,問題依然存在,由此可以排除服務端問題。
但無論客戶端拋哪種問題,服務端均能捕捉到,并輸出相應日志:







2018/10/26 14:40:30 [4228] name lookup failed for <rsync-client>: Name or service not known2018/10/26 14:40:30 [4228] connect from UNKNOWN (<rsync-client>)2018/10/26 14:40:30 [4228] rsync on path/to/folder from UNKNOWN (<rsync-client>)2018/10/26 14:40:30 [4228] building file list2018/10/26 14:40:35 [4228] rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Connection timed out (110)2018/10/26 14:40:35 [4228] rsync error: error in rsync protocol data stream (code 12) at io.c(1525) [sender=3.0.6]

rsync客戶端:strace排查

通過 strace 來跟蹤 rsync 進程執(zhí)行時的系統(tǒng)調(diào)用和所接收的信號,但未發(fā)現(xiàn)系統(tǒng)級明顯異常:

lstat("<rsync-test-pkg>-SNAPSHOT.jar", 0x7fff7d6e0000) = -1 ENOENT (No such file or directory)select(5, [4], [3], [3], {30, 0}) = 2 (in [4], out [3], left {29, 999998})select(5, [4], [], NULL, {30, 0}) = 1 (in [4], left {29, 999999})read(4, "\0\0\0\34", 8184)= 4write(3, "\26\0\0\7\1\10\0\3\0\240\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 26) = 26select(5, [4], [], NULL, {30, 0}./<rsync-test-pkg>-SNAPSHOT.jar) = 0 (Timeout)8.79MB/s0:00:02select(5, [4], [], NULL, {30, 0}) = 0 (Timeout)select(5, [4], [], NULL, {30, 0}[receiver] io timeout after 60 seconds -- exitingrsync error: timeout in data send/receive (code 30) at io.c(140) [receiver=3.0.9]) = 1 (in [4], left {28, 559609})--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=15649, si_status=30, si_utime=20, si_stime=5} ---wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 30}], WNOHANG, NULL) = 15649wait4(-1, 0x7fff7d6e11e4, WNOHANG, NULL) = -1 ECHILD (No child processes)rt_sigreturn()= 1read(4, "", 8184) = 0write(2, "rsync: connection unexpectedly c"..., 77rsync: connection unexpectedly closed (115 bytes received so far) [generator]) = 77write(2, "\n", 1) = 1rt_sigaction(SIGUSR1, {SIG_IGN, [], SA_RESTORER, 0x7f1e73cca670}, NULL, 8) = 0rt_sigaction(SIGUSR2, {SIG_IGN, [], SA_RESTORER, 0x7f1e73cca670}, NULL, 8) = 0getpid()= 15648kill(15649, SIGUSR1)= -1 ESRCH (No such process)write(2, "rsync error: error in rsync prot"..., 89rsync error: error in rsync protocol data stream (code 12) at io.c(605) [generator=3.0.9]) = 89write(2, "\n", 1) = 1exit_group(12)= ?+++ exited with 12 +++

問題根源:網(wǎng)絡質(zhì)量

由于發(fā)布系統(tǒng)與qa環(huán)境不在同一個機房,存在跨機房調(diào)用的情況,而兩端間的鏈路是走的公網(wǎng)VPN線路,確實可能存在質(zhì)量不穩(wěn)定的情況。
在執(zhí)行rsync命令異常的qa環(huán)境服務器上,抓到的包是這樣的:

圖片

而我們在與發(fā)布系統(tǒng)在同一機房網(wǎng)絡環(huán)境下,抓到的包是這樣的:

圖片

很明顯,跨機房網(wǎng)絡傳輸數(shù)據(jù)包中充斥著丟包、亂序以及重傳,從而導致傳輸失敗;
而在穩(wěn)定的網(wǎng)絡環(huán)境下,tcp包有序進行,rsync傳輸毫無問題。

TCP協(xié)議

這邊在相同的源服務器上部署了nginx,通過80端口,開放http協(xié)議,供相同的客戶端進行下載,結(jié)果發(fā)現(xiàn)wget相同文件,沒有任何問題,而且網(wǎng)速還挺快的:












# wget http://<sitename>/<rsync-test-pkg>-SNAPSHOT.jar--2018-10-26 10:57:45--http://<sitename>/<rsync-test-pkg>-SNAPSHOT.jarResolving <sitename> (<sitename>)... 10.20.51.127Connecting to <sitename> (<sitename>)|10.20.51.127|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 60606801 (58M) [application/java-archive]Saving to: ‘<rsync-test-pkg>-SNAPSHOT.jar’
100%[==================================================================================================================================================================>] 60,606,8019.81MB/s in 5.2s
2018-10-26 10:57:50 (11.1 MB/s) - ‘<rsync-test-pkg>-SNAPSHOT.jar’ saved [60606801/60606801]

但對其流量抓包,發(fā)現(xiàn)仍然有丟包的現(xiàn)象:

圖片

這就說明了一個現(xiàn)象:
rsync 的網(wǎng)絡傳輸協(xié)議特別依賴網(wǎng)絡質(zhì)量穩(wěn)定性,推測當其tcp丟包、亂序或重傳次數(shù)到達一定閾值時,便造成文件同步失敗。

緩解

詢問了網(wǎng)絡的同事,沒有辦法快速解決,除非花錢買專線,但資源成本太高,為解決跨機房數(shù)據(jù)同步這個問題,小題大做了。
所以在目前網(wǎng)絡環(huán)境下,無法從根源上有效解決該問題。
這邊嘗試過讓異常用戶重啟下rsync客戶端服務器,發(fā)現(xiàn)重啟后能夠同步成功,給到反饋發(fā)布失敗的用戶,也是給到該解決辦法,即使用戶很不理解為什么發(fā)布失敗為什么需要他們重啟服務器來解決,其實我也表示很無奈啊…

后記

當然,問題還是存在,rsync不行,這邊就需要考慮通過其他方式來完成機房間文件存儲同步了,這塊需要后續(xù)調(diào)研下。


我要咨詢