315 lines
6.4 KiB
Markdown
315 lines
6.4 KiB
Markdown
# 快速启动指南
|
||
|
||
## 在服务器上运行
|
||
|
||
### 1. 上传代码到服务器
|
||
|
||
```bash
|
||
# 上传整个项目目录到服务器
|
||
scp -r licensing-cotton user@your-server:/path/to/
|
||
```
|
||
|
||
### 2. 在服务器上编译
|
||
|
||
```bash
|
||
cd /path/to/licensing-cotton
|
||
go build -o licensing-cotton cmd/server/main.go
|
||
```
|
||
|
||
**注意**:首次启动会自动生成密钥对,无需手动创建 `keys/` 目录!
|
||
|
||
### 3. 启动服务
|
||
|
||
**方式一:后台运行(简单)**
|
||
```bash
|
||
# 创建日志目录
|
||
mkdir -p /var/log
|
||
|
||
# 后台运行
|
||
nohup ./licensing-cotton > /var/log/licensing-cotton.out 2>&1 &
|
||
|
||
# 查看日志
|
||
tail -f /var/log/licensing-cotton.out
|
||
```
|
||
|
||
**方式二:使用 systemd(推荐用于生产环境)**
|
||
|
||
创建服务文件:
|
||
```bash
|
||
sudo vi /etc/systemd/system/licensing-cotton.service
|
||
```
|
||
|
||
内容:
|
||
```ini
|
||
[Unit]
|
||
Description=Licensing Cotton License Management System
|
||
After=network.target
|
||
|
||
[Service]
|
||
Type=simple
|
||
User=your-username
|
||
WorkingDirectory=/path/to/licensing-cotton
|
||
ExecStart=/path/to/licensing-cotton/licensing-cotton
|
||
Restart=always
|
||
RestartSec=5
|
||
StandardOutput=append:/var/log/licensing-cotton.out
|
||
StandardError=append:/var/log/licensing-cotton.err
|
||
|
||
[Install]
|
||
WantedBy=multi-user.target
|
||
```
|
||
|
||
启用并启动服务:
|
||
```bash
|
||
sudo systemctl daemon-reload
|
||
sudo systemctl enable licensing-cotton
|
||
sudo systemctl start licensing-cotton
|
||
|
||
# 查看状态
|
||
sudo systemctl status licensing-cotton
|
||
|
||
# 查看日志
|
||
sudo journalctl -u licensing-cotton -f
|
||
```
|
||
|
||
### 4. 配置防火墙
|
||
|
||
如果使用了防火墙,需要开放 8895 端口:
|
||
|
||
```bash
|
||
# 使用 firewalld
|
||
sudo firewall-cmd --permanent --add-port=8895/tcp
|
||
sudo firewall-cmd --reload
|
||
|
||
# 使用 ufw
|
||
sudo ufw allow 8895/tcp
|
||
```
|
||
|
||
## 访问系统
|
||
|
||
### 浏览器访问
|
||
|
||
打开浏览器访问:
|
||
```
|
||
http://your-server-ip:8895
|
||
```
|
||
|
||
### 登录
|
||
|
||
默认管理员账号:
|
||
- **用户名**:`admin`
|
||
- **密码**:`admin123`
|
||
|
||
⚠️ **重要**:首次登录后请修改密码!
|
||
|
||
## 基本使用流程
|
||
|
||
### 1. 首次配置 - 开启自动续期
|
||
|
||
登录后:
|
||
1. 点击 **"系统设置"** 标签
|
||
2. 开启 **"自动续期所有设备"** 开关
|
||
3. 点击刷新确认状态
|
||
|
||
### 2. 创建设备
|
||
|
||
1. 点击 **"设备管理"** 标签
|
||
2. 在"创建/更新设备"表单中:
|
||
- 输入设备 ID(例如:`dev-001`)
|
||
- 选择到期时间(默认为1年后)
|
||
- 点击 **"保存设备"**
|
||
3. 在设备列表中确认设备已创建
|
||
|
||
### 3. 签发 License
|
||
|
||
1. 点击 **"签发License"** 标签
|
||
2. 输入设备 ID
|
||
3. 点击 **"签发License"**
|
||
4. 复制返回的完整 License JSON(包含签名)
|
||
|
||
### 4. 续期请求审批(如果关闭了自动续期)
|
||
|
||
1. 点击 **"续期审批"** 标签
|
||
2. 查看待审批的续期请求
|
||
3. 点击 **"批准"** 或 **"拒绝"**
|
||
|
||
## 常用操作
|
||
|
||
### 查看服务状态
|
||
```bash
|
||
# 如果使用 systemd
|
||
sudo systemctl status licensing-cotton
|
||
|
||
# 如果使用 nohup
|
||
ps aux | grep licensing-cotton
|
||
```
|
||
|
||
### 停止服务
|
||
```bash
|
||
# systemd
|
||
sudo systemctl stop licensing-cotton
|
||
|
||
# nohup
|
||
pkill licensing-cotton
|
||
```
|
||
|
||
### 重启服务
|
||
```bash
|
||
sudo systemctl restart licensing-cotton
|
||
```
|
||
|
||
### 查看日志
|
||
```bash
|
||
# systemd 日志
|
||
sudo journalctl -u licensing-cotton -f
|
||
|
||
# 或者查看输出文件
|
||
tail -f /var/log/licensing-cotton.out
|
||
```
|
||
|
||
### 数据库位置
|
||
|
||
数据库文件位于项目目录:
|
||
```
|
||
/path/to/licensing-cotton/mydb.db
|
||
```
|
||
|
||
定期备份此文件!
|
||
|
||
### 密钥位置
|
||
|
||
密钥文件位于项目目录:
|
||
```
|
||
/path/to/licensing-cotton/keys/
|
||
├── licensing-key # 私钥(加密,权限 600)
|
||
└── licensing-key.pub # 公钥(权限 644)
|
||
```
|
||
|
||
⚠️ **非常重要**:请备份整个 `keys/` 目录!丢失私钥将无法签发新 License!
|
||
|
||
```bash
|
||
# 备份密钥
|
||
tar -czf keys-backup-$(date +%Y%m%d).tar.gz keys/
|
||
```
|
||
|
||
## 故障排查
|
||
|
||
### 服务无法启动
|
||
|
||
1. 检查端口是否被占用:
|
||
```bash
|
||
netstat -tlnp | grep 8895
|
||
lsof -i :8895
|
||
```
|
||
|
||
2. 检查日志文件查看错误信息
|
||
|
||
3. 检查文件权限:
|
||
```bash
|
||
chmod +x licensing-cotton
|
||
```
|
||
|
||
### 前端无法访问
|
||
|
||
1. 检查服务是否运行
|
||
2. 检查防火墙设置
|
||
3. 检查云服务器安全组规则(阿里云、腾讯云等)
|
||
|
||
### 数据库错误
|
||
|
||
删除并重建数据库:
|
||
```bash
|
||
cd /path/to/licensing-cotton
|
||
rm mydb.db
|
||
# 重启服务,会自动重新创建数据库
|
||
```
|
||
|
||
### 密钥错误
|
||
|
||
如果遇到密钥相关错误,可以重新生成(注意:这会丢失所有已签发的 License):
|
||
```bash
|
||
cd /path/to/licensing-cotton
|
||
rm -rf keys/
|
||
# 重启服务,会自动重新生成密钥对
|
||
```
|
||
|
||
⚠️ **警告**:删除密钥后,之前签发的所有 License 将无法验证!
|
||
|
||
## 安全建议
|
||
|
||
1. **修改默认密码**:首次登录后立即创建新管理员账号,删除或修改默认 admin 账号
|
||
2. **使用 HTTPS**:生产环境建议配置 Nginx 反向代理并使用 HTTPS
|
||
3. **定期备份**:备份 `mydb.db` 数据库文件和 `keys/` 密钥目录
|
||
4. **限制访问**:使用防火墙限制访问来源 IP
|
||
5. **保护密钥**:确保 `keys/` 目录权限为 700,私钥文件权限为 600
|
||
|
||
## Nginx 反向代理配置(可选)
|
||
|
||
如果想让服务运行在 80/443 端口并使用 HTTPS:
|
||
|
||
```nginx
|
||
server {
|
||
listen 80;
|
||
server_name your-domain.com;
|
||
|
||
location / {
|
||
proxy_pass http://127.0.0.1:8895;
|
||
proxy_set_header Host $host;
|
||
proxy_set_header X-Real-IP $remote_addr;
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
proxy_set_header X-Forwarded-Proto $scheme;
|
||
}
|
||
}
|
||
```
|
||
|
||
## 日志管理
|
||
|
||
### 查看实时日志
|
||
```bash
|
||
# 查看当前日志
|
||
tail -f logs/licensing-cotton.log
|
||
|
||
# 查看最近的错误
|
||
grep ERROR logs/licensing-cotton.log
|
||
|
||
# 查看特定设备的日志
|
||
grep "dev-001" logs/licensing-cotton.log
|
||
```
|
||
|
||
### 日志文件说明
|
||
|
||
日志会自动轮转和保留:
|
||
- `logs/licensing-cotton.log` - 当前日志文件
|
||
- `logs/licensing-cotton.log.1` - 上次轮转的日志
|
||
- `logs/licensing-cotton.log.2-5` - 更早的日志
|
||
|
||
当日志文件达到 **10MB** 时自动轮转,保留 **5个** 历史文件。
|
||
|
||
### 日志级别
|
||
|
||
系统当前使用的日志级别:
|
||
- **INFO** 及以上:系统启动、密钥加载、License 签发等
|
||
- **WARN**:可恢复的错误
|
||
- **ERROR**:严重错误
|
||
- **FATAL**:致命错误(程序终止)
|
||
|
||
## 性能监控
|
||
|
||
### 查看内存使用
|
||
```bash
|
||
ps aux | grep licensing-cotton
|
||
```
|
||
|
||
### 查看磁盘使用
|
||
```bash
|
||
du -sh /path/to/licensing-cotton
|
||
```
|
||
|
||
## 支持
|
||
|
||
如有问题,请查看:
|
||
- `README.md` - 完整文档
|
||
- 服务器日志文件(`logs/licensing-cotton.log`)
|
||
- Issue Tracker
|
||
|