目的:在一台监控VPS上实时查看并告警位于马来西亚的 SCUM 游戏服务器(以下简称游戏服)CPU、内存、磁盘与网络负载。 前提:你有(A)游戏服的 root/SSH 权限,(B)一台监控用VPS(Ubuntu/Debian 推荐),二者能互相连通。 准备事项:记录游戏服公网IP、SSH端口;在两台机器上备用 sudo 权限;开放 node_exporter(9100)、netdata(19999)等监控端口(仅允许监控VPS访问,建议用防火墙限制)。
步骤:1) 登录游戏服:ssh root@GAME_IP -p PORT。
2) 下载并安装 node_exporter:
- wget https://github.com/prometheus/node_exporter/releases/latest/download/node_exporter-*-linux-amd64.tar.gz
- tar xzf node_exporter-*-linux-amd64.tar.gz && cd node_exporter-*-linux-amd64
- sudo mv node_exporter /usr/local/bin/
3) 建立用户与 systemd 服务:
- sudo useradd --no-create-home --shell /bin/false nodeusr
- 创建 /etc/systemd/system/node_exporter.service 内容(可复制标准配置),然后 sudo systemctl daemon-reload && sudo systemctl enable --now node_exporter。
4) 验证:curl http://localhost:9100/metrics 或在监控VPS上 curl http://GAME_IP:9100/metrics(确保防火墙允许)。
用途:netdata 提供实时图表,安装简单。 安装:在游戏服执行:bash <(curl -Ss https://my-netdata.io/kickstart.sh) 配置:安装后修改 /etc/netdata/netdata.conf,将 bind to = 127.0.0.1 或指定允许监控VPS的IP;若需远程访问,配置防火墙仅放行监控VPS IP。 查看:访问 http://GAME_IP:19999 即可看到实时CPU/IO/网络/进程等详细图表。
步骤:1) 下载 Prometheus:wget https://github.com/prometheus/prometheus/releases/latest/download/prometheus-*-linux-amd64.tar.gz,解压并移动二进制。
2) 配置 /etc/prometheus/prometheus.yml,添加抓取目标:
- job_name: 'scum-malaysia'
static_configs:
- targets: ['GAME_IP:9100']
3) 建立 systemd 服务文件 promethes.service,启动并设置开机自启:sudo systemctl enable --now prometheus。
4) 验证:访问 http://MONITOR_VPS_IP:9090,使用 Prometheus 的 Targets 页面确认 scum-malaysia 的状态为 UP。
安装:按 Grafana 官方步骤添加 apt 源并安装 grafana-server,然后 sudo systemctl enable --now grafana-server。 配置数据源:在 Grafana UI -> Configuration -> Data Sources -> 添加 Prometheus,填入 http://localhost:9090。 导入仪表盘:在 Grafana 仪表盘库搜索 Node Exporter Full 或 Linux server dashboard,导入并选择你的 Prometheus 数据源,调整变量(instance 设为 GAME_IP:9100)。 效果:你将实时看到 CPU/Load、内存、磁盘 I/O、网络吞吐与进程监控(可关注 scum 进程名)。
简单告警流程(Prometheus + Alertmanager):1) 在 Prometheus 增加 alerting.rules 文件示例: - alert: HighCpuSCUM expr: avg by (instance) (rate(node_cpu_seconds_total{mode!="idle"}[1m])) > 0.8 for: 2m labels: { severity: "critical" } annotations: { summary: "SCUM 服务器 CPU 偏高", description: "{{ $labels.instance }} CPU >80% 超过2分钟" } 2) 安装并配置 Alertmanager,配置接收器(邮件、Webhook、Telegram)。 Grafana 也支持基于面板创建告警并发送到 Slack/Telegram/Email。建议测试告警策略并设置抑制规则避免误报警。
答:原则上只允许监控VPS访问游戏服的 node_exporter/netdata 端口。方法包括:在游戏服上使用 UFW/iptables 限制来源 IP(ALLOW 监控VPS IP,DROP 其他);或者通过 SSH 隧道(ssh -fNT -L 9100:localhost:9100 user@GAME_IP)把采集流量加密并只在监控VPS本地访问;若使用云防火墙,也在控制台限定来源 IP。
答:在 node_exporter/Prometheus 中可以写进程指标规则(如检查 scum 进程数 >0),当检测到 scum 进程不存在触发告警后,可以结合一个自动化脚本(通过 Ansible 或在监控VPS上触发 SSH 命令)来重启服务。示例:在监控VPS上用 webhook 触发脚本执行 ssh root@GAME_IP 'systemctl restart scum.service',并在告警触发条件和自动重启之间加入人工确认或速率限制以防误操作。
答:可以。安装 netdata 或 glances 在游戏服上直接查看实时负载:glances 安装 apt install glances,运行 glances -w 可通过 web 端口查看;netdata 更直观但注意防火墙与安全。若只有一台服务器且流量不大,此法最省资源,但不利于分离监控/业务,也不便做跨机报警与历史长期存储。