1、软件包准备
nagios-4.0.8.tar.gz
nagios-plugins-2.0.3.tar.gz
nrpe-2.15.tar.gz
httpd-2.2.23.tar.gz
2、Nagios Server端安装
1)、安装相关依赖包
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
2)、安装Nagios
# useradd -s /sbin/nologin nagios
# configure --prefix=/usr/local/nagios
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# chkconfig nagios on
# chkconfig --list | grep nagios
3)、安装Nagios插件
# tar zxvf nagios-plugins-2.0.3.tar.gz
# cd nagios-plugins-2.0.3
# ./configure --prefix=/usr/local/nagios/
# make && make install
4)、安装配置apache
# tar zxvf httpd-2.2.23.tar.gz
# cd httpd-2.2.23
# ./configure --prefix=/usr/local/apache2
# make && make install
# vim /usr/local/apache2/conf/http.conf
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
User daemon
Group daemon
修改为
User nagios
Group nagios
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
修改并增加为
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
AddType application/x-httpd-php .php
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
增加验证配置,即在httpd.conf 文件最后添加如下信息:
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
创建上面的目录验证文件htpasswd
# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios
# vim /usr/local/nagios/etc/cgi.cfg
修改配置文件中所有含有nagiosadmin的内容
nagiosadmin => nagiosadmin,nagios
# scp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
# vim /etc/init.d/httpd
添加以下内容
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web Server
# chkconfig httpd on
# chkconfig --list | grep httpd
5)、安装配置php
# tar zxvf php-5.4.10.tar.gz
# cd php-5.4.10
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
# make && make install
# service httpd start
# service nagios start
6)、安装nrpe
# tar zxvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure --enable-command-args
# make all
# make install-plugin
# /usr/local/nagios/libexec/check_nrpe -H 10.0.2.203
NRPE v2.15
7)、配置commands.cfg,添加check_nrpe定义
vim /usr/local/nagios/etc/objects/commands.cfg
# ‘check_nrpe‘ command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
8、配置hosts.cfg
vim /usr/local/nagios/etc/objects/hosts.cfg
define host{
use linux-server
host_name node.3
alias node.3
address 10.0.2.203
}
9、配置node.3.cfg(也就是node.3的services.cfg文件,为了便于管理,每台机器的services.cfg文件分开配置,并以主机名命名)
vim /usr/local/nagios/etc/objects/node.3.cfg
define service{
use local-service
host_name node.3
service_description Current Load
check_command check_nrpe!check_load
contact_groups admins
}
define service{
use local-service
host_name node.3
service_description Check Disk disk
check_command check_nrpe!check_disk
contact_groups admins
}
define service{
use local-service
host_name node.3
service_description Total Processes
check_command check_nrpe!check_total_procs
contact_groups admins
}
define service{
use local-service
host_name node.3
service_description Current Users
check_command check_nrpe!check_users
contact_groups admins
}
define service{
use local-service
host_name node.3
service_description Check Zombie Procs
check_command check_nrpe!check_zombie_procs
contact_groups admins
}
10)、配置nagios.cfg
# vim /usr/local/nagios/etc/nagios.cfg
添加以下内容
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/node.3.cfg
11)、检查nagios配置文件,并重启nagios服务
# chown -R nagios.nagios /usr/local/nagios
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# service nagios restart
3、Nagios Client端的配置安装
1)、安装相关软件包
yum install -y xinetd openssl*
2)、添加用户
useradd nagios
passwd nagios
3)、安装nagios插件
# tar zxvf nagios-plugins-2.0.3.tar.gz
# cd nagios-plugins-2.0.3
# ./configure --prefix=/usr/local/nagios
# make && make install
# chown -R nagios.nagios /usr/local/nagios
4)、安装nrpe
# tar zxvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure --enable-command-args
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd
# vim /etc/services
在文件最后追加以下内容
nrpe 5666/tcp # nrpe
# vim /etc/xinetd.d/nrpe
添加监控主机IP
only_from = 127.0.0.1 10.0.2.201
# vim /usr/local/nagios/etc/nrpe.cfg
修改
dont_blame_nrpe=1
# service xinetd restart
# lsof -i:5666
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.15
# vim /usr/local/nagios/etc/nrpe.cfg
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
修改
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda
4、添加mysql和tomcat的监控
1)、添加mysql监控
Nagios Server:
# vim /usr/local/nagios/etc/objects/commands
添加以下内容
# ‘check_mysql‘ command definition
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$
}
# vim /etc/ld.so.conf
追加以下内容
/usr/local/mysql/lib/#因为check_mysql会提示找不到libmysqlclient.so.18文件
# /sbin/ldconfig -v
# /usr/local/nagios/libexec/check_mysql -H 10.0.2.203 -u mysql -p 123456
# vim /usr/local/nagios/etc/objects/node.3.cfg
追加以下内容
define service{
use local-service
host_name node.3
service_description Check MySQL
check_command check_nrpe!check_mysql!mysql!123456
contact_groups admins
}
Nagios Client:
# vim /usr/local/nagios/etc/nrpe.cfg
添加以下内容
command[check_mysql]=/usr/local/nagios/libexec/check_mysql -u $ARG1$ -p $ARG2$
# vim /etc/ld.so.conf
追加以下内容
/usr/local/mysql/lib/#因为check_mysql会提示找不到libmysqlclient.so.18文件
# /sbin/ldconfig -v
2)、添加自定义tomcat监控
Nagios Server:
# vim /usr/local/nagios/etc/objects/commands
添加以下内容
# ‘check_tomcat‘ command definition
define command{
command_name check_tomcat
command_line $USER1$/check_tomcat -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
}
# vim /usr/local/nagios/etc/objects/node.3.cfg
追加以下内容
define service{
use local-service
host_name node.3
service_description Check Tomcat
check_command check_nrpe!check_tomcat!tomcat
contact_groups admins
}
# service nagios restart
Nagios Client:
# vim /usr/local/nagios/etc/nrpe.cfg
添加以下内容
command[check_tomcat]=/usr/local/nagios/libexec/check_tomcat $ARG1$
# vim /usr/local/nagios/libexec/check_tomcat
#!/bin/sh
name=`basename $0`
process=`ps aux |grep -w "$1" | grep -vE "grep|$name"|wc -l |tr -d ‘ ‘`
if [ $process -ge 1 ]
then
echo "$1 proces running...."
exit 0
else
echo "$1 proces no exist! "
exit 2
fi
5、windows系统的监控
解压NSClient++-0.2.7.zip到C盘根目录
命令行:cmd
>c:\NSClient++-0.2.7
>nsclient++ /install
>nsclient++ SysTray
命令行:services.msc
找到NSClientpp服务,双击打开,点击”登录“标签,在”允许服务与桌面交互“前打勾
编辑c:\NSClient++-0.2.7\NSC.ini
[modules]模块
去掉除CheckWMI.dll和 RemoteConfiguration.dll 以外行的”;“
[Settings]
去掉password行的注释,并设置密码123456,同时需要在Nagios Server端command.cfg配置文件中check_nt命令定义处配置对应的密码
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s 123456 -v $ARG1$ $ARG2$
}
去掉allowed_hosts行的注释,并将本行修改为allowed_hosts=127.0.0.1/32,10.0.2.201
[NSClient]
去掉port行前面的注释,并设置port=12489
6、配置报警
1)、声音报警
Nagios Server端
上传音乐文件到/usr/local/nagios/share/media文件夹中
# vim /usr/local/nagios/etc/cgi.cfg
取消以下行前的”#“
host_unreachable_sound=hostdown.wav
host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
service_unknown_sound=warning.wav
normal_sound=noproblem.wav
2)、邮件报警
# yum install -y sendmail*
# service sendmail start
# vim /usr/local/nagios/etc/objects/contacts.cfg
修改
emailnagios@local.com => email*******@qq.com
# service nagios restart
# vim /usr/local/nagios/etc/objects/templates.cfg
修改generic-service中
notification_interval60 => notification_interval5
修改local-service中
max_check_attempts 4 => max_check_attempts 1
normal_check_interval 5 => normal_check_interval 5
retry_check_interval 2 => retry_check_interval 1
表示每五分钟发送一次邮件报警,关于nagios报警时间的详细配置,请参考”关于nagios报警时间间隔的配置“一文。
本文出自 “kimileonis” 博客,请务必保留此出处http://kimileonis.blog.51cto.com/5531747/1545943