项目地址:https://github.com/zdz/ServerStatus-Rust
项目演示:https://ssr.rs
完整文档:https://doc.ssr.rs
参考资料:https://catcat.blog/serverstatus-rust-debian11.html
准备资料:通过 @BotFather
获得 bot_token
,通过 @Get My ID
获得 chat_id
服务端部署
基础安装:
建立文件夹并进入
apt install wget curl unzip vim
新建目录并且进入
mkdir -p /opt/ServerStatus && cd /opt/ServerStatus
编辑.sh文件
vim server.sh
编辑 server.sh
,注意 OS_ARCH
变量的修改
#!/bin/bash
set -ex
WORKSPACE=/opt/ServerStatus
mkdir -p ${WORKSPACE}
cd ${WORKSPACE}
# 下载, arm 机器替换 x86_64 为 aarch64
OS_ARCH="x86_64"
latest_version=$(curl -m 10 -sL "https://api.github.com/repos/zdz/ServerStatus-Rust/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
wget --no-check-certificate -qO "server-${OS_ARCH}-unknown-linux-musl.zip" "https://github.com/zdz/ServerStatus-Rust/releases/download/${latest_version}/server-${OS_ARCH}-unknown-linux-musl.zip"
unzip -o "server-${OS_ARCH}-unknown-linux-musl.zip"
# systemd service
mv -v stat_server.service /etc/systemd/system/stat_server.service
systemctl daemon-reload
# 启动
systemctl start stat_server
# 状态查看
systemctl status stat_server
# 使用以下命令开机自启
systemctl enable stat_server
# https://fedoraproject.org/wiki/Systemd/zh-cn
# https://docs.fedoraproject.org/en-US/quick-docs/understanding-and-administering-systemd/index.html
运行 server.sh
文件
bash -ex server.sh
配置并重启:
修改 config.toml
配置文件
vim /opt/ServerStatus/config.toml
配置参考
# 管理员账号,不设置默认随机生成,用于查看 /detail, /map
jwt_secret = "" 第13行 # 修改这个, 使用 openssl rand -base64 16 生成 secret
admin_user = "" 第14行
admin_pass = "" 第15行
hosts = [ 第27行
# 开关 true 打开
enabled = false 第67行
bot_token = "<tg bot token>" 第68行
chat_id = "<chat id>" 第69行
测试配置文件
# 测试配置文件是否有效
./stat_server -c config.toml -t
# 根据配置发送测试消息,验证通知是否生效
./stat_server -c config.toml --notify-test
重启服务端服务
systemctl restart stat_server
客户端部署:
基础安装:
建立文件夹并进入
apt install wget curl unzip vim
新建目录并且进入
mkdir -p /opt/ServerStatus && cd /opt/ServerStatus
编辑.sh文件
vim client.sh
编辑 client.sh
,注意 OS_ARCH
变量的修改
#!/bin/bash
set -ex
WORKSPACE=/opt/ServerStatus
mkdir -p ${WORKSPACE}
cd ${WORKSPACE}
# 下载, arm 机器替换 x86_64 为 aarch64
OS_ARCH="x86_64"
latest_version=$(curl -m 10 -sL "https://api.github.com/repos/zdz/ServerStatus-Rust/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
wget --no-check-certificate -qO "client-${OS_ARCH}-unknown-linux-musl.zip" "https://github.com/zdz/ServerStatus-Rust/releases/download/${latest_version}/client-${OS_ARCH}-unknown-linux-musl.zip"
unzip -o "client-${OS_ARCH}-unknown-linux-musl.zip"
# systemd service
mv -v stat_client.service /etc/systemd/system/stat_client.service
systemctl daemon-reload
# 启动
systemctl start stat_client
# 状态查看
systemctl status stat_client
# 使用以下命令开机自启
systemctl enable stat_client
# 停止
# systemctl stop stat_client
# https://fedoraproject.org/wiki/Systemd/zh-cn
# https://docs.fedoraproject.org/en-US/quick-docs/understanding-and-administering-systemd/index.html
# 修改 /etc/systemd/system/stat_client.service 文件,将IP改为你服务器的IP或你的域名
运行 client.sh
文件
bash -ex client.sh
配置并重启:
测试服务端配置
./stat_client -a http://example.com/report -u 用户名 -p 密码
修改 stat_client.service
配置文件
vim /etc/systemd/system/stat_client.service
配置参考
[Unit]
Description=ServerStatus-Rust Client
After=network.target
[Service]
User=root
Group=root
Environment="RUST_BACKTRACE=1"
WorkingDirectory=/opt/ServerStatus
# EnvironmentFile=/opt/ServerStatus/.env
ExecStart=/opt/ServerStatus/stat_client -a "http://example.com/report" -u 用户名 -p 密码 -n # 如果是 HTTP 记得将 https 改成 http,不使用 vnstat 的话,请删除 -n
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/stat_client.service
# journalctl -u stat_client -f -n 100
重启客户端服务
systemctl daemon-reload && systemctl restart stat_client
评论区