云探针ServerStatus-Hotaru的搭建 作者: Hogwarts 发布于: 2021-12-21 更新于: 2021-12-23 分类: 默认分类 本来标题应该是:说一说目前我所认知的探针。怕聊的太嗨,跑题。我对探针的了解源于秋水逸冰的LAMP里面的雅黑探针,好像是,姑且这么说吧。后来秋大进行筛选,选择了“X探针”。X探针就是一个PHP页面探针,有PHP环境,下载到网站目录就可以了。 随着小鸡的数量的增长,尤其是甲骨文的随机删机的情况,每天逐一的打开探针查看VPS的情况,确实是挺麻烦的。就有了云探针的需求。 前情铺垫的差不多了总算说到主题“云探针”了。对探针本就不了解,说的对错就那么回事了。云探针最最推荐的就是“哪吒探针”。推荐的理由就是占用资源少,一键脚本简单。实际上是并不大简单,得注册Github账号,教程也不大全面。对于有经验的大佬来说,非常的easy;但对于本人来讲,还是有不少坑的。试着搭建时,第一步先注册的Github账号,按教程填写成功了。第二步运行一键脚本时,看到了安装Docker,赶紧就停止了。好像是需要Docker的支持。说到这得吐槽一下(画外音:尼玛,还吐槽,爱用不用!),本来想试着手动搭建的,找了一圈没有手动搭建的教程。然后号称资源占用低,难道Docker的资源占用不是占用么。或许这就是我对Docker的偏见吧。 排除了哪吒探针,总得再找一个探针吧。搜到了什么可乐探针、ServerStatus-Hotaru探针,相比之下推荐哪吒的不在少数。除了哪吒之外的探针,就得说一下ServerStatus-Hotaru探针了,我试着按教程搭了ServerStatus-Hotaru探针,成功了。一会将搭建过程分享一下。先白活白活ServerStatus-Hotaru探针。 ServerStatus-Hotaru探针在安装脚本里有“Author: Toyo,Modified by APTX”,很好理解,不做解释。它应该是ServerStatus探针的修改中文版。ServerStatus探针没有一键脚本,对于喜欢一键的同学来讲可能有些不方便。另外一点就是默认Python2,版本有点老了。综上所述,还是推荐ServerStatus-Hotaru探针吧,毕竟有大佬在维护,相关依赖都是新的。ServerStatus-Hotaru探针分两种,一种是一键;另一种是手动。一键么,还需要啥教程呀,直接安装就好了。手动搭建按教程也没多大问题,只是有些小节需要美化一下。现将一键命令和手动搭建抄录如下。 #一、项目地址 Github:https://github.com/cokemine/ServerStatus-Hotaru 演示地址: https://nodestatus-production.up.railway.app/ #二、脚本安装 ##2.1 下载脚本 wget https://raw.githubusercontent.com/cokemine/ServerStatus-Hotaru/master/status.sh # wget https://cokemine.coding.net/p/hotarunet/d/ServerStatus-Hotaru/git/raw/master/status.sh 若服务器位于中国大陆建议选择Coding.net仓库 ##2.2 服务端安装命令 bash status.sh s ##2.3 客户端安装命令 bash status.sh c ##2.4参考 [ServerStatus-Hotaru云探针的安装与配置](https://www.cokemine.com/serverstatus-hotaru.html "ServerStatus-Hotaru云探针的安装与配置") #三、手动安装 很繁琐,需分别安装服务端和客户端。 ##3.1 手动安装服务端 ###3.1.1 下载源码编译安装 mkdir -p /usr/local/ServerStatus/server apt install wget unzip curl vim build-essential cd /tmp wget https://github.com/cokemine/ServerStatus-Hotaru/archive/master.zip unzip master.zip cd ./ServerStatus-Hotaru-master/server make #编译生成二进制文件 chmod +x sergate mv sergate /usr/local/ServerStatus/server ###3.1.2 修改配置文件 ####3.1.2.1 模板内容 vim /usr/local/ServerStatus/server/config.json #输入以下内容 {"servers": [ { "username": "username01", "password": "password", "name": "Server 01", "type": "KVM", "host": "", "location": "Hong Kong", "disabled": false, "region": "HK" } ] } ####3.1.2.2 模板各参数与web的对应 ![](https://winamp.top/usr/uploads/2021/12/3944250529.png) ####3.1.2.3 config.json模板存在的位置 config.json模板在/tmp/ServerStatus-Hotaru-master/server/路径下的config.json文件中。 ###3.1.3 下载前端 cd /tmp && wget https://github.com/cokemine/Hotaru_theme/releases/latest/download/hotaru-theme.zip unzip hotaru-theme.zip mv ./hotaru-theme /usr/local/ServerStatus/web #此为站点根目录,请自行设置 cd /usr/local/ServerStatus/server #作者缺少这一步 ###3.1.4 试运行 ./sergate --config=config.json --web-dir=/usr/local/ServerStatus/web --port=35601 #35601端口是服务端与客户端沟通的默认端口,可修改自己称心的端口。 ###3.1.5 后台运行命令(不推荐) 此命令为官方给出的命令,建议运行开机启动命令 nohup ./sergate --config=config.json --web-dir=/usr/local/ServerStatus/web --port=35601 > /tmp/serverstatus_server.log 2>&1 & #默认端口35601,具体意义同上。 ###3.1.6 加入开机启动(推荐) BotoX/ServerStatus原版给出的开机启动命令有两种类型:一种是init.d的service模式,一种是systemctl模式。 ServerStatus-Hotaru版是systemctl模式。 systemctl中的运行客户可以为root用户,也可以为其它用户,但其它用户应具有访问 Web 路径和写入权限。 本例中以caddy用户和caddy用户组为例。 vim /etc/systemd/system/sergate.service [Unit] Description=ServerStatus-Server Documentation=https://github.com/cokemine/ServerStatus-Hotaru After=network.target [Service] User=caddy Group=caddy ExecStart=/usr/local/ServerStatus/server/sergate --config=/usr/local/ServerStatus/server/config.json --web-dir=/usr/local/ServerStatus/web --port 35601 Restart=on-failure [Install] WantedBy=multi-user.target chown -R caddy:caddy /usr/local/ServerStatus/server/ chown -R caddy:caddy /usr/local/ServerStatus/web systemctl daemon-reload systemctl start sergate systemctl status sergate --no-page -l systemctl enable sergate ##3.2 手动安装客户端 ###3.2.1 安装必要的运行依赖 apt install python3 python3-pip wget #一般系统都是python3了,可以试着暂时不安装。 ###3.2.2 下载客户端文件 ####3.2.2.1 psutil 版客户端 pip3 install psutil #需安装psutil依赖 wget -P /etc/serverstatus https://raw.githubusercontent.com/cokemine/ServerStatus-Hotaru/master/clients/status-psutil.py ####3.2.2.2 默认版本,推荐 wget -P /etc/serverstatus https://raw.githubusercontent.com/cokemine/ServerStatus-Hotaru/master/clients/status-client.py #此版本无需安装上述任何依赖即可运行 ###3.2.3 修改客户端配置文件 vim /etc/serverstatus/status-psutil.py #psutil 版 vim /etc/serverstatus/status-client.py #默认版 修改以下几项就可以了 SERVER = "填写服务端IP" #域名最好 PORT = 服务端端口 #默认35601 USER = "username01" #服务端用户名 PASSWORD = "password" #服务端密码 INTERVAL = 1 # 更新间隔,单位:秒 ###3.2.4 试运行 python3 /etc/serverstatus/status-psutil.py二选一status-client.py ###3.2.5 可能出现的问题 系统中python3没有安装,比如上古的Centos。 安装方法见`https://winamp.top/142.html`2.3.2章节。 ###3.2.6 加入开机启动 vim /etc/systemd/system/serverstatus.service [Unit] Description=ServerStatus Client After=network.target [Service] Type=simple IgnoreSIGPIPE=no User=nobody ExecStart=/usr/bin/python3 /etc/serverstatus/status-psutil.py二选一status-client.py [Install] WantedBy=multi-user.target systemctl daemon-reload systemctl start serverstatus systemctl status serverstatus systemctl enable serverstatus #四、服务端Web的搭建 上述服务端和客户端指的是两个VPS,现在,服务端指的是VPS的服务端,客户端指的是你本地的PC。 说的比较啰嗦,简而言之就是,你在你的笔记本或手机上怎么查看各服务器的情况呢。 ##4.1 服务端web的搭建 本例以caddy v1.0.5为例,也可以是疯行的nginx。caddy前文有安装教程,不再赘述。 ##4.2 caddy配置文件 yourdomain.com:port { #你的域名和端口,一般是443 gzip timeouts none tls /etc/caddy/fullchain.cer /etc/caddy/private.key #证书和密钥 root /usr/local/ServerStatus/web #web存放的路径,必须和上文3.1.3中的一致。 header / { Strict-Transport-Security "max-age=31536000;" } } ##4.3 本地查看 在本地PC端浏览器中输入`https://yourdomain.com:port` ##4.4 题外话 可以先搭建好caddy,并指向存放web前端。这样的话在搭建ServerStatus-Hotaru过程中可以清楚明了的看到服务端和客户端是否运行成功的情况。 #五、参考 1. [Github ServerStatus-Hotaru](https://github.com/cokemine/ServerStatus-Hotaru "Github ServerStatus-Hotaru") 1. [Github ServerStatus](https://github.com/BotoX/ServerStatus "Github ServerStatus") 1. [ServerStatus-Hotaru:基于Toyo修改的ServerStatus脚本](https://www.aptx.xin/serverstatus-hotaru.html "ServerStatus-Hotaru:基于Toyo修改的ServerStatus脚本") 标签: 云探针, 探针, ServerStatus