1072 字
5 分钟

ServerStatus-Rust Hands-on Deployment Guide on Debian 11

Originally the probe was deployed on Oracle Arm in Osaka, but the account got reclaimed, so I had to redeploy.

Result#

Preparation#

  • TG BOT API

  • TG CHAT ID

  • Vercel

  • VPS

  • Domain name (optional)

Deploying the Server#

Get your bot_token from @BotFather. The content pointed to by the red box is your token.

Get your chat_id from @Get My ID.

Server-side Deployment#

Terminal window
apt install wget curl unzip vim
新建目录并且进入
mkdir -p /opt/ServerStatus && cd /opt/ServerStatus
编辑.sh文件
vim server.sh

If you are deploying on ARM architecture, remember to modify the OS_ARCH variable as indicated in the comment. File content is as follows:

#!/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

Run the .sh file:

Terminal window
bash -ex server.sh

Edit the config.toml configuration file. You can edit it locally with reference to config.toml.

Terminal window
vim /opt/ServerStatus/config.toml

config.toml reference

Terminal window
# 管理员账号,不设置默认随机生成,用于查看 /detail, /map
jwt_secret = "" # 修改这个, 使用 openssl rand -base64 16 生成 secret 第8行
admin_user = "" 第9行
admin_pass = "" 第10行
hosts = 第22行
# 开关 true 打开
enabled = false 第60行
bot_token = "<tg bot token>" 第61行
chat_id = "<chat id>" 第62行

Test the configuration file:

Terminal window
# 测试配置文件是否有效
./stat_server -c config.toml -t
# 根据配置发送测试消息,验证通知是否生效
./stat_server -c config.toml --notify-test

Restart the server-side service:

Terminal window
systemctl restart stat_server

Test access (ip:8080).

Theme Configuration#

Theme configuration is implemented via frontend–backend separation, with the frontend deployed on Vercel.

First fork HinataKato/hotaru_theme_for_RustVersion: The frontend of ServerStatus-Hotaru based on Vue 3.0 (github.com) to your own account:

Import this repo into Vercel:

Just deploy directly; no need to modify anything. After deployment finishes, open the forked repository in GitHub and use Codespaces to modify the project.

Create vercel.json in the repo root directory. The file content is as follows. Replace http://xxx.com/ with your own domain name or IP:port. If you support HTTPS, remember to change all http:// to https://:

Terminal window
{
"routes": [
{
"src": "/json/stats.json",
"dest": "http://ip:端口/json/stats.json"
},
{
"src": "/detail",
"dest": "http://ip:端口/detail"
},
{
"src": "/map",
"dest": "http://ip:端口/map"
},
{
"src": "/i",
"dest": "http://ip:端口/i"
},
{
"src": "/report",
"dest": "http://ip:端口/report"
}
]
}

Commit and push the branch with any message you like.

Wait for it to redeploy and connect to the backend.

Add your own domain name:

Wait a bit for it to take effect and the deployment is complete.

Deploying the Client#

Create the directory:

Terminal window
cd
apt install wget curl unzip vim vnstat
mkdir -p /opt/ServerStatus && cd /opt/ServerStatus

Edit the .sh file:

Terminal window
vim client.sh

If you are deploying on ARM architecture, remember to modify the OS_ARCH variable as indicated in the comment. File content is as follows:

#!/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或你的域名

Run the .sh file:

Terminal window
bash -ex client.sh

If you need to use vnStat data, follow zdz/ServerStatus-Rust: ✨ Rust 版 ServerStatus 探针、威力加强版 (github.com) to install and configure vnStat:

Terminal window
# 在client端安装 vnstat
## Centos
sudo yum install epel-release -y
sudo yum install -y vnstat
## Ubuntu/Debian
sudo apt install -y vnstat
# 修改 /etc/vnstat.conf
# 一般来说只要修改BandwidthDetection和MaxBandwidth就够了
# BandwidthDetection 0
# MaxBandwidth 0
# 默认不是 eth0 网口的需要置空 Interface 来自动选择网口
# 没报错一般不需要改
# Interface ""
systemctl restart vnstat
# 确保 version >= 2.6
vnstat --version
# 测试查看月流量 (刚安装可能需等一小段时间来采集数据)
vnstat -m
vnstat --json m

Before editing the configuration file, you can first test whether your service works. (Here the domain is the one where you deployed on Vercel; the username and password correspond to the host.)

Terminal window
./stat_client -a https://probe.catcat.blog/report -u 用户名 -p 密码

If it works, you can edit the stat_client.service configuration file:

Terminal window
vim /etc/systemd/system/stat_client.service

Refer to the following and only modify the line ExecStart=/opt/ServerStatus/stat_client. If you’re using HTTP, remember to change https to http. If you don’t use vnStat, remove -n, i.e. only keep -a "https://probe.catcat.blog/report" -u 用户名 -p 密码.

Terminal window
[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 "https://probe.catcat.blog/report" -u 用户名 -p 密码 -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

After editing, reload the unit file and then restart the client service:

Terminal window
systemctl daemon-reload && systemctl restart stat_client

Check the service status with systemctl status stat_client.

ServerStatus-Rust Hands-on Deployment Guide on Debian 11
https://catcat.blog/en/serverstatus-rust-debian11.html
作者
猫猫博客
发布于
2023-09-04
许可协议
CC BY-NC-SA 4.0