通过脚本实现对web的健康检查
前面的文章中(https://www.cnblogs.com/zyxnhr/p/10707932.html),通过nginx的第三方模块实现对web端的一个监控,现在通过一个脚本实现对第三方的监控
脚本实现web的健康检查
1、编写脚本
[root@lb01 ~]# vim /script/nginx_check.sh
#!/bin/bash
#定义需要监控的节点
rs_arr=(
172.25.254.134
172.25.254.135
)
file_location=/usr/local/nginx/html/test.html
#定义函数web_result用于检测RS节点的web服务状态
function web_result {
rs=`curl -I -s $/index.html|awk 'NR==1{print $2}'`
return $rs
}
#定义函数new_row用于根据固定样式产生html表格框架
function new_row {
cat >> $file_location <<eof
<tr>
<td bgcolor="$4">$</td>
<td bgcolor="$4">$</td>
<td bgcolor="$4">$</td>
</tr>
eof
}
#定义函数auto_html通过并调用new_row冰箱其传递参数填充表格内容
function auto_html {
web_result $
rs=$?
if [ $rs -eq ]
then
new_row $ $ up green
else
new_row $ $ down red
fi
} while true
do
#产生头部部分
cat >> $file_location <<eof
<h4>The Status Of RS :</h4>
<table border="">
<tr>
<th>NO:</th>
<th>IP:</th>
<th>Status:</th>
</tr>
eof #循环产生每个节点的表格信息
for ((i=;i<${#rs_arr[*]};i++));do
auto_html $i ${rs_arr[$i]}
done #产生表格结尾部分
cat >> $file_location <<eof
</table>
eof sleep
>$file_location #每一次循环晴空一次html文件
done
2、修改配置文件
[root@lb01 ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
upstream web_pools {
server 172.25.254.134: weight=;
server 172.25.254.135: weight=;
}
server {
listen ;
server_name www.lbtest.com;
location / {
root html;
index test.html index.htm;
# proxy_set_header Host $host;
# proxy_pass http://web_pools;
}
}
}
3、执行脚本
[root@lb01 ~]# sh /script/nginx_check.sh
4、 浏览器访问看结果

看test.html
[root@lb01 ~]# watch -n "cat /usr/local/nginx/html/test.html"
<h4>The Status Of RS :</h4>
<table border="">
<tr>
<th>NO:</th>
<th>IP:</th>
<th>Status:</th>
</tr>
<tr>
<td bgcolor="green"></td>
<td bgcolor="green">172.25.254.134</td>
<td bgcolor="green">up</td>
</tr>
<tr>
<td bgcolor="green"></td>
<td bgcolor="green">172.25.254.135</td>
<td bgcolor="green">up</td>
</tr>
</table>
5、关闭172.25.254.134的httpd
[root@web1 image]# systemctl stop httpd

查看test.html
[root@lb01 ~]# watch -n "cat /usr/local/nginx/html/test.html"
<h4>The Status Of RS :</h4>
<table border="">
<tr>
<th>NO:</th>
<th>IP:</th>
<th>Status:</th>
</tr>
<tr>
<td bgcolor="red"></td>
<td bgcolor="red">172.25.254.134</td>
<td bgcolor="red">down</td>
</tr>
<tr>
<td bgcolor="green"></td>
<td bgcolor="green">172.25.254.135</td>
<td bgcolor="green">up</td>
</tr>
</table>
6、 恢复
[root@web1 image]# systemctl start httpd

查看test.html
[root@lb01 ~]# watch -n 1 "cat /usr/local/nginx/html/test.html"
<h4>The Status Of RS :</h4>
<table border="">
<tr>
<th>NO:</th>
<th>Status:</th>
</tr>
<tr>
<td bgcolor="green"></td>
<td bgcolor="green">172.25.254.134</td>
<td bgcolor="green">up</td>
</tr>
<tr>
<td bgcolor="green"></td>
<td bgcolor="green">172.25.254.135</td>
<td bgcolor="green">up</td>
</tr>
</table
已经实现了对web端的监控
7、添加监控节点
当需要添加节点时。只要在脚本的 rs_arr定义新的IP节点就可以了
rs_arr=(
172.25.254.134
172.25.254.135
NEW_IP
)
同时,在我们启动了脚本之后,监控到web端有变化,这时html已经发生变化,但是浏览器仍然停留在上一个页面,需要刷新才能跟新页面,这里用的是Google浏览器,有同一个自动刷新插件,设置1秒刷新一次,就保证了html的实时性!
参考:老男孩教育视频公开课https://www.bilibili.com/video/av25869969/?p=33
通过脚本实现对web的健康检查的更多相关文章
- 用 Python 脚本实现对 Linux 服务器的监控
目前 Linux 下有一些使用 Python 语言编写的 Linux 系统监控工具 比如 inotify-sync(文件系统安全监控软件).glances(资源监控工具)在实际工作中,Linux 系统 ...
- c#调用js,以及js调用C#里的函数, c#自己生成js代码,实现对web的控制
using mshtml;using System;using System.Collections.Generic;using System.Linq;using System.Security.P ...
- 利用过滤器Filter和特性Attribute实现对Web API返回结果的封装和统一异常处理
在我们开发Web API应用的时候,我们可以借鉴ABP框架的过滤器Filter和特性Attribute的应用,实现对Web API返回结果的封装和统一异常处理,本篇随笔介绍利用AuthorizeAtt ...
- 用 Python 脚本实现对 Linux 服务器的网卡流量监控
*这篇文章网上已经有相关代码,为了加深印象,我做了相关批注,希望对朋友们有帮助 工作原理:基于/proc文件系统 Linux 系统为管理员提供了非常好的方法,使其可以在系统运行时更改内核,而不需要重新 ...
- 用PowerShell脚本实现对SharePoint页面Title的修改
存在这样一种情况,对应的page已经部署到product的SharePoint环境中,那么在部署下一个版本的时候就不允许把已经创建好的page删除再创建,因此page中修改过的属性就不能再次部署到Sh ...
- 利用Python实现对Web服务器的目录探测
今天是一篇提升技能的干货分享,操作性较强,适用于中级水平的小伙伴,文章阅读用时约3分钟. PART 1/Python Python是一种解释型.面向对象.动态数据类型的高级程序设计语言. Python ...
- 利用 python 实现对web服务器的目录探测
一.pythonPython是一种解释型.面向对象.动态数据类型的高级程序设计语言.python 是一门简单易学的语言,并且功能强大也很灵活,在渗透测试中的应用广泛,让我们一起打造属于自己的渗透测试工 ...
- Python 脚本实现对 Linux 服务器的监控
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: 原文地址 由于原文来自微信公众号,并且脚本都是图片,所以这里 ...
- 利用shell脚本实现对mysql数据库的备份
#!/bin/bash #保存备份个数 number=3 #备份保存路径 backup_dir=/root/mysqlbackup #日期 dd=`date +%Y%m%d` #备份工具 tool=m ...
随机推荐
- poj 2828【线段树 单点更新】
POJ 2828 还是弱啊.思维是个好东西... 刚开始想来想去用线段树存人的话不仅超时,而且存不下...居然是存空位! sum[]数组存这个序列空位个数,然后逆序遍历.逆序好理解,毕竟最后一个人插进 ...
- 洛谷P1510 精卫填海
//01背包 求背包内物品价值超过某一定值时的最小体积 #include<bits/stdc++.h> using namespace std; ; ; int n,v_tot,w_tot ...
- oracle函数 mod(x,y)
[功能]返回x除以y的余数 [参数]x,y,数字型表达式 [返回]数字 [示例] select mod(23,8),mod(24,8) from dual; 返回:7,0
- CNN如何识别一幅图像中的物体
让我们对卷积神经网络如何工作形成更好直观感受.我们先看下人怎样识别图片,然后再看 CNNs 如何用一个近似的方法来识别图片. 比如说,我们想把下面这张图片识别为金毛巡回犬. 一个需要被识别为金毛巡 ...
- HZOJ 数颜色
一眼看去树套树啊,我可能是数据结构学傻了…… 是应该去学一下莫队进阶的东西了. 上面那个东西我没有打,所以这里没有代码,而且应该也不难理解吧. 这么多平衡树就算了,不过线段树还是挺好打的. 正解3: ...
- php 正则表达式怎么匹配标签里面的style?
$str = '<div style="margin:0px;text-align:left;padding:0px;">任意内容</div>'; $reg ...
- get_magic_quotes_gpc() PHP转义的真正含义
如何正确的理解PHP转 义是一个初学者比较困扰的问题.我们今天为大家简要的讲述了PHP转义的具体含义,希望有所帮助.PHP转义一直困扰着我, 今天认真的看了一下PHP手册, 终于解决了. 在PHP中默 ...
- no_expand优化案例
bond 来看一个烂语句: select a.*,b.dn from temp_allcrmuser a, phs_smc_user b where a.USERNUMBER=b.dn and ( ...
- Educational Codeforces Round 54 (Rated for Div. 2) D Edge Deletion (SPFA + bfs)
题目大意:给定你一个包含n个点m条边的无向图,现在最多在图中保留k条边,问怎么删除多的边,使得图中良好的节点数最多,求出保留在图中的边的数量和编号. 良好的节点定义为:删除某条边后该点到点1的最短距离 ...
- P1004 奶牛与牧场
题目描述 有一个牧场,牧场上的牧草每天都在匀速生长,这片牧场可供 \(a\) 头牛吃 \(b\) 天,或可供 \(c\) 头牛吃 \(d\) 天,那么,这片牧场每天新生的草量最多可供几头牛吃1天? 输 ...