Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现打包部署到服务器 #3

Open
yaogengzhu opened this issue Oct 15, 2023 · 1 comment
Open

实现打包部署到服务器 #3

yaogengzhu opened this issue Oct 15, 2023 · 1 comment

Comments

@yaogengzhu
Copy link
Member

yaogengzhu commented Oct 15, 2023

将go 项目打包成可执行的二进制文件

 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build

在云端拉取二进制文件

./ginchat

可能会找不到配置文件,需要设置下路径信息

 CONFIG_PATH=/root/serve/ginchat/config ./ginchat&

& 表示可后台运行

查看当前运行的端口 如 8888

netstat -tuln | grep 8888
@yaogengzhu
Copy link
Member Author

yaogengzhu commented Oct 26, 2023

部署现在遇到一个问题,过一段时间就502了

方案1, 保持db 长链接 【未解决】

方案2, 更换启动方式 【未解决】

nohup ./ginchat > output.log 2>&1 &

方案3 改用linux 的启动方式 【解决】

第一步: 新建一个ginchat.service 的文件

  • user, group 统一用root 吧
[Unit]
Description=GinChat Service
After=network.target

[Service]
User=your_user
Group=your_group
Restart=always
WorkingDirectory=/path/to/your/ginchat
ExecStart=/path/to/your/ginchat/ginchat

[Install]
WantedBy=multi-user.target

第二步 : 执行如下命令

sudo systemctl enable ginchat.service
sudo systemctl start ginchat.service

第三步: 查看服务状态

sudo systemctl status ginchat.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant