Rust版 ServerStatus 探针安装教程

本文重在 ServerStatus 的部署流程,介绍和更多使用请到:VPS 网络测试与长期监测 – 承飞之咎 (vfly2.com)

若无单独说明,按照文章代码块中命令的顺序,一条一条执行,即可实现目标。
适用系统:Debian 系发行版,包括 Ubuntu 和 Armbian,其他发行版按流程稍改命令一般也可。

若无单独说明,文章里的一键脚本仅适用于 amd64 系统


Github: zdz/ServerStatus-Rust: ✨ Rust 版 ServerStatus 探针、威力加强版
官方文档: 介绍 – Rust 版 ServerStatus 云探针 (ssr.rs)

前置准备

  1. 一个二级域名解析到作为服务端机子的ip上,比如 serverstatus.ahfei.blog 。既可用于web端界面访问,也可用于客户端联系服务端。
  2. VPS 的网络可以访问GitHub

一键安装脚本——客户端和服务端

这个脚本会安装客户端并用systemd管理,开机自启;另外,服务端可选安装。

  • 对于被监控的机子,只需要运行一次这个脚本即成功安装客户端,无须看文章其他部分。
  • 对于服务端机子,还需要看下文的服务端部分,不过也只是需要编辑服务端配置文件。

我的仓库: ahfei/Rust_ServerStatus: 对 https://github.com/zdz/ServerStatus-Rust 中的脚本自定义 – Rust_ServerStatus – Gitea for AhFei

下载脚本

wget --no-check-certificate -qO one-touch.sh 'https://git.ahfei.blog/ahfei/Rust_ServerStatus/raw/branch/main/one-touch.sh'

执行脚本–使用示例

sudo apt install unzip -y && \
sudo bash -ex one-touch.sh x86_64 "/home/skf/myserve/serverstatus" "123456" "ahfei-rn" "http://serverstatus.ahfei.blog:8080/report" 1000 1

参数:(根据实际情况自行修改)

  1. 机器架构:x86_64 或 aarch64
  2. 工作目录:"/home/skf/myserve/serverstatus" (软件所在位置)
  3. 密码: "123456"
  4. uid:"ahfei-rn"
  5. 服务端地址: "http://serverstatus.ahfei.blog:8080/report"
  6. 运行软件的用户,如 root 或 1000 ,用户组同用户
  7. 是否安装服务端,填任意字符即安装服务端,示例是安装。对于非服务端机子,删去最后的 1 即可

若之前执行过脚本,再次运行就会覆盖原来的,
不过需要重启客户端或服务端 systemctl restart stat_client

若服务端部署完毕,打开 http://<你的IP>:8080/ ,访问地图打开 http://<你的IP>:8080/map 。


国内机子不能访问GitHub

可以编辑脚本文件,加入代理

vim one-touch.sh

在脚本开头

export http_proxy="127.0.0.1:1080"
export https_proxy="127.0.0.1:1080"
export no_proxy=127.0.0.1,localhost,192.168.*

然后如前文,自定义参数,执行脚本

ServerStatus 服务端

官方文档:服务端说明 – Rust 版 ServerStatus 云探针 (ssr.rs)

先配置工作目录和防火墙(其实前面脚本已经创建了工作目录)

myserve="serverstatus"
sudo ufw allow 8080,9394/tcp comment $myserve && sudo ufw reload
mkdir -p ~/myserve/$myserve && cd ~/myserve/$myserve

服务端配置

进入工作目录,编辑服务端配置文件

cd /home/skf/myserve/serverstatus && sudo vim config.toml

配置文件示例

# 默认安装的路径
workspace = "/home/skf/myserve/serverstatus"

# 侦听地址, ipv6 使用 [::]:9394
grpc_addr = "0.0.0.0:9394"
http_addr = "0.0.0.0:8080"
# 默认30s无上报判定下线
offline_threshold = 30

# 管理员账号,不设置默认随机生成,用于查看 /detail, /map
admin_user = "admin_user"
admin_pass = "112233"

hosts = [
  {name = "ahfei-bwg", password = "123456", alias = "Bwg", location = "US", type = "KVM", labels = "os=debian;ndd=2024/1/15;spec=2C/2G/40G;"},
  {name = "ahfei-ht", password = "123456", alias = "HT", location = "TR", type = "VMware", labels = "os=debian;ndd=2024/3/28;spec=1C/1G/20G;"},
  {name = "ahfei-as", password = "123456", alias = "alongserver", location = "AS", type = "arm", labels = "os=arch;ndd=2029/11/25;spec=4C/2G/14G;", notify = false},
]
  • name 主机唯一标识,不可重复
  • password 客户端那里用的
  • alias 展示名
  • location 国家缩写即可,如 cn us 等, https://emojixd.com/group/flags ,所有国家见目录 web/static/flags
  • 自定义标签 labels = "os=debian;ndd=2022/11/25;spec=2C/4G/60G;"
    • os 标签可选,不填则使用上报数据(可用值 centos debian ubuntu alpine pi arch windows linux)
    • ndd(next due date) 下次续费时间
    • spec 为主机规格
  • notify = false 单独禁止单台机器的告警,一般针对网络差,频繁上下线
  • monthstart = 1 没启用vnstat时,表示月流量从每月哪天开始统计
  • disabled = true 单机禁用

更多配置见 Releases 中的 zip 中的 config.toml

这里用的是hosts 模式,还有 hosts_group 模式,具体请看官方文档

服务端运行

systemd 方式

执行脚本后,已经配置好 systemd ,具体的配置文件参照 one-touch.sh 脚本,或查看

sudo cat /etc/systemd/system/stat_server.service
sudo systemctl stop stat_server
sudo systemctl start stat_server
sudo systemctl restart stat_server

# 查看服务端运行状态
sudo systemctl status stat_server

手动

# help
./stat_server -h
# 手动运行
./stat_server -c config.toml
# 或
RUST_BACKTRACE=1 RUST_LOG=trace ./stat_server -c config.toml

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

ServerStatus 客户端

官方文档: 客户端说明 – Rust 版 ServerStatus 云探针 (ssr.rs)

前面脚本若成功执行,则客户端已安装好。官方文档是借助服务端快速安装,这里不涉及。

客户端运行

systemd 方式

执行脚本后,已经配置好 systemd ,具体的配置文件参照 one-touch.sh 脚本,或查看

sudo vim /etc/systemd/system/stat_client.service
sudo systemctl stop stat_client
sudo systemctl start stat_client
sudo systemctl restart stat_client

# 查看客户端运行状态
sudo systemctl status stat_client

? 手动方式

./stat_client -h
./stat_client -a "http://127.0.0.1:8080/report" -u h1 -p p1
# 或
./stat_client -a "grpc://127.0.0.1:9394" -u h1 -p p1
# 按组动态注册 (version >= v1.5.0)
# 不同的主机可以运行相同的命令注册到同一组
./stat_client -a "http://127.0.0.1:8080/report" -g g1 -p pp --alias "$(hostname)"
# 使用 -w 让主机加 10000 分,让主机排前
./stat_client -a "https://ssr.rs/report" -g g2 -p pp --alias "$(hostname)" -w 10000

# rust client 可用参数
./stat_client -h
OPTIONS:
    -6, --ipv6                   ipv6 only, default:false
    -a, --addr <ADDR>            [default: http://127.0.0.1:8080/report]
        --alias <ALIAS>          alias for host [default: unknown]
        --cm <CM_ADDR>           China Mobile probe addr [default: cm.tz.cloudcpp.com:80]
        --ct <CT_ADDR>           China Telecom probe addr [default: ct.tz.cloudcpp.com:80]
        --cu <CU_ADDR>           China Unicom probe addr [default: cu.tz.cloudcpp.com:80]
        --disable-extra          disable extra info report, default:false
        --disable-notify         disable notify, default:false
        --disable-ping           disable ping, default:false
        --disable-tupd           disable t/u/p/d, default:false
    -g, --gid <GID>              group id [default: ]
    -h, --help                   Print help information
        --ip-info                show ip info, default:false
        --ip-source <IP_SOURCE>  ip info source [env: SSR_IP_SOURCE=] [default: ip-api.com]
        --json                   use json protocol, default:false
        --location <LOCATION>    location [default: ]
    -n, --vnstat                 enable vnstat, default:false
        --vnstat-mr <VNSTAT_MR>  vnstat month rotate 1-28 [default: 1]
    -p, --pass <PASS>            password [default: p1]
    -t, --type <HOST_TYPE>       host type [default: ]
    -u, --user <USER>            username [default: h1]
    -V, --version                Print version information
    -w, --weight <WEIGHT>        weight for rank [default: 0]

# 一些参数说明
--ip-info       # 显示本机ip信息后立即退出,目前使用 ip-api.com 数据
--ip-source     # 指定 ip 信息源,ip-api.com / ip.sb / ipapi.co / myip.la
--disable-extra # 不上报系统信息和IP信息
--disable-ping  # 停用三网延时和丢包率探测
--disable-tupd  # 不上报 tcp/udp/进程数/线程数,减少CPU占用
-w, --weight    # 排序加分,微调让主机靠前显示,无强迫症可忽略
-g, --gid       # 动态注册的组id
--alias         # 动态注册模式下,指定主机的展示名字

# 总流量,网卡流量/网速统计
-i, --iface         # 非空时,只统计指定网口
-e, --exclude-iface # 排除指定网口,默认排除 "lo,docker,vnet,veth,vmbr,kube,br-"

Python版客户端

支持更多平台。

安装依赖

apt -y install python3-pip
python3 -m pip install psutil requests py-cpuinfo

下载Python文件

wget --no-check-certificate -qO stat_client.py 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/client/stat_client.py'

运行

python3 stat_client.py -h   # 帮助
python3 stat_client.py -a "http://127.0.0.1:8080/report" -u h1 -p p1

寡人之前用的是 cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ (github.com) 版的 ServerStatus,也不错,但相比Rust版本更繁复

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇