前置条件
| 要求 | 最低版本 | 推荐版本 |
|---|---|---|
| Linux 内核 | 5.10 | 6.1+ |
| Rust 工具链 | 1.75 | 最新稳定版 |
| Redis(可选) | 6.0 | 7.x |
构建
以 release 模式构建arc-gateway:
./target/release/arc-gateway
Systemd(裸机或虚机)
安装
以 root 身份执行安装脚本:- 复制
./target/release/arc-gateway到/usr/local/bin/arc-gateway - 创建
/etc/arc/ - 复制
arc.example.json到/etc/arc/arc.json - 安装
deploy/arc-gateway.service到/etc/systemd/system/ - 执行
systemctl daemon-reload && systemctl enable arc-gateway
服务单元参数
服务单元路径:/etc/systemd/system/arc-gateway.service。
| 指令 | 值 | 作用 |
|---|---|---|
ExecStart | /usr/local/bin/arc-gateway --config /etc/arc/arc.json | 启动主进程 |
ExecReload | /bin/kill -HUP $MAINPID | 触发热更新 |
Restart | on-failure | 异常退出自动拉起 |
RestartSec | 5s | 重启间隔 |
TimeoutStopSec | 35s | SIGKILL 前的优雅退出窗口 |
WatchdogSec | 60s | systemd watchdog 周期 |
LimitNOFILE | 1048576 | 最大文件描述符数 |
LimitNPROC | 65536 | 最大进程数 |
NoNewPrivileges=yesPrivateTmp=yesProtectSystem=strictProtectHome=yesProtectKernelTunables=yesProtectControlGroups=yesRestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
热更新
修改/etc/arc/arc.json 后执行:
常用命令
Kubernetes
Kubernetes 清单都在deploy/kubernetes/ 下,按顺序应用:
创建的资源
| 资源 | 说明 |
|---|---|
| Namespace | arc-gateway |
| ConfigMap | arc-gateway-config,包含 arc.toml |
| Secret | arc-gateway-secret,包含 auth-token |
| Deployment | replicas=2,滚动更新 |
| Service(ClusterIP) | 暴露 8080、8443、9090 |
| Service(NodePort) | NodePort 30080(HTTP)、30443(HTTPS) |
| HPA | 基于 CPU 的自动扩缩容 |
应用前:先设置认证 token
在部署前,Secret 必须写入真实 token:control_plane.auth_token 与该值一致。
建议覆盖的 ConfigMap 关键字段
| 键 | 默认值 | 说明 |
|---|---|---|
workers | 0(自动) | 建议按 Pod CPU limit 设置,性能更可预测 |
control_plane.auth_token | __ARC_TOKEN__ | 必须替换 |
io_uring.sqpoll | false | 裸机场景可开启 |
upstreams[0].addr | 127.0.0.1:18080 | 指向你的后端服务 |
Deployment 规格
| 字段 | 值 |
|---|---|
replicas | 2 |
strategy | RollingUpdate,maxSurge=1,maxUnavailable=0 |
terminationGracePeriodSeconds | 35 |
| HTTP 端口 | 8080 |
| HTTPS 端口 | 8443 |
| 管理端口 | 9090 |
| CPU request/limit | 500m / 2000m |
| 内存 request/limit | 256Mi / 1Gi |
GET /healthz(9090 端口),initialDelaySeconds=5,periodSeconds=10
就绪探针: GET /healthz(9090 端口),initialDelaySeconds=3,periodSeconds=5
优雅下线
preStop hook 会先执行 sleep 5,给负载均衡器留出摘流时间,再由容器接收 SIGTERM。terminationGracePeriodSeconds=35 与该下线窗口对齐。
Kubernetes 中的 XDP/eBPF
XDP 需要NET_ADMIN 和 SYS_ADMIN capability,并要求 privileged: true。默认清单里是关闭状态(注释掉的 YAML),多数托管 Kubernetes 平台也不支持这类能力。
启动流程(arc-daemon)
执行arc-gateway --config arc.yaml 后的启动序列如下:
node.workers。如果设置为 0,会使用 std::thread::available_parallelism() 自动识别。
生产上线检查清单
上线前建议逐项确认:- 将
node.workers设为0(自动)或按进程可用 CPU 核数固定 - 按预期并发连接量设置
max_connections - 在 systemd 单元里设置
LimitNOFILE(默认1048576) - 在监听器启用
SO_REUSEPORT,让 Arc 在多 worker 间无锁分摊连接 - 按峰值并发请求调整上游
pool.max_idle - 如果 control plane 对外可达,务必设置高强度随机
control_plane.auth_token - 将指标服务绑定到回环地址(
observability.metrics_bind: "127.0.0.1:9090")或用防火墙保护 9090;该端点没有内建鉴权 - 配置日志轮转(
logging.output.rotation.max_size与max_files) - 在 Prometheus 加入
<host>:9090/metrics采集目标 - 验证热更新:
kill -HUP <pid>后确认/metrics中arc_config_reload_total递增
故障排查
systemd: Failed to start arc-gateway.service
systemd: Failed to start arc-gateway.service
先看
journalctl -xe -u arc-gateway。最常见原因是 ExecStart 指向的二进制不存在,或配置文件路径写错。可用 arc-gateway --config /etc/arc/arc.json --check(如果版本支持 --check)辅助验证,或直接检查启动日志。Arc 重启循环并提示 io_uring: Operation not supported
Arc 重启循环并提示 io_uring: Operation not supported
当前内核可能不支持请求的 io_uring 特性。可先关闭 SQPOLL(
io_uring.sqpoll: false),并适当调小 uring_entries。最低要求内核为 Linux 5.10。Kubernetes Pod 卡在 CrashLoopBackOff
Kubernetes Pod 卡在 CrashLoopBackOff
执行
kubectl logs -n arc-system <pod> 排查。常见原因包括:arc-gateway-secret 不存在或缺少 auth-token;ConfigMap 的 arc.toml 指向了启动阶段不可达的上游地址;资源上限过低,需要提高 resources.limits.memory。bind: address already in use
bind: address already in use
说明端口被其他进程占用。可用
ss -tlnp | grep 8080 检查。如果是 Pod 重启场景,可能旧 Pod 尚未完全退出,可适当增大 terminationGracePeriodSeconds。Hot reload(SIGHUP)不生效
Hot reload(SIGHUP)不生效
node.workers、监听器 bind 地址和 io_uring.uring_entries 等字段必须完整重启才能生效,其他字段才可在线生效。可检查 arc_config_reload_total 确认是否触发了热更新。
