Files

154 lines
6.3 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.
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# NAS 运维管理
这个目录是 NASSynology DS925+)的运维配置管理仓库,存放 docker-compose 配置、脚本和文档。
## 连接
```bash
ssh nas # ~/.ssh/config 已配置,HostName 192.168.3.200User wangjia
```
## 硬件概况
| 项目 | 信息 |
|------|------|
| 型号 | Synology DS925+ |
| 系统 | DSM (Linux 5.10.55+, x86_64) |
| 存储 | /volume17TB 总量 |
| IP | 192.168.3.200(静态,手动配置) |
## 仓库目录结构
```
docker/
├── forgejo/
│ ├── docker-compose.yml # Forgejo + act-runnertoken 通过 .env 注入)
│ ├── .env.example # 复制为 .env 填入真实 token
│ └── runner/
│ └── config.yaml # act-runner 配置
├── frp/
│ ├── docker-compose.yml # 历史遗留(实际部署走二进制+systemd,见 scripts/
│ └── frpc.toml.example # frpc 配置模板(token 占位,真值在 Bitwarden
└── derp/ # Tailscale 自建 DERP(可选,未部署)
```
> mihomo 透明代理 + dnsmasq 已于 2026-07-05 下线删除(配置见 git 历史 `docker/proxy/`)。
> ⚠️ 若 Windows192.168.3.88)网关/DNS 仍指向 NAS,需改回路由器,否则断网。
NAS 上实际路径:`/volume1/docker/<服务名>/`,与仓库 `docker/` 目录一一对应。
## Docker 服务
### 权限说明
`wangjia` 用户不在 docker 组,**无法直接运行 `docker` 命令**。容器管理需通过:
- DSM → Container Manager UI
- 或 root 权限(DSM 终端)
### ForgejoGit 服务)
- **`git.51yanmei.com` 当前仅局域网可达**:DNS 记录指向 `192.168.3.200`(内网私有 IP、未走 CF 代理),公网打不开
- **局域网直连**`http://192.168.3.200:3000/`
- **公网访问**:经 Tailscale`http://100.95.151.13:3000`(或 `https://ds925.tail6e8719.ts.net`),见 `docs/public-access.md`
- **SSH Clone(局域网)**`ssh://git@192.168.3.200:2222/`
- **配置方式**:优先通过 docker-compose.yml 的环境变量(`GITEA__section__key`)管理,避免直接改 app.ini
- **app.ini 路径**`/volume1/docker/forgejo/data/gitea/conf/app.ini`(属于 uid=1000wangjia 只读,需 root 修改)
- **数据库**SQLite`/volume1/docker/forgejo/data/gitea/gitea.db`
- **act-runner**CI/CD runner`forgejo-act-runner`),挂载 `/var/run/docker.sock` 可运行 Docker 任务
```bash
# 查看 Forgejo 日志
ssh nas "tail -f /volume1/docker/forgejo/data/gitea/log/gitea.log"
```
### frp 内网穿透(frpcsystemd 常驻)
在外经 `nas/git/win.yanmeiai.com` 访问家里(frps 锚点在 ali 北京,方案见 `docs/remote-access-frp.html`):
- **frpc 二进制** `/usr/local/bin/frpc`,配置 `/volume1/docker/frp/frpc.toml`root:600,含 token 不入 git,模板见 `docker/frp/frpc.toml.example`
- systemd 服务 `frpc.service`Restart=always + MemoryLimit=64M);转发:git SSH/Web、DSM 5001、NAS SSH→10022、Windows RDP 3389 / SSH→10023
- 一键部署/重装:Mac 上跑 `bash scripts/setup-frp-remote.sh`(自动从 Bitwarden 取 token、代下载二进制、经 ssh 推送执行)
```bash
# 查看 frpc 状态与日志(NAS 上)
sudo systemctl status frpc
sudo journalctl -u frpc -n 20 --no-pager
```
### jiu-db 自动备份
每天 02:00UTC+8)自动备份 jiu 项目 PostgreSQL,存至 `/volume1/docker/backups/jiu-db/`,格式 `jiu_db_YYYYMMDD_HHmmss.sql.gz`,保留约 16 天。
```bash
ssh nas "ls -lh /volume1/docker/backups/jiu-db/"
```
## 端口清单
| 端口 | 服务 |
|------|------|
| 22 | SSH |
| 80 / 443 | Synology nginx(反代 + DSM 重定向) |
| 2222 | Forgejo SSH |
| 3000 | Forgejo HTTP |
| 5000 / 5001 | DSM Web UIHTTP / HTTPS |
| 5432 | PostgreSQLlocalhost only |
| 6690 | Synology Drive |
| 41641/udp | Tailscale WireGuard |
| 445 / 139 | SMB 文件共享 |
(frpc 无入站监听——只出站长连接到 ali:7000)
## Synology 反向代理
通过 DSM 内置 nginx 管理:**Control Panel → Login Portal → Advanced → 反向代理服务器**
当前规则:
| 来源 | 目的地 |
|------|--------|
| `http://git.nas.local:80` | `http://localhost:3000` |
## 常用运维
```bash
# 磁盘使用
ssh nas "df -h /volume1"
# 查看路由规则(透明代理策略路由)
ssh nas "ip rule list"
ssh nas "ip route show table 2022 | head -5"
# 查看网络接口(Meta = mihomo TUN
ssh nas "ip addr show Meta"
```
## 公网访问(Tailscale,已上线)
NAS 通过 **TailscaleWireGuard 网格 VPN** 对外提供 Gitea 与 Synology Photos 访问:
零公网暴露、无文件大小限制、不泄露家庭公网 IP。部署与踩坑详见 `docs/public-access.md`
Cloudflare Tunnel 因免费版 100MB 上限不适合 Photos 大文件,故选 Tailscale。)
- **节点**`ds925`Tailscale IP `100.95.151.13`MagicDNS `ds925.tail6e8719.ts.net`
- **身份**Google SSO`wang880812@gmail.com`);Google 仅登录/进后台时需要,日常用不需要
- **CLI 路径**`/var/packages/Tailscale/target/bin/tailscale`(已设 `--operator=wangjia`,免 sudo
- **关键依赖**mihomo 的 `fake-ip-filter` 必须含 `+.tailscale.com` 等(见 mihomo 配置注释),
否则 fake-ip 劫持会导致 `tailscale up` 卡住。修复脚本:`scripts/fix-mihomo-tailscale.sh`
```bash
ssh nas "/var/packages/Tailscale/target/bin/tailscale status" # 查看节点与对端连接
```
## TODO
- [x] NAS 安装 Tailscale 套件并登录,Gitea/Photos 公网访问已验证(含 >100MB 上传)
- [x] 后台对 `ds925` 关闭 key expiry(已确认 KeyExpiry=None,不会再因密钥过期掉线)
- [ ] (可选)`tailscale serve` 给 Gitea 套 HTTPS(解决 Arc 等强制 HTTPS 浏览器超时)
- [ ] (可选)新加坡 EC2 自建 DERP 中继 / 把 Tailscale UDP 排除出 mihomo,从香港中继提速到 P2P 直连(`docker/derp/`
- [ ] wangjia 用户加入 docker 组,方便 SSH 管理容器
- [ ] dnsmasq 启用(全局 DHCP 分发,让其他设备也自动走透明代理)
- [ ] Forgejo app.ini 的 DOMAIN/SSH_DOMAIN/ROOT_URL 改为 `git.51yanmei.com`(需 rootdocker-compose 环境变量已覆盖,改 app.ini 仅为保持一致)