01 Server Status Monitor 项目

1.1 常用项目对比

我们常有监控服务器运行状态的需求,常用的项目有 ward 、serverstatus 等。

如果你只有一个服务器,可以参考ward,如果你有不止一台,可以搭建serverstatus。

开源项目“Server Status”,一般简称为”sss”。不过,对比之下,我用了功能更强大的开源项目“Server Status Rust”。但是,我为了方便将“Server Status Rust”缩写为“ssr”。

因此,个人监控网站:https://ssr.xuanyangxu.com

1.2 Server端 & Client端 对比

所有的server status项目大同小异,都是基于两个应用端,一是 Server(一个足够),而是 Client(多个,部署在每台被监控的小鸡上)。

02 Server Status Rust 安装并配置

2.1 Server (服务端)

2.1.1 stat_server 安装

安装位置,我们将ServerStatusRust安装在 /opt/ServerStatus

1
2
3
4
mkdir -p /opt/ServerStatus && cd /opt/ServerStatus

# 下载脚本
wget --no-check-certificate -qO status.sh 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/status.sh'

安装server端,执行以下命令:

1
2
# 安装 服务端
bash status.sh -i -s

2.1.2 nginx 配置

将自己想要的主题放在对应的文件夹,然后配置nginx,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
server {
# ssl, domain 等其它 nginx 配置
server_name ssr.mydomain.com;

listen [::]:80;
listen 80;

# 反代 /report 请求
location = /report {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;

proxy_pass http://127.0.0.1:9393/report;
}
# 反代 json 数据请求
location = /json/stats.json {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;

proxy_pass http://127.0.0.1:9393/json/stats.json;
}
# v1.4.0后,同样需要反代 /detail, /map

location = /detail {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;

proxy_pass http://127.0.0.1:9393/detail;
}

location = /map {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;

proxy_pass http://127.0.0.1:9393/map;
}

# 其它 html,js,css 等,走本地文本
location / {
root /home/web/ServerStatus/web; # 你自己修改的主题目录
index index.html index.htm;
}
}

然后使用 certbot 获取证书

1
2
3
4
5
nginx -t
nginx -s reload

certbot --nginx
#生成之后可以更改端口,把443改为自己想要的端口

修改 config.toml 中的 http 的端口

1
2
# 修改为9393,和上面的nginx文件对应
http_addr = "0.0.0.0:9393"

2.1.3 配置 config.toml 文件

设置admin密码

1
2
admin_user = "admin"
admin_pass = "admin_p"

配置host列表,例子如下:

1
2
3
hosts = [
{name = "vps1_CC", password = "pp", alias = "vps1_CC", location = "us", type = "kvm", labels = "os=ubuntu;ndd=2025/12/22;spec=2C/1G/45G;"},
]

host_groups 可以不用配置

2.2 Client (客户端)

2.2.1 安装

1
2
# 安装 客户端
bash status.sh -i -c

2.2.2 配置客户端

对于流量统计工具,建议安装vnstat:

1
sudo apt install -y vnstat
1
2
3
4
5
6
# 修改 /etc/vnstat.conf
BandwidthDetection 0
MaxBandwidth 0

# 重启服务
systemctl restart vnstat

如果使用了 vnstat,那么需要编辑 /etc/systemd/system/stat_client.service 文件:

1
ExecStart=/path/of/stat_client -a "https://xxx/report" -u u1 -p p1 -n

如果不用 vnstat,那么在结尾就不需要 -n

配置client文件之后,重启服务:

1
2
systemctl daemon-reload
systemctl restart stat_client

2.3 备忘录: SSR便捷脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 下载脚本
wget --no-check-certificate -qO status.sh 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/status.sh'

# 安装 服务端
bash status.sh -i -s

# 安装 客户端
bash status.sh -i -c
# or
bash status.sh -i -c protocol://username:password@master:port
# eg:
bash status.sh -i -c grpc://h1:p1@127.0.0.1:9394
bash status.sh -i -c http://h1:p1@127.0.0.1:8080

# 更多用法:
❯ bash status.sh

help:
-i,--install 安装 Status
-i -s 安装 Server
-i -c 安装 Client
-i -c conf 自动安装 Client
-up,--upgrade 升级 Status
-up -s 升级 Server
-up -c 升级 Client
-up -a 升级 Server和Client
-un,--uninstall 卸载 Status
-un -s 卸载 Server
-un -c 卸载 Client
-un -a 卸载 Server and Client
-rc,--reconfig 更改 Status 配置
-rc 更改 Client 配置
-rc conf 自动更改 Client配置
-s,--server 管理 Status 运行状态
-s {status|start|stop|restart}
-c,--client 管理 Client 运行状态
-c {status|start|stop|restart}
-b,--bakup 备份 Status
-b -s 备份 Server
-b -c 备份 Client
-b -a 备份 Server and Client
-rs,--restore 恢复 Status
-rs -s 恢复 Server
-rs -c 恢复 Client
-rs -a 恢复 Server and Client
-h,--help 查看帮助

若无法访问 Github:
CN=true bash status.sh args