http://www.maiziedu.com/wiki/linux/monitor/
网站服务器监控的内容有:
监控WEB服务器的状态;
监控数据库服务器的工作状态;
监控网络的工作状态;
监控服务器的资源使用状态;
监控其他需要关注的服务状态。
网站服务器监控的内容有:
邮件报警;
短信报警;
页面状态报警。
监控任务部署
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]
实际环境操作:
脚本文件内容:
执行结果:
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 ! ..
实际环境操作:
脚本文件内容:
执行结果:
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 ! ..
环境操作:
脚本文件内容:
执行结果:
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! ..
实际环境操作:
脚本文件内容:
执行结果: