原创文章,转载请注明出处
https://qiedd.com/

前言

Server Status 是一个轻量化的探针,对服务器的占用低。
虽然有手动部署的教程,但是并没有讲太多,这里我的演示环境为 ArchLinux + Caddy

一、服务端安装

0. Arch Linux
# 安装所需软件包
pacman -S base-devel git linux-headers jq python python-pip --needed

# 下载serverstatus
git clone https://github.com/cppla/ServerStatus

# 编译生成服务端
cd ServerStatus/server
make

# 运行看看有没有报错
./sergate

# 编辑配置文件,往下加即可,注意格式
vim config.json

# 检查配置文件是否有报错
jq . config.json
config.json
1. 配置web
# 回到根目录
cd

# 创建存放web的文件夹
mkdir -p /www/serverstatus

# 复制网站到
cp -r ServerStatus/web/* /www/serverstatus

# 修改权限给caddy
chown -R caddy /www/serverstatus
chgrp -R caddy /www/serverstatus

# 测试运行
/root/ServerStatus/server/sergate --config=/root/ServerStatus/server/config.json --web-dir=/www/serverstatus

# 修改/etc/caddy/Caddyfile
vim /etc/caddy/Caddyfile

# 在/etc/caddy/conf中添加文件
vim /etc/caddy/conf/serverstatus.conf
/etc/caddy/Caddyfile

删除之前的配置,开启 HTTP2 和 HTTP3 的支持

{
        servers :443 {
                protocol {
                        allow_h2c
                        experimental_http3
                }
        }
        servers :80 {
                protocol {
                        allow_h2c
                        experimental_http3
                }
        }
}
import /etc/caddy/conf.d/*
/etc/caddy/conf/serverstatus.conf
你的域名 {
        log {
                output file /var/log/caddy/serverstatus.log
        }
        root * /www/serverstatus
        file_server
        encode zstd gzip
}
2. 将服务端加入Systemd
# 创建配置文件
vim /usr/lib/systemd/system/sergate.service

# 重新应用systemd
systemctl daemon-reload

# 启动
systemctl start sergate

# 开机启动
systemctl enable sergate

# 查看状态
systemctl status sergate
/usr/lib/systemd/system/sergate.service
[Unit]
Description=ServerStatus_Server
After=network.target

[Service]
Type=simple
WorkingDirectory=/root/ServerStatus/server
ExecStart=/root/ServerStatus/server/sergate --config=config.json --web-dir=/www/serverstatus
Restart=on-abnormal
RestartSec=5s
KillMode=mixed

[Install]
WantedBy=multi-user.target
3. 开放防火墙(如果你有)
# ufw
ufw allow 35601

# firewalld
firewall-cmd --zone=public --add-port=35601/tcp --permanent  、
firewall-cmd --reload  

二、客户端

# 下载源码
git clone https://github.com/cppla/ServerStatus

# 编辑配置文件
vim ServerStatus/clients/client-linux.py

# SERVER = "填服务端的域名和IP都行"
# USER = "服务端设置的uesrname"
# PASSWORD = "服务端设置的密码"
# CU = ""
# CT = ""
# CM = ""

# 测试运行
python ServerStatus/clients/client-linux.py

# 写进systemd
vim /usr/lib/systemd/system/serverstatus.service

# 保存
systemctl daemon-reload
systemctl start serverstatus
systemctl enable serverstatus
/usr/lib/systemd/system/serverstatus.service
[Unit]
Description=ServerStatus
After=network.target

[Service]
Type=simple
WorkingDirectory=/root/ServerStatus/clients
ExecStart=python /root/ServerStatus/clients/client-linux.py
Restart=on-abnormal
RestartSec=5s
KillMode=mixed

[Install]
WantedBy=multi-user.target

CU, CT, CM 这些地址你可以去去找你当地的电信营业厅,比如说 https://www.189.cn

分类: Linux

0 条评论

发表评论

Avatar placeholder

您的电子邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据