Golang在CentOS上的打包流程如下:
sudo yum install golang。/usr/local,并设置GOROOT、GOPATH环境变量。go test验证功能。export GOOS=linux GOARCH=amd64。go build -o output_binary main.go。tar -czvf app.tar.gz output_binary config/。rpmbuild工具)。chmod +x output_binary,运行程序。优化建议:
CGO_ENABLED=0避免依赖外部库。参考来源: