Gor + Apisix实现流量复制

环境准备

#安装Go 1.13+
$ wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz
$ tar -C /usr/local -zxvf go1.13.linux-amd64.tar.gz
$ sudo vim /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
$ source /etc/profile
#查看Go版本
$ go version

## 安装GIN 不需要就不执行
#解决Gin从Github拉取失败的问题
$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.io,direct
#安装
$ go get -u github.com/gin-gonic/gin

配置Apisix插件

找到Apisix对应的路由,配置Proxy-mirror插件,host配置为需要镜像转发的ip和port

"proxy-mirror": {
      "host": "http://<ip>:<port>"
}

GOR引流

#下载Gor
$ wget https://github.com/buger/goreplay/releases/download/v1.0-rc2/gor_1.0-RC2_x64.tar.gz
$ tar xvf gor_1.0-RC2_x64.tar.gz

#拉取本地Http端口上的流量,保存在本地文件中(GZ文件类型为压缩类型,可以减少磁盘空间占用)
$ sudo ./gor --input-raw :<port> \
--http-allow-url <Uri : /api/user/me|/api/*|..> \
--http-allow-method <Method : GET|POST|..> \
--output-file <FileName>
#转发文件中流量至指定环境
$ sudo ./gor --input-file <FileName> \
--output-http="http://<ip>:<port>"

#以2倍的速率发出去
$ sudo ./gor --input-file "./limit_0.gor|200%" --output-http="http://<host>:<port>"
#限速,指定每秒的请求数
$ sudo ./gor --input-file "./limit_0.gor" --output-http="http://<host>:<port>|1" 
#循环播放文件
--input-file-loop
#性能测试,模拟10倍流量
$ sudo ./gor --input-file "./limit_0.gor|1000%" --output-http="http://localhost:10850" --input-file-loop
#curl模拟发送测试数据
curl -i -X GET "www.baidu.com" -H "lilei: hanmeimei"

Gor一些常用的命令

--input-raw 抓取指定端口的流量
--output-stdout 打印到控制台
--output-file 将请求写到文件中
--input-file 从文件中读取请求,与上一条命令呼应
--http-allow-url url白名单,其他请求将会被丢弃
--http-allow-method 根据请求方式过滤
--http-disallow-url 遇上一个url相反,黑名单,其他的请求会被捕获到
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值