Files
lisglosips/docs/SERVER_B_BASELINE_RUNBOOK.md

163 lines
5.1 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.
# Server B 基础系统 Runbook
> 对应任务:S03
> 完成日期:2026-06-20
> 环境:本地开发 Server BTailscale IP 100.90.90.91
## 1. 当前基线
| 项目 | 状态 |
| --- | --- |
| OS | Ubuntu 24.04.4 LTS |
| 内核 | 6.17.0-35-generic |
| 时间同步 | chrony 4.5,阿里云 NTP 优先、腾讯云 NTP 备用 |
| 防火墙 | nftables 1.0.9,默认拒绝入站 |
| SSH 防护 | fail2ban 1.0.2sshd jail |
| 系统指标 | sysstat enabled |
| 数据盘 | 无独立盘;开发阶段 `/data` 位于根分区 |
| NFS | `/home/hector/share` 经 Tailscale automount |
完整变更前备份位于 B
`/var/backups/lisglosips-s03/20260620184404`
目录权限为 0700,包含变更前 tar、包清单、网络/防火墙快照、变更后配置和 SHA-256 清单。
## 2. 系统用户
| 用户 | 主组 | 用途 | 登录 |
| --- | --- | --- | --- |
| lisglosips | lisglosips | API 与通用 Worker | nologin |
| lisglo-recorder | lisglosips | 录音搬运 | nologin |
| lisglo-monitor | lisglosips | 自定义监控采集 | nologin |
不要依赖当前数字 UID/GID;部署脚本应按名称解析。
## 3. 目录权限
| 目录 | 所有者 | 模式/说明 |
| --- | --- | --- |
| `/data/mysql` | root:root | 0750S04 安装后交给 mysql |
| `/data/redis` | root:root | 0750S04 安装后交给 redis |
| `/data/recordings` | lisglo-recorder:lisglosips | 2750 |
| `/data/prometheus` | root:root | 0750S06 后调整 |
| `/data/grafana` | root:root | 0750S06 后调整 |
| `/data/homer` | root:root | 0750S06 后调整 |
| `/data/backups` | root:root | 0700 |
| `/opt/lisglosips` | root:lisglosips | 2750 |
| `/etc/lisglosips` | root:lisglosips | 0750 |
| `/var/log/lisglosips` | lisglosips:lisglosips | 2750 |
`/run/lisglosips``/run/lisglo-recorder``/run/lisglo-monitor``/etc/tmpfiles.d/lisglosips.conf` 在启动时重建。
## 4. NFS 自动挂载
`/etc/fstab`
```fstab
100.120.96.71:/mnt/share /home/hector/share nfs _netdev,nofail,noatime,x-systemd.automount,x-systemd.requires=tailscaled.service,x-systemd.after=tailscaled.service,x-systemd.mount-timeout=30s 0 0
```
验证:
```bash
systemctl status home-hector-share.automount
ls /home/hector/share
findmnt /home/hector/share
```
业务数据库和录音暂不使用该共享。迁移阿里云时重新设计独立数据盘,不复制本地 fstab。
## 5. 时间同步
配置文件:
- `/etc/chrony/sources.d/lisglosips.sources`
- Ubuntu 默认 pool 与 DHCP 动态 NTP 源已在 `chrony.conf` 中禁用。
当前网络会把部分公网 NTP 请求透明转发到不同响应地址,严格 conntrack 会拒绝该回复。因此选用能原地址响应的两个时间源,没有放宽 UDP 123 入站。
```bash
chronyc tracking
chronyc sources -v
timedatectl
```
验收标准:Stratum 非 0、Leap status 为 Normal、`System clock synchronized: yes`
## 6. 防火墙
配置文件:
- `/etc/nftables.conf`
- `/etc/nftables.d/lisglosips.nft`
- 仓库副本:`infra/server-b/s03/`
允许项:
| 来源 | 目标端口 | 用途 |
| --- | --- | --- |
| 100.91.249.119、100.98.167.119 | TCP `<SSH_ADMIN_PORT>`、443 | 两台现有管理设备;SSH 保留 Key 登录 |
| 100.90.90.90 | TCP 6379 | A 到 Redis |
| 100.90.90.90 | UDP 9060 | A 到 HEP |
| 任意来源 | UDP 41641 | Tailscale 外层直连 |
| 任意来源 | ICMP/ICMPv6 | 诊断与 IPv6 必需控制报文 |
除此之外的入站流量默认丢弃。MySQL 3306、Prometheus 9090、Grafana 3000 和应用内部端口不得开放。
修改规则时:
```bash
sudo nft -c -f /etc/nftables.conf
sudo systemctl restart nftables
sudo nft list table inet lisglosips_filter
```
修改 SSH 端口或防火墙时,必须保持一个已验证 SSH 会话,并在另一个新会话中用 Key 登录验证成功后才能关闭旧会话。
## 7. Fail2ban
`/etc/fail2ban/jail.d/lisglosips.local` 启用 sshd jail
- 10 分钟内失败 5 次;
- 封禁 1 小时;
- 使用 nftables multiport action
- 当前开发机 100.91.249.119 在 ignoreip 中。
```bash
sudo fail2ban-client -t
sudo fail2ban-client status sshd
```
## 8. 回滚
仅回滚防火墙:
```bash
sudo /var/backups/lisglosips-s03/20260620184404/rollback-firewall.sh
```
恢复 fstab
```bash
sudo cp -a /var/backups/lisglosips-s03/20260620184404/fstab.before-nfs-fix /etc/fstab
sudo systemctl daemon-reload
```
恢复 chrony 配置:
```bash
sudo cp -a /var/backups/lisglosips-s03/20260620184404/chrony.conf.before-lisglosips /etc/chrony/chrony.conf
sudo rm -f /etc/chrony/sources.d/lisglosips.sources
sudo systemctl restart chrony
```
系统包升级不建议逐包降级。若升级导致系统级故障,应从变更前虚拟机快照恢复;远端备份主要用于配置审计和局部恢复。
## 9. 已知事项
- SSH 由 `ssh.socket` 启动:socket enabled、service active`ssh.service` 显示 disabled 属正常状态。
- `findmnt --verify` 对 swapfile 给出常规文件警告,不是解析错误。
- 桌面、CUPS、Avahi、rpcbind 等服务仍存在,但已被主机防火墙隔离;精简桌面不属于 S03。
- 本地 `/data` 只是开发布局。迁移阿里云前必须创建独立数据盘并重新验收容量、IOPS、挂载和备份。