shell 监控网站

http://www.maiziedu.com/wiki/linux/monitor/

网站服务器监控的内容有:

  1. 监控WEB服务器的状态;

  2. 监控数据库服务器的工作状态;

  3. 监控网络的工作状态;

  4. 监控服务器的资源使用状态;

  5. 监控其他需要关注的服务状态。

网站服务器监控的内容有:

  1. 邮件报警;

  2. 短信报警;

  3. 页面状态报警。

监控任务部署

1.监控网络工作状态

1)监控网络的运行情况

思路:定期获取监控服务器到被监控服务器的平均的响应时间以及丢包率,如果这两个指标超过我们设置的阀值,将触发报警机制。

2)脚本设计与测试:

[liutaostdio@WLJY01 lesson9]$ cat server.list 
## init env: server_detect_url-IP-service
#   server_description  server_ip  server_service
GUANGHUAN_IDC    119 . 254 . 71 . 1        ping
DianXinTong_IDC      211 . 103 . 156 .1      ping
YiDong_IDC              114 . 113 . 235. 65    ping
Xidan_IDC                10 . 10 . 10 . 10          ping
[liutaostdio@WLJY01 lesson9]$ sh ping.sh 
Testing  119 . 254 . 71 . 1  .... repl_time : 3.391 , lost_percent : 0-->GUANGHUAN_IDC is normal..
Testing  211 . 103 . 156 . 1  .... repl_time : 2.716 , lost_percent:0-->DianXinTong_IDC is normal..
Testing  114 . 113 . 235 . 65 .... repl_time : 3.941 , lost_percent:0-->YiDong_IDC is normal..
Testing  10 . 10 . 10 . 10 ....repl_time : , lost_percent:100-->reply time > 50ms or exist lost_percent!
--2015-08-30 15:30:35--  http://service.winic.org/sys_port/gateway/?id=your_id&pwd=your_password&to=your_telphone&content=reply%20time%20%3E%2050ms%20or%20exist%20lost_percent!
Resolving service.winic.org... 220.112.27.49
Connecting to service.winic.org|220.112.27.49|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 38 [text/html]
Saving to: “./smslog/10.10.10.10_ping_150830-15:30:21.log”


100%[==========================================================================================>] 38         --.-K/s   in 0s      


2015-08-30 15:30:36 (4.45 MB/s) - “./smslog/10.10.10.10_ping_150830-15:30:21.log” saved [38/38]

实际环境操作:

monitor1.png

脚本文件内容:

monitor2.png

monitor3.png

执行结果:

monitor4.png

2.监控web服务器工作状态

1) 监控web 服务器运行情况

思路:定期获取被监控服务器提供的URL地址,如果url内容可以正常返回,则表示服务正常,否则将触发报警机制

2)脚本设计与测试:

[liutaostdio@WLJY01 lesson9]$ cat server.list 
## init env: server_detect_url-IP-service
#   server_description   server_ip  server_service
http://172.21.2.25/index.html       172.21.2.25  web
http://172.21.2.26:8080/ac/         172.21.2.26  web
http://172.21.2.27:8080/console/  172.21.2.27  web


[liutaostdio@WLJY01 lesson9]$ sh  web.sh 
--------- 172 . 21 . 2 . 25 : web -----------
Spider mode enabled. Check if remote file exists.
--2015-08-30 16:15:27--  http://172.21.2.25/index.html
Connecting to 172 . 21 . 2 . 25 : 80 ...  Connected .
HTTP request sent, awaiting response... 200 OK
Length: 23 [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.


172 .21 . 2 . 25  web is normal ...
--------- 172 .21 . 2 . 26 : web -----------
Spider mode enabled. Check if remote file exists.
--2015-08-30 16:15:27--  http://172.21.2.26:8080/ac/
Connecting to 172 . 21 . 2 . 26 : 8080 ...  Failed : No route to host .
172 . 21 . 2 . 26 web error , please check !  ..

实际环境操作:

monitor5.png

脚本文件内容:

monitor6.png

执行结果:

monitor7.png

3.监控数据库服务器工作状态

1)监控数据库服务器运行情况

思路:定期获取被监控服务器的状态,如果状态信息可以正常返回,则表示服务正常,否则将触发报警机制

2)脚本设计与测

[liutaostdio@WLJY01 lesson9]$ cat server.list 
## init env : server_detect_url-IP-service
# server_description  server_ip  server_service
#db
mysql_172 . 21 . 2 . 25   172 . 21 . 2 . 25   mysql
mysql_172 . 21 . 2 . 26   172 . 21 . 2 . 26   mysql


[liutaostdio@WLJY01 lesson9]$ sh db.sh 
--------- 172 . 21 . 2 . 25 : mysql -----------
1+1
2
172 . 21 . 2 . 25  mysql is normal ...
--------- 172 . 21 . 2 . 26 : mysql -----------
ERROR 2003 (HY000) : Can't connect to MySQL server on ' 172 . 21 . 2 . 26 ' (113)
172 .21 . 2 . 26 mysql error , please check ! ..

环境操作:

monitor8.png

脚本文件内容:

monitor9.png

执行结果:

monitor90.png

4.监控特定服务端口工作状态

1)监控服务器特殊端口是否正常;

思路:定期获取被监控服务器特定的端口状态,如果端口状态正常,则表示服务正常,否则将触发报警机制

检测方法:采用nmap 来获取目标服务器的端口开放状态

2)脚本设计与测试:

[liutaostdio@WLJY01 lesson9]$ cat server.list 
## init env: server_detect_url-IP-service
#   server_description server_ip  server_service
80     172 . 21 . 2 . 25     port
3306   172 . 21 . 2 . 25    port
9000   172 . 21 . 2 . 25    port
1723   172 . 21 . 2 . 26    port
[liutaostdio@WLJY01 lesson9]$ sh port.sh 
--------- 172 . 21 . 2 . 25 : 80 port state is ----------open
172 . 21 . 2 . 25 80  port is normal...
--------- 172 . 21 . 2 . 25 : 3306 port state is ----------open
172 . 21 . 2 . 25 3306  port is normal...
--------- 172 . 21 . 2 . 25 : 9000 port state is ---------- closed
172 . 21 . 2 . 25 port error,please check! ..
---------172 . 21 . 2 . 26 : 1723 port state is ---------filtered
172 . 21 . 2 . 26 port error,please check! ..

实际环境操作:

monitor91.png

脚本文件内容:

monitor92.png

执行结果:

monitor93.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值