Goreplay開源工具的介紹,安裝及使用 (Linux)


Goreplay

介紹

GoReplay是一個開源的網絡監控工具,它可以記錄你的實時流量,並用於跟蹤、負載測試、監控和詳細分析。

GoReplay提供了一種unique approach for shadowing方式:GoReplay不是以代理形式,而是監聽網絡接口上的流量,不需要對生產基礎設施進行任何更改,而是在與服務相同的機器上運行GoReplay守護進程。

GoReplay的工作原理框圖:

 

Linux系統環境下的安裝 

Golang安裝

一 、首先安裝Golang及相關依賴環境

 在官網上下載安裝包或者go的一些中文網站上下載安裝包

1. https://golang.org/dl/

2. https://studygolang.com/dl

我下載的是: go1.14.4.linux-amd64.tar.gz

二、解壓到/usr/local目錄下

tar -C /usr/local -zxvf go1.14.4.linux-amd64.tar.gz

三、配置環境變量

# 打開
vim /etc/profile
# 添加
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
# 編譯生效
source /etc/profile

四、驗證

go env

GoReplay安裝

 官網上下載源碼包: goreplay-1.1.0.tar.gz

https://github.com/buger/goreplay/releases

解壓: 

tar xvf goreplay-1.1.0.tar.gz

cd goreplay-1.1.0/

編譯

go build

編譯出現問題:

vendor/github.com/google/gopacket/pcap/pcap_unix.go:34:18: fatal error: pcap.h: No such file or directory

解決辦法:

安裝 libpcap
  下載地址:http://www.tcpdump.org/
  下載版本:libpcap-1.2.1.tar.gz

解壓,執行:

./configure
make
make install

回到goreplay-1.1.0目錄,再次執行編譯命令: 

go build

編譯成功后生成可執行文件:goreplay

 安裝成功。

GoReplay的常用使用方式:

1. 轉發(改成你需要的ip和端口)
./goreplay --input-raw :8080 --output-http "http://192.168.1.100:6660"

2. 保存到文件
./goreplay --input-raw :8080 --output-file “requests.gor“

3. 保存到文件,添加內容到相同文件
./goreplay --input-raw :8080 --output-file requests.txt --output-file-append

4. 從文件轉發
./goreplay --input-file requests.txt --output-http "http://192.168.1.100:6660"
5. 只允許轉url regexp
./goreplay --input-raw :8080 --output-http staging.com --http-allow-url /api

6. 轉發到本機tcp(適用於nginx upstream的情況)

需要打開2goreplay
./goreplay --input-raw :1029 --output-tcp "localhost:28020"
./goreplay --input-tcp :28020 --output-file "request.gor"

 7. 循環+流量放大

 ./goreplay --input-file "oo01_0.log|1000%" --output-http "http://xxx.cn" --input-file-loop

 


免責聲明!

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



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