前言
在 CentOS 9 x64 系統(tǒng)上,可以通過以下步驟來部署 Golang 服務(wù)。
1. 安裝必要的軟件包
安裝以下軟件包:
- Golang:Golang 編程語言
- Nginx:Web 服務(wù)器
- Supervisor:進(jìn)程管理工具
- Git:版本控制工具
- EPEL:擴(kuò)展軟件包
可以通過以下命令來安裝:
yum -y update
yum install nginx golang epel-release supervisor git -y
2. 生成 SSH 密鑰[可選]
為 Git 生成 SSH 密鑰,以便于進(jìn)行代碼管理??梢酝ㄟ^以下命令來生成:
cd ~
ssh-keygen -t rsa -C "your_email@example.com"
cat ~/.ssh/id_rsa.pub
將公鑰添加到 Git 倉(cāng)庫(kù)中。
3. 下載代碼
將代碼下載到服務(wù)器上,可以使用 Git 命令來下載代碼:
cd /
mkdir web
cd web
# or `git clone https://...`
git clone git@github.com:your_name/your_repo.git
cd /web/your_repo
4. 運(yùn)行應(yīng)用
在應(yīng)用根目錄下運(yùn)行以下命令來初始化應(yīng)用:
go run scripts/init/main.go
5. 編譯應(yīng)用
使用以下命令來編譯應(yīng)用:
GOOS=linux GOARCH=amd64 go build -o dist/app-linux-amd64 cmd/app/main.go
6. 配置 Supervisor
在 /etc/supervisord.d
目錄下創(chuàng)建一個(gè)新的配置文件 app.ini
,并添加以下內(nèi)容:
[program:app]
directory=/web/your_repo
command=/web/your_repo/dist/app-linux-amd64 -param1="value1" -param2="value2"
autostart=true
autorestart=true
stderr_logfile=/web/your_repo/log/app.err
stdout_logfile=/web/your_repo/log/app.log
environment=ENV_VAR1="value3",ENV_VAR2="value4"
啟動(dòng) Supervisor 并檢查狀態(tài):
systemctl start supervisord
systemctl status supervisord
systemctl enable supervisord
ps -ef|grep supervisord
后續(xù)更新重啟 app
:
# Start
supervisorctl start app
# Stop
supervisorctl stop app
# Restart
supervisorctl restart app
7. 配置 Nginx
在 /etc/nginx
目錄下打開 nginx.conf
文件,并修改以下內(nèi)容:
listen 80;
# listen [::]:80;
include /etc/nginx/conf.d/*.conf;
# 指向 Golang 的 Nginx Server 配置
include /your_path/your_app.conf;
然后重新啟動(dòng) Nginx 并檢查狀態(tài):
systemctl restart nginx
systemctl status nginx
現(xiàn)在,Golang 應(yīng)用已經(jīng)成功部署到 CentOS 服務(wù)器上了。
版權(quán)聲明
本博客所有的原創(chuàng)文章,作者皆保留版權(quán)。轉(zhuǎn)載必須包含本聲明,保持本文完整,并以超鏈接形式注明作者后除和本文原始地址:https://blog.mazey.net/3696.html文章來源:http://www.zghlxwxcb.cn/news/detail-527223.html
(完)文章來源地址http://www.zghlxwxcb.cn/news/detail-527223.html
到了這里,關(guān)于CentOS 9 x64 使用 Nginx、Supervisor 部署 Go/Golang 服務(wù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!