介绍
ServerStatus中文版是一个酷炫高逼格的云探针、云监控、服务器云监控、多服务器探针~。
在线演示:https://tz.cloudcpp.com
本程序的使用需用nginx,直接使用lnmp.org上的一键安装即可,不需要安装mysql.
安装服务端
生成服务端程序需要make,gcc,g++这三个依赖,如果没有安装的话,执行:
apt-get update && apt-get install gcc g++ make wget -y
如果你已经安装了,那么直接执行下面的命令即。
wget --no-check-certificate https://github.com/cppla/ServerStatus/archive/master.tar.gz -O /root/ServerStatus.tar.gz tar -zxvf /root/ServerStatus.tar.gz mv /root/ServerStatus-master /root/ServerStatus cd /root/ServerStatus/server make ./sergate
如果没错误提示,OK,ctrl+c关闭;如果有错误提示,检查35601端口是否被占用
拷贝ServerStatus/status到你的网站目录,
sudo cp -r /root/ServerStatus/web/* /home/wwwroot/你的域名
修改服务端配置配置
修改config.json
文件,注意username, password的值需要和客户端对应一致
{"servers": [ { "username": "s01", "name": "Mainserver 1", "type": "Dedicated Server", "host": "GenericServerHost123", "location": "Austria", "password": "some-hard-to-guess-copy-paste-password" }, ] }
运行服务端:
web-dir参数为上一步设置的网站根目录,务必修改成自己网站的路径
cd /root/ServerStatus/server ./sergate --config=config.json --web-dir=/home/wwwroot/default
客户端配置设置
客户端有两个版本,client-linux为普通linux,client-psutil为跨平台版,普通版不成功,换成跨平台版即可。
这里只介绍linux版本的配置,如果需要跨平台,请参考:https://github.com/cppla/ServerStatus
客户端是一个python编写的单文件,可以不用下载serverstatus的全部文件
wget https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py -O /root/client-linux.py vim client-psutil.py #修改SERVER地址,username帐号, password密码
打开云探针页面,就可以正常的监控。接下来把服务器和客户端脚本自行加入开机启动,或者进程守护,或以后台方式运行即可!例如: nohup python client-linux.py &
脚本
开机启动可以采用cron
的@reboot
或者写入/etc/rc.local
文件。
在支持systemd
(debian8/ubuntu16/centos7以上)的系统中可以用以下的方法:
服务端:
添加配置(全文复制并粘贴)
echo '[Unit] Description=serverstatus After=network.target [Service] ExecStart=/root/ServerStatus/server/sergate --config=/root/ServerStatus/server/config.json --web-dir=/home/wwwroot/status Restart=always [Install] WantedBy=multi-user.target' > /etc/systemd/system/serverstatus.service
启动程序并设置开机自启
systemctl enable serverstatus && systemctl start serverstatus
客户端(全文复制并粘贴)
echo '[Unit] Description=serverstatus After=network.target [Service] ExecStart=/usr/bin/python /root/client-linux.py Restart=always [Install] WantedBy=multi-user.target' > /etc/systemd/system/cstatus.service
启动程序并设置开机自启
systemctl enable cstatus && systemctl start cstatus
快速添加
服务端
服务端快速添加配置,
wget --no-check-certificate https://files.zorz.cc/addserverstatus.sh -O addserverstatus.sh && bash addserverstatus.sh
代码预览
#!/bin/bash server_conf="/root/ServerStatus/server/config.json" set_config(){ read -p "Please enter username:" username_s [[ -z $username_s ]] && echo "username is needed" && exit 1 grep username ${server_conf} | sed s/[[:space:]]//g | cut -d ":" -f 2 | tr -d '["][,]' | while read line ; do [[ "$line" = "$username_s" ]] && echo "Username has been used" && exit 89 done [[ $? -eq 89 ]] && exit 1 read -p "Please enter password (default is zorz.cc):" password_s password_s=${password_s:-zorz.cc} read -p "Please enter location (default is us):" location_s location_s=${location_s:-us} read -p "Please enter type (default is kvm):" type_s type_s=${type_s:-kvm} read -p "Please enter name:" name_s [[ -z $name_s ]] && echo "name is needed" && exit 1 } Add_ServerStatus_server(){ sed -i '3i\ },' ${server_conf} sed -i '3i\ "disabled": false' ${server_conf} sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} sed -i '3i\ "host": "'"None"'",' ${server_conf} sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf} sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf} sed -i '3i\ "username": "'"${username_s}"'",' ${server_conf} sed -i '3i\ {' ${server_conf} echo "done" } set_config Add_ServerStatus_server
添加完成之后需要重新启动serverstatus,如果是systemd的话那么systemctl restart serverstatus
客户端
客户端快速添加配置
wget --no-check-certificate https://files.zorz.cc/clientstatus.sh -O clientstatus.sh && bash clientstatus.sh
代码预览
#!/bin/bash client_file="/root/client-linux.py" read -p "Please enter same username with server:" username_c [[ -z $username_c ]] && echo "same username is needed" && exit 1 read -p "Please enter same password with server (default is zorz.cc):" password_c password_c=${password_c:-zorz.cc} read -p "Please enter server address (domain or ip) :" server_address [[ -z $server_address ]] && echo "server address is needed" && exit 1 wget --no-check-certificate https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py -O /root/client-linux.py [[ -z $(which python) ]] && apt-get update && apt-get install python -y sed -i 's/'"127.0.0.1"/"${server_address}"'/' ${client_file} sed -i 's/USER = "s01"/USER = "'"${username_c}"'"/' ${client_file} sed -i 's/USER_DEFAULT_PASSWORD/'${password_c}'/' ${client_file} echo '[Unit] Description=serverstatus After=network.target [Service] ExecStart=/usr/bin/python /root/client-linux.py Restart=always [Install] WantedBy=multi-user.target' > /etc/systemd/system/cstatus.service systemctl start cstatus && systemctl enable cstatus echo done
这里的脚本主要是我自己用的,所以只实现了添加配置这个功能,如果有需要的话,可以留言给我,我可以完善这个脚本的功能。
参考链接:
https://github.com/cppla/ServerStatus
https://doub.io/shell-jc3/