注:該方法實現不用登錄服務器查看基本系統狀況,定時任務會消耗必定的系統資源,不適合多臺監控,按需修改,部署。html
一、安裝nginx,我是用yum安裝的Nginx。nginx
[root@Test ~]# yum -y install nginx
二、建立2個目錄vim
[root@Test ~]# [ -d /sh ] || mkdir -p /sh
[root@Test ~]# [ -d /info ] || mkdir -p /info
三、建立信息生成腳本瀏覽器
[root@Test ~]# vim /sh/info.sh #!/bin/bash #生成系統狀況index.html cat << EFO > /info/index.html <!doctype html><html> <head><meta charset="utf-8"><title>系統狀況</title></head> <body><pre> DATETIME : $(date +%Y-%m-%d\ %H:%M:%S) HOSTNAME : $HOSTNAME IPADDR : $(hostname -I| awk '{print $1}') ------------------------------------------------------------------------------------------ $(uptime) ------------------------------------------------------------------------------------------ $(free -h) ------------------------------------------------------------------------------------------ $(df -h) ------------------------------------------------------------------------------------------ </pre></body></html> EFO
四、配置Nginx代理bash
[root@Test ~]# vim /etc/nginx/nginx-info.conf user root; worker_processes 1; pid logs/nginx-info.pid; events { worker_connections 1024; } http { server { listen 3000; server_name localhost; root /info; location / { } } }
五、賦予執行權限服務器
[root@Test ~]# chmod +x /sh/info.sh
六、添加定時任務spa
[root@Test ~]# echo '* * * * * root /bin/bash /sh/info.sh' >> /etc/crontab
七、啓動Nginx代理
[root@Test ~]# /usr/sbin/nginx -c /etc/nginx/nginx-info.conf
八、瀏覽器輸入IP:3000端口訪問便可code