系统管理:使用Nagios监控网页

来源:软件水平考试    发布时间:2012-11-04    软件水平考试视频    评论

  1. 问题的由来
  对于一个网站来说,外部用户能够看到就是该网站的页面。网站页面能否被正常访问,以及显示是否正常势必会成为网站整体水平最直接的外在表现。
  那么,如何才能在第一时间检测到网页是否正常,并且给相应的技术人员发出报警来及时解决问题,而不是等接到用户抱怨的电话后才在慌忙中仓促的解决问题呢?解决这个问题的关键就是要在第一时间发现问题,发现那些不能显示的网页或是显示不正常的网页,并及时发出报警。当然我们可以通过人工的方法去监测,但对于一些大型的、复杂的网站来说就不是很合适了,我们可以使用监控软件来解决这个问题。我所使用的就是Nagios软件,它提供的插件(Plugins)中有相应的命令可以完成对网页的监控。
  2. 如何通过Nagios解决此类问题
  对于Nagios、NRPE以及Nagios Plugins的安装配置网站的资料很多,在我的Blog中也有相应的文章可以参考,在这里就不再过多的说明了。
  想使用Nagios监控网页状况,Nagios插件中的一个命令不得不被提及,那就是check_http,我没可以使用它来检查网页是否正常、可用。该命令的具体说明和用法如下。
  Usage: check_http -H | -I [-u ] [-p ]
  [-w ] [-c ] [-t ] [-L]
  [-a auth] [-f ] [-e ]
  [-s string] [-l] [-r | -R ] [-P string]
  [-m :] [-4|-6] [-N] [-M ] [-A string]
  [-k string] [-S] [-C ] [-T ]
  NOTE: One or both of -H and -I must be specified
  Options:
  -h, --help
  Print detailed help screen
  -V, --version
  Print version information
  -H, --hostname=ADDRESS
  Host name argument for servers using host headers (virtual host)
  Append a port to include it in the header (eg: example.com:5000)
  -I, --IP-address=ADDRESS
  IP address or name (use numeric address if possible to bypass DNS lookup).
  -p, --port=INTEGER
  Port number (default: 80)
  -4, --use-ipv4
  Use IPv4 connection
  -6, --use-ipv6
  Use IPv6 connection
  -S, --ssl
  Connect via SSL. Port defaults to 443
  -C, --certificate=INTEGER
  Minimum number of days a certificate has to be valid. Port defaults to 443
  (when this option is used the url is not checked.)
  -e, --expect=STRING
  String to expect in first (status) line of server response (default:
  HTTP/1.)
  If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)
  -s, --string=STRING
  String to expect in the content
  -u, --url=PATH
  URL to GET or POST (default: /)
  -P, --post=STRING
  URL encoded http POST data
  -N, --no-body
  Don’t wait for document body: stop reading after headers.
  (Note that this still does an HTTP GET or POST, not a HEAD.)
  -M, --max-age=SECONDS
  Warn if document is more than SECONDS old. the number can also be of
  the form "10m" for minutes, "10h" for hours, or "10d" for days.
  -T, --content-type=STRING
  specify Content-Type header media type when POSTing
  -l, --linespan
  Allow regex to span newlines (must precede -r or -R)
  -r, --regex, --ereg=STRING
  Search page for regex STRING
  -R, --eregi=STRING
  Search page for case-insensitive regex STRING
  --invert-regex
  Return CRITICAL if found, OK if not
  -a, --authorization=AUTH_PAIR
  Username:password on sites with basic authentication
  -A, --useragent=STRING
  String to be sent in http header as "User Agent"
  -k, --header=STRING
   Any other tags to be sent in http header. Use multiple times for additional headers
  -L, --link
  Wrap output in HTML link (obsoleted by urlize)
  -f, --onredirect=
  How to handle redirected pages
  -m, --pagesize=INTEGER<:INTEGER>
  Minimum page size required (bytes) : Maximum page size required (bytes)
  -w, --warning=DOUBLE
  Response time to result in warning status (seconds)
  -c, --critical=DOUBLE
  Response time to result in critical status (seconds)
  -t, --timeout=INTEGER
  Seconds before connection times out (default: 10)
  -v, --verbose
  Show details for command-line debugging (Nagios may truncate output)
  通过check_http的帮助我们可以清楚的了解到该命令可以为我们做什么,以及如何去做。选项虽然很多,其实常被用到的却只有几项,而且很多选项是有默认值的一般无需设置。下面就我们需要用到的几个选项做一个简要的说明。
-H, --hostname=ADDRESS
主机名或域名
-I, --IP-address=ADDRESS
serverIP地址,用于在不能DNS的情况下
-p, --port=INTEGER
端口号,默认80
-u, --url=PATH
url,默认是/
-w, --warning=DOUBLE
warning状态的响应时间,单位是秒
-c, --critical=DOUBLE
critical状态的响应时间,单位是秒
-t, --timeout=INTEGER
连接超时时间,默认10

    举一个简单的实例,一个网站的域名是www.testhost.test,端口是默认80,需要监测它的主页/index.html,warning时间和critical时间、 timeout时间使用默认值,不设置。具体命令书写如下。
  $ ./check_http -H www.testhost.test -u /index.html
  HTTP OK HTTP/1.1 200 OK - 115357 bytes in 1.717 seconds |time=1.716934s;;;0.000000 size=115357B;;;0
  可以看出该网页是正常的,如果网页地址不对或显示有错误也会有相应的反馈信息。
  3. 具体配置Nagios来监控网页
  通过Nagios监控网页一般有两种方式,一种是直接通过Nagios监控主机配置监控服务监视网页;另一种是在某一安装了NRPE的客户端主机上配置监控命令,通过NRPE监控网页情况,再将结果传回给Nagios监控主机。通过一个装有NRPE的客户端作为桥梁的方式可以使主机更加安全,减轻Nagios主机的负担,同时可以避免在Nagios主机上配置DNS等不必要的麻烦。

上一页12下一页

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答