此服务网页端需要有网页环境,譬如lemp
以Nginx为例
首先安装Nginx
apt-get install nginx
停止并启动 Nginx的命令如下
/etc/init.d/nginx stop
/etc/init.d/nginx start
示例界面:tz.hilove.cc
克隆代码
git clone https://github.com/cppla/ServerStatus.git
配置服务端(网页端):
生成服务端(服务端程序在ServerStatus/web下)
cd ServerStatus/server
make
./sergate
如果没错误提示,OK,ctrl+c关闭;如果有错误提示,检查35601端口是否被占用
修改配置文件
修改config.json文件(/root/ServerStatus/server/config.json),注意username, password的值需要和客户端对应一致
仿照原来示例修改填写就行了
拷贝ServerStatus/status到你的网站目录
cp -r ServerStatus/web/* /var/www/html
cp -r ServerStatus/web/* /home/wwwroot/tz.hilove.cc
运行服务端:
web-dir参数为上一步设置的网站根目录,务必修改成自己网站的路径
cd ServerStatus/server
./sergate --config=config.json --web-dir=/var/www/html
./sergate --config=config.json --web-dir=/home/wwwroot/tz.hilove.cc
客户端(分布在各个要监控的节点)配置(客户端程序在ServerStatus/clients下):
cd ServerStatus/clients
nano client-linux.py
修改SERVER地址,username帐号, password密码
python client-linux.py
运行即可
配置一下Supervisor进程守护,安装
apt-get install supervisor -y
写入配置(客户端)
nano /etc/supervisor/conf.d/tz_client.conf
写入以下内容
[program:tz_client]
command=python /root/ServerStatus/clients/client-linux.py
autorestart=true
autostart=true
user=root
重启Supervisor服务。
/etc/init.d/supervisor restart
重启客户端
supervisorctl restart tz_client
查看Supervisor服务运行状态。
supervisorctl status
如果遇到问题,可以检查日志:
supervisorctl tail -f tz_client stderr
更新PM2守护
安装PM2
wget -qO- https://getpm2.com/install.sh | bash
创建启动脚本
cat > /root/ServerStatus/clients/client-linux.json <<EOF
{
"name": "ServerStatus",
"cwd": "/root/ServerStatus/clients",
"interpreter": "python",
"script": "client-linux.py"
}
EOF
pm2 start client-linux.json
pm2 startup
pm2 save