Files
navigation-app/README.md
2025-03-26 01:09:15 +08:00

281 lines
3.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[TOC]
# navigation-app
from deepseek
## 详细部署流程
### 1. 开发环境准备
1. **安装Go语言环境** (仅开发机需要):
bash
复制
```
# Linux
sudo apt update && sudo apt install -y golang
# Mac
brew install go
# Windows
# 从 https://golang.org/dl/ 下载安装包
```
2. **初始化Go模块**:
bash
复制
```
cd backend
go mod init navigation/backend
go mod tidy
```
### 2. 编译应用程序
1. **编译Linux可执行文件**:
bash
复制
```
make build
```
这会在`bin/`目录下生成`navigation-server`二进制文件
### 3. VPS部署步骤
1. **上传文件到VPS**:
bash
复制
```
scp -r bin/ navigation-server config/ frontend/ data/ user@your_vps_ip:/opt/navigation-app
```
2. **SSH登录VPS**:
bash
复制
```
ssh user@your_vps_ip
```
3. **设置文件权限**:
bash
复制
```
cd /opt/navigation-app
chmod +x bin/navigation-server
mkdir -p data
chmod 700 data
```
4. **运行应用程序** (测试运行):
bash
复制
```
cd /opt/navigation-app
./bin/navigation-server
```
5. **配置持久化运行** (使用systemd):
创建服务文件`/etc/systemd/system/navigation.service`:
ini
复制
```
[Unit]
Description=Navigation Server
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/opt/navigation-app
ExecStart=/opt/navigation-app/bin/navigation-server
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
```
启用并启动服务:
bash
复制
```
sudo systemctl daemon-reload
sudo systemctl enable navigation
sudo systemctl start navigation
```
6. **验证服务运行**:
bash
复制
```
sudo systemctl status navigation
curl http://localhost:8080/api/sites
```
### 4. 配置反向代理 (可选,推荐)
使用Nginx作为反向代理:
1. **安装Nginx**:
bash
复制
```
sudo apt update && sudo apt install -y nginx
```
2. **创建配置文件** `/etc/nginx/sites-available/navigation`:
nginx
复制
```
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
```
3. **启用配置**:
bash
复制
```
sudo ln -s /etc/nginx/sites-available/navigation /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
```
4. **配置HTTPS (使用Let's Encrypt)**:
bash
复制
```
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
```
## 维护与管理
### 常用命令
- **查看日志**:
bash
复制
```
journalctl -u navigation -f
```
- **重启服务**:
bash
复制
```
sudo systemctl restart navigation
```
- **备份数据库**:
bash
复制
```
cp /opt/navigation-app/data/navigation.db /path/to/backup/navigation_$(date +%F).db
```
### 更新流程
1. 本地修改代码后重新编译:
bash
复制
```
make build
```
2. 上传新版本到VPS:
bash
复制
```
scp bin/navigation-server user@your_vps_ip:/opt/navigation-app/bin/
```
3. 重启服务:
bash
复制
```
ssh user@your_vps_ip
sudo systemctl restart navigation
```
这个方案提供了完整的、生产就绪的Go后端实现具有以下优点
1. 单个静态二进制文件,部署简单
2. 使用SQLite数据库无需额外服务
3. 完整的CRUD API实现
4. 包含生产环境部署配置
5. 易于维护和更新