版本:nagios-plugins-1.4.15.tar.gz
nagios-3.3.1.tar.gz
nrpe-2.13.tar.gz
nagios 3.3 是变化很大的 他需要apache和PHP 结合 加CGI 原来只用CGI 。
因为主页原来是/usr/local/nagios/share/index.html
现在是 index.php 但是感觉页面没原来好看了。
本章 是结合前面的LAMP 环境nginx代理没了使用正常的80端口。
一 nagios3.3的配置开始
(1)apache安装及配置
vim /usr/local/apache-2.2.21/conf/httpd.conf
#setting for nagios
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
#groupadd nagcmd
#usermod -G nagcmd nagios
# id nagios
uid=1000(nagios) gid=1000(nagios) 组=1000(nagios),1001(nagcmd)
#tar zxvf nagios-3.3.1.tar.gz
#cd nagios/
#./configure --with-command-group=nagcmd
#make all
#make install
这里会报错。。。
/usr/bin/install: omitting directory `includes/rss/extlib’
/usr/bin/install: omitting directory `includes/rss/htdocs’
/usr/bin/install: omitting directory `includes/rss/scripts’
make[1]: *** [install] Error 1
make[1]: Leaving directory `/tmp/nagios-3.3.1/nagios/html’
make: *** [install] Error 2
解决方法:
sed -i 's:for file in includes/rss/*;:for file in includes/rss/*.*;:g' ./html/Makefile
sed -i 's:for file in includes/rss/extlib/*;:for file in includes/rss/extlib/*.*;:g' ./html/Makefile
或者手动 vim html/Makefile
#make install
# make install-init
# make install-config
# make install-commandmode
# /usr/local/apache-2.2.21/bin/htpasswd -c /usr/local/nagios/etc/htpasswd houzc
New password:
Re-type new password:
Adding password for user houzc
二 Nagios默认有如下几个配置文件修改:
define contact{
contact_name
houzc
use generic-contact
alias nagiosadmin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email
houzaicunsky@gmail.com
}
define contactgroup{
contactgroup_name
admins
alias Nagios Administrators
members nagiosadmin,houzc #定义联系组的成员
|
define host{
host_name 192.168.3.107
address 192.168.3.107
check_command check-host-alive
max_check_attempts 5
check_period 24x7
contact_groups
admins
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
|
#vim /usr/local/nagios/etc/objects/services.cfg
#service definition
define service{
host_name 192.168.3.107 #被监控的主机,hosts.cfg中定义的
service_description check-host-alive #被监控服务的描述
check_command check-host-alive #所用的命令,是commands.cfg中定义的
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups admins # 联系人组,是contactgroups.cfg中定义的
}
|
三 .安装Nagios-plugins插件
…………..前面省略
Checking host dependencies...
Checked 0 host dependencies.
Checking commands...
Checked 24 commands.
Checking time periods...
Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:
0
Things look okay - No serious problems were detected during the pre-flight check
|
service nagios start
四、监控远程服务器的服务
nagios 是一个主动与被动的监控,什么是主动和被动?
主动 :就是被监控端不用授权或者被监控是提供对外的服务。如:ping HTTP
下面图是本地监控
如果想监控URL 不同参数 还要自己修改他的插件的参数。
看这篇:http://hzcsky.blog.51cto.com/1560073/493599
被动监控需要通过SLL 加入 隧道然后 NRPE ->libexec的监控插件采集数据。
(2)安装nrpe
apt-get install libssl-dev libssl0.9.8
|
cd nrpe-2.13
./configure
make all
make install-daemon
make install-daemon-config
ls /usr/local/nagios 会生成 bin etc libexec share
NRPE v2.13
注:蓝色标注的是命令名,即check_users就是等号后面/usr/local/nagios/libexec/check_users -w 5 -c 10的简称。这五个命令,分别是监控登录用户数、cpu负载、/ 分区使用情况、僵尸进程和总的进程数。 具体可以-h 查看相应参数。
|
PROCS OK: 85 processes
apt-get
install libssl-dev libssl0.9.8
|
make install-daemon-config
(2)添加check_nrpe定义
添加如下内容:
# 'check_nrpe ' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
$USER1 是/usr/local/nagios/etc/resource.cfg 声明的 $USER1$=/usr/local/nagios/libexec |
define service{
host_name 192.168.3.101 #被监控的主机名,这里注意必须是linux且运行着nrpe,而且必须是hosts.cfg中定义的
service_description check-load # 监控项目的名称
check_command check_nrpe!check_load
#监控命令是check_nrpe,是在commands.cfg中定义的,带的参数是check_load,是在nrpe.cfg中定义的
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
这里只添加一个测试。 |
host 配置文件添加和107 修改没区别只是IP地址变了。
define host{ host_name 192.168.3.101 address 192.168.3.101 check_command check-host-alive max_check_attempts 5 check_period 24x7 contact_groups admins notification_interval 10 notification_period 24x7 notification_options d,u,r } |
测试nagios配置# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
五、利用邮件手机报警。
nagios发警告邮件是采用本机的smtp服务,可以查看commands.cfg中关于发邮件的命令进行定义。使用本机的mail命令,就需要开启本机的smtp服务。
我是用的公司的邮件服务器建立了个用户而已,不然自己用postfix 搭建个SMTP端只为nagios用更好!
# tar –zxvf sendEmail-v1.55.tar.gz -c /usr/src
# cp sendEmail-v1.55/sendEmail /usr/local/bin
如果你不带-m参数的话,就会提示你自行输入,输入完成后使用CTRL-D来结束
vim /usr/local/nagios/etc/objects/commands.cfg
#文件前面有最后先注释 直接复制修改自己的邮件用户和认证就可以! # 'notify-host-by-email' command definition # 'notify-service-by-email' command definition |
如有问题请加群:71922203!!!!
本文转自 houzaicunsky 51CTO博客,原文链接:http://blog.51cto.com/hzcsky/838778