最近公司上马go的项目,每次更新代码都要停机琢磨了一下做了一个减配方案,后期再上新方案
1、复制项目main.go
main.go文件监听8080
run.go 文件监听8081
分别执行
go build -o run1 main.go
go build -o run2 run.go
将打包好的run1和run2覆盖到linux的项目目录下
nohup后台启动项目
nohup ./run1 > sys1.out 2>&1 &
nohup ./run2 > sys2.out 2>&1 &
nginx代理轮询服务
upstream go_http {
server 10.101.21.10:8080;
server 10.101.21.11:8081;
}server {
listen 80;
server_name www.test.com;
root xxxxx/xxx/xxx/xx;
location /api/ {
proxy_pass http://go_http/;
}
}
后续更新代码可以逐个覆盖重启项目做到平滑更新
当然这里必不可少的有一个优雅关闭,具体的自行百度吧每个框架的做法不一样。这里贴出iris的处理方式
serverWG := new(sync.WaitGroup)
defer serverWG.Wait()
// Iris ========================================
iris.RegisterOnInterrupt(func() {
serverWG.Add(1)
defer serverWG.Done()
timeout := 5 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
// 关闭所有主机
app.Shutdown(ctx)
})
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)