Gor 是一款go語(yǔ)言實(shí)現(xiàn)的簡(jiǎn)單的http流量復(fù)制工具,它的主要目的是使你的生產(chǎn)環(huán)境HTTP真實(shí)流量在測(cè)試環(huán)境和預(yù)發(fā)布環(huán)境重現(xiàn)。只需要在 LB 或者 Varnish 入口服務(wù)器上執(zhí)行一個(gè)進(jìn)程,就可以把生產(chǎn)環(huán)境的流量復(fù)制到任何地方,完美解決了 HTTP 層實(shí)時(shí)流量復(fù)制和壓力測(cè)試的問(wèn)題。對(duì)比在Nginx通過(guò)編寫(xiě)lua腳本進(jìn)行流量拷貝要更加簡(jiǎn)單便捷,下載解壓后就可馬上使用。
二、Gor安裝
安裝包下載地址:https://github.com/buger/goreplay/releases
下載完成后,將解壓后的goreplay文件復(fù)制到/usr/bin下,就可以開(kāi)始使用了
三、使用方法
1.基礎(chǔ)HTTP流量復(fù)制
將本機(jī)上80端口的流量全部復(fù)制到192.168.0.100的8080端口
goreplay –input-raw :80 –output-http 'https://192.168.0.100:8080'
2.HTTP流量復(fù)制頻率控制
將本機(jī)上80端口的流量復(fù)制到192.168.0.100的8080端口,每秒請(qǐng)求不超過(guò)10個(gè)
goreplay –input-tcp :80 –output-http "https://192.168.0.100:8080|10"
將本機(jī)上80端口的流量復(fù)制到192.168.0.100的8080端口,每秒請(qǐng)求不超過(guò)總數(shù)的10%
goreplay –input-raw :80 –output-http "https://192.168.0.100:8080|10%"
3.HTTP流量復(fù)制輸出到文件
goreplay –input-raw :80 –output-file requests.log
4.通過(guò)HTTP流量回放進(jìn)行壓力測(cè)試
goreplay –input-file 'request.gor|200%' –output-http 'https://192.168.0.100:8080'
5.過(guò)濾指定url,進(jìn)行HTTP流量復(fù)制
goreplay –input-raw :80 –output-http 'https://192.168.0.100:8080' –http-original-host –output-http-url-regexp test
6.過(guò)濾請(qǐng)求頭,進(jìn)行HTTP流量復(fù)制
goreplay –input-raw :80 –output-http 'https://192.168.0.100:8080' –http-allow-header api-version:^1.0d
7.過(guò)濾http方法,進(jìn)行HTTP流量復(fù)制
goreplay –input-raw :80 –output-http "https://192.168.0.100:8080" –http-allow-method GET –http-allow-method OPTIONS
8.將HTTP流量進(jìn)行url重寫(xiě)后再?gòu)?fù)制
goreplay –input-raw :80 –output-http 'https://192.168.0.100:8080' –http-rewrite-url /v1/user/([^\/]+)/ping:/v2/user/$1/ping