linux环境手动编译goreplay 0.16.1

1.安装golang环境, 以1.16.3为例

# 前期准备sudo apt-get install flex bison -y# Download latest stable release, compile and install itwget http://www.tcpdump.org/release/libpcap-1.7.4.tar.gz && tar xzf libpcap-1.7.4.tar.gzcd libpcap-1.7.4./configure && make install
# 下载golang安装包wget https://golang.org/dl/go1.16.3.linux-amd64.tar.gz # 解压tar -C /usr/local -zxvf  go1.16.3.linux-amd64.tar.gz
# 添加环境变更vim /etc/profile# 最后一行添加export GOROOT=/usr/local/goexport PATH=$PATH:$GOROOT/bin# 保存退出后sourcesource /etc/profile
# 输入go version验证是否安装成功root@duyan:/# go versiongo version go1.16.3 linux/amd64
# go env 查看go环境变量, 只关注以下3个GO111MODULE=""GOPATH="/root/go"GOPROXY="https://proxy.golang.org,direct"
# 若 GOPATH 文件夹不存在,新建一个mkdir /root/go
# 关闭 go modgo env -w GO111MODULE=off
# 设置国内代理go env -w GOPROXY="https://goproxy.io,direct"
# go env 查看结果如下,只关注以下3个GO111MODULE="off"GOPATH="/root/go"GOPROXY="https://goproxy.io,direct"

2.手动下载gorepaly 0.16.1 源码# cd到GOPATH目录

cd /root/go/# 手动创建gorepaly包目录, 并cd到buger目录mkdir src && cd src && mkdir github.com && cd github.com && mkdir buger && cd buger# git 手动下载 指定版本: v0.16.1git clone https://github.com/buger/goreplay.git -b v0.16.1

3.下载goreplay 依赖# 添加 -v 可以打印详细信息, 中途下载失败可以重复执行这个命令多试几次

go get -v github.com/buger/goreplay

4.编译

cd goreplaygo build -ldflags '-extldflags "-static" -s -w -X main.VERSION=0.16.1'
# 编译结果如下,有warning,不影响/tmp/go-link-853597898/000004.o: In function `_cgo_26061493d47f_C2func_getaddrinfo':/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking//usr/local/lib/libpcap.a(nametoaddr.o): In function `pcap_nametoaddr':/libpcap-1.7.4/./nametoaddr.c:102: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking//usr/local/lib/libpcap.a(nametoaddr.o): In function `pcap_nametonetaddr':/libpcap-1.7.4/./nametoaddr.c:146: warning: Using 'getnetbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking//usr/local/lib/libpcap.a(nametoaddr.o): In function `pcap_nametoproto':/libpcap-1.7.4/./nametoaddr.c:263: warning: Using 'getprotobyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking//usr/local/lib/libpcap.a(nametoaddr.o): In function `pcap_nametoport':/libpcap-1.7.4/./nametoaddr.c:176: warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
# goreplay 为输出的可执行文件# 指定可执行文件名命令: go build -ldflags '-extldflags "-static" -s -w -X main.VERSION=0.16.1' -o gorroot@duyan:~/go/src/github.com/buger/goreplay# ls...goreplay          input_dummy.go                  LICENSE.txt          output_http.go           raw_socket_listener

参考

公众号: 杜焰

https://github.com/buger/goreplay/wiki/Compilation

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值