tar xvzf nagios-3.2.3.tar.gz
mkdir /xyx/nagios
useradd -d /xyx/nagios nagios
chmod 755 /xyx/nagios
cd nagios-3.2.3
./configure --prefix=/xyx/nagios --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include
make all
make install
make install-init ##This installs the init script in /usr/local/etc/rc.d
make install-commandmode
make install-config
2、nagios-plugins的安装
tar –xvzf nagios-plugins-1.4.15.tar.gz
#mkdir /xyx/nagios
cd nagios-plugins-1.4.15
./configure --prefix=/xyx/nagios
make all
make install
安装完成以后在/xyx/nagios/libexec目录下生成基本的plugins. 包含ping, http, ftp, smtp等基本命令
#mv /xyx/nagios-plugins/libexec /xyx/nagios 作者: 翔子 时间: 2011-11-22 23:54 标题: 使用linux下Nagios开源监控软件来监控服务器 http://hi.baidu.com/thinkwzb/blog/item/9283a700ce352096e850cdf6.html
首先通过-v选项验证配置文件是否正确
# cd /usr/lcoal/nagios/bin
# ./nagios -v ../etc/nagios.cfg
如果没有错误,就可以启动它了。
# cd /usr/local/nagios/bin
# ./nagios -d /usr/local/nagios/etc/nagios.cfg
nagios web界面提示
It appears as though you do not have permission to view information for any of the services you requested...
打开cgi.cfg配置文件,里面有个参数:
use_authentication=1
为了保障系统的安全性,nagios设置了这个参数,默认为1,改为0即可
查看/usr/local/nagios/var/nagios.log日志文件,观察启动是否正常。
在IE浏览器中查看监控情况。
点击左边导航栏的 Host Detail
1. 问题的由来
对于一个网站来说,外部用户能够看到就是该网站的页面。网站页面能否被正常访问,以及显示是否正常势必会成为网站整体水平最直接的外在表现。
那么,如何才能在第一时间检测到网页是否正常,并且给相应的技术人员发出报警来及时解决问题,而不是等接到用户抱怨的电话后才在慌忙中仓促的解决问题呢?解决这个问题的关键就是要在第一时间发现问题,发现那些不能显示的网页或是显示不正常的网页,并及时发出报警。当然我们可以通过人工的方法去监测,但对于一些大型的、复杂的网站来说就不是很合适了,我们可以使用监控软件来解决这个问题。我所使用的就是Nagios软件,它提供的插件(Plugins)中有相应的命令可以完成对网页的监控。
2. 如何通过Nagios解决此类问题
对于Nagios、NRPE以及Nagios Plugins的安装配置网站的资料很多。
想使用Nagios监控网页状况,Nagios插件中的一个命令不得不被提及,那就是check_http,我没可以使用它来检查网页是否正常、可用。该命令的具体说明和用法如下。
Usage: check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>] [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string] [-k string] [-S] [-C <age>] [-T <content-type>]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=<ok|warning|critical|follow> 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)
define host{
use linux-server
host_name web_pages
alias web_pages
address 127.0.0.1
}
#the check web pages on the remote host.
define service{
use generic-service
host_name web_pages ;主机名,为了便于显示可以定义一个虚拟的host
service_description web page1
check_command check_webpage!-H www.testhost.test -u /index.html
}
#the check_apache on the remote host.
define service{
use generic-service
host_name hostname
service_description web page
check_command check_nrpe! check_webpage
}
command_line /usr/bin/sms -f 13901111111 -p 562128 -t $CONTACTPAGER$ -m "$HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$
on $TIME$ result is $SERVICEOUTPUT$" $CONTACTPAGER$
}
2、 nagios发送配置contacts.cfg:
[root@nagios ~]# more /usr/local/nagios/etc/contacts.cfg
define contact{
contact_name sa
alias system admin
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,r,
service_notification_options c,w,r
service_notification_commands notify-service-by-email,notify-service-by-sms
# service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
# email 1234@sina.com
pager 158010775111
}
[root@nagios ~]#