# skills/server-ops.hdlp · 服务器操作技能包 > HLDP://maomao/skills/server-ops > 类型: 技能包 > 管辖: 仅 175.178.176.145 --- ## @trigger 你需要操作毛毛的服务器——查看状态、重启服务、部署代码。 ## @emergence 毛毛的服务器只有一台: 175.178.176.145。广州七区。4核4G。Ubuntu 24.04。 你有三种方式操作它。从最简单到最复杂。 ## 方式一: Gatekeeper API (推荐·最安全) Gatekeeper 运行在端口 3910。它接受 POST 请求,执行命令并返回结果。 ``` 基本格式: curl -X POST http://175.178.176.145:3910/exec \ -H "Content-Type: application/json" \ -d '{"cmd":"你的命令"}' 返回格式: {"ok":true/false, "stdout":"...", "stderr":"..."} ``` ### 常用操作 ```bash # 检查所有服务状态 curl -X POST http://175.178.176.145:3910/exec \ -H "Content-Type: application/json" \ -d '{"cmd":"systemctl status gitea --no-pager; echo ===; systemctl status nginx --no-pager; echo ===; systemctl status guanghu-engine --no-pager"}' # 重启 Gitea curl -X POST http://175.178.176.145:3910/exec \ -H "Content-Type: application/json" \ -d '{"cmd":"systemctl restart gitea; sleep 2; systemctl status gitea --no-pager"}' # 查看磁盘 curl -X POST http://175.178.176.145:3910/exec \ -H "Content-Type: application/json" \ -d '{"cmd":"df -h; echo ===; free -h"}' # 查看日志 curl -X POST http://175.178.176.145:3910/exec \ -H "Content-Type: application/json" \ -d '{"cmd":"journalctl -u guanghu-engine -n 50 --no-pager"}' # 查看端口 curl -X POST http://175.178.176.145:3910/exec \ -H "Content-Type: application/json" \ -d '{"cmd":"ss -tlnp | grep -E \"3001|80|3910\""}' ``` ### 部署文件到服务器 ```bash # 从代码仓库读取文件,写入服务器 curl -X POST http://175.178.176.145:3910/exec \ -H "Content-Type: application/json" \ -d '{"cmd":"cat > /opt/guanghu/test.txt << '\''EOF'\''\n文件内容\nEOF"}' ``` ## 方式二: SSH 直连 ``` 服务器: 175.178.176.145 用户: root 端口: 22 毛毛本地电脑上: ssh root@175.178.176.145 ``` 适用于需要交互式操作、长命令、文件编辑等场景。 如果你在毛毛本地电脑上运行,优先用 SSH。 ## 方式三: Gitea API (仓库管理) Gitea 在端口 3001,提供 REST API。 ``` API Token: 762dafa0cd3f133a35690521dc70804357911db7 Token 名: gatekeeper 用户: maomao 基础请求: curl -H "Authorization: token 762dafa0cd3f133a35690521dc70804357911db7" \ http://localhost:3001/api/v1/... 创建文件: POST /api/v1/repos/maomao/{repo}/contents/{path} 读取文件: GET /api/v1/repos/maomao/{repo}/contents/{path} ``` ## 服务器目录结构 ``` 175.178.176.145: ├── /opt/guanghu/ # 光湖主目录 │ └── gatekeeper.js # Gatekeeper v2.1 脚本 ├── /opt/gitea/ # Gitea 安装目录 │ ├── custom/conf/app.ini # Gitea 配置 │ └── data/ │ └── repos/ # Git 仓库存储 ├── /var/log/guanghu/ # 日志目录 │ └── engine.log # Gatekeeper 日志 ├── /etc/systemd/system/ │ ├── gitea.service # Gitea systemd 服务 │ └── guanghu-engine.service # Gatekeeper systemd 服务 └── /etc/nginx/ # Nginx 配置 ``` ## 端口清单 ``` 22 → SSH 80 → Nginx (毛毛首页) 3001 → Gitea (代码仓库) 3910 → Gatekeeper (执行引擎) ``` ## 防火墙 ``` sudo ufw status 开放端口: 22, 80, 3910 ``` ## @lock ⊢ 你只管 175.178.176.145 这一台服务器。不要碰冰朔的六台服务器。 ⊢ 操作前先 CHECK_ 当前状态。不要没看就改。 ⊢ 改了之后验证。验证之后再标记完成。 ⊢ 服务器操作不要做不可逆的事 (rm -rf /, 清数据库)。先备份。 ## @why 操作服务器不是你主要的工作。但有时候需要——查看日志、重启服务、部署新版本。 用 Gatekeeper 最安全——不用记密码、不用配 SSH、从任何地方都能调用。 --- > 铸渊 ICE-GL-ZY001 · 技能包 v1.0