Linux 安装

XYGo Admin 2025-02-20 64 次阅读

Linux 生产环境部署指南

Linux 安装

以 Ubuntu 22.04 / CentOS 8 为例。

1. 安装 Go

bash 复制代码
# 下载
wget https://go.dev/dl/go1.24.0.linux-amd64.tar.gz

# 解压
sudo tar -C /usr/local -xzf go1.24.0.linux-amd64.tar.gz

# 配置环境变量
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc

# 设置代理
go env -w GOPROXY=https://goproxy.cn,direct

# 验证
go version

2. 安装 Node.js

bash 复制代码
# 使用 nvm 安装(推荐)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 20
nvm use 20

# 安装 pnpm
npm install -g pnpm

3. 安装 PostgreSQL

bash 复制代码
# Ubuntu
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql

# 创建数据库
sudo -u postgres psql
CREATE DATABASE xygoadmin WITH ENCODING 'UTF8';
ALTER USER postgres PASSWORD '123456';
\q

4. 安装 Redis

bash 复制代码
sudo apt install redis-server
sudo systemctl start redis
sudo systemctl enable redis

5. 部署项目

bash 复制代码
# 克隆代码
git clone https://gitee.com/a751300685a/xygo-admin.git
cd xygoadmin

# 导入数据库
psql -U postgres -d xygoadmin -f pgsql_install.sql

# 编译后端
cd server
go build -o xygoadmin main.go

# 构建前端
cd ../web
pnpm install
pnpm build

6. 配置 Nginx

bash 复制代码
sudo apt install nginx

将前端 dist/ 目录部署到 Nginx,配置反向代理到后端 8000 端口。详见「构建与部署」文档。

7. 配置 systemd

bash 复制代码
sudo vim /etc/systemd/system/xygoadmin.service
ini 复制代码
[Unit]
Description=XYGo Admin
After=network.target postgresql.service redis.service

[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/xygoadmin/server
ExecStart=/var/www/xygoadmin/server/xygoadmin
Restart=always

[Install]
WantedBy=multi-user.target
bash 复制代码
sudo systemctl daemon-reload
sudo systemctl start xygoadmin
sudo systemctl enable xygoadmin