ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
重启apache
service httpd restart
7、为web访问加入认证的用户名和密码;
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
8、配置nagios;
A、修改nagios中收取报警消息的联系人
#vi /usr/local/nagios/etc/objects/contacts.cfg
此处我只修改了email 加入了自己的邮箱地址;
B、vi /usr/local/nagios/etc/cgi.cfg
use_authentication=1 改成
use_authentication=0,
即不用验证.不然有一些页面不会显示。 //在网上看到这个,不知道这点是什么意思 ,我也做了此修改;
C、检查配置文件是否正确:
[root@host etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 3.2.1
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 03-09-2010
License: GPL
Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'...
Read object config files okay...
Running pre-flight check on configuration data...
Checking services...
Checked 8 services.
Checking hosts...
Checked 1 hosts.
Checking host groups...
Checked 1 host groups.
Checking service groups...
Checked 0 service groups.
Checking contacts...
Checked 1 contacts.
Checking contact groups...
Checked 1 contact groups.
Checking service escalations...
Checked 0 service escalations.
Checking service dependencies...
Checked 0 service dependencies.
Checking host escalations...
Checked 0 host escalations.
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
D、修改日志文件的属主,以后有问题可以查看此文件;
chown -R nagios:nagios /usr/local/nagios/var/nagios.log
E、以上各步配置均没有错误,此时可以启动nagios了,
service nagios start
到此nagios配置完成,可以通过下面web访问访问了;
http://ip/nagios/
9、配置被监控端;(监控linux服务器)
下载如下安装包:
A、nagios-plugins:wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
B、nrpe:wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
安装如下;
(1)在系统中添加nagios用户;
useradd nagios
passwd nagios
(2)安装nagios-plugins;
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure
make
make install
(3)改变nagios下的属主;
chown nagios.nagios /usr/local/nagios -Rf
(4)安装nrpe-2.12
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
(5)修改nrpe.cfg,允许主机为对应公司网关;
vi /usr/local/nagios/etc/nrpe.cfg 将allowed_hosts=127.0.0.1改成:X.X.X.X,127.0.0.1
添加相应要监控的对象,如下所示:
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 500 -c 600
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
(6) 启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
可以查看nrpe是否启动;
netstat -an|grep 5666
察看是否能返回nrpv版本号;
/usr/local/nagios/libexec/check_nrpe -H localhost
10、配置command.cfg、nagios.cfg……
vi /usr/local/nagios/etc/objects/commands.cfg
添加如下内容;
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
添加被监控端的配置文件;
vi /usr/local/nagios/etc/nagios.cfg
在此处中间添加;
cfg_file=/usr/local/nagios/etc/objects/Test.cfg
编辑该文件;
define host{
use linux-server
host_name Test
alias linux-server
address 192.168.0.110
}
define service{
use generic-service
host_name Test
service_description HTTP
check_command check_http
}
define service{
use generic-service
host_name Test
service_description FTP
check_command check_ftp
}
define service{
use generic-service
host_name Test
service_description SSH
check_command check_ssh
}
define service{
use generic-service
host_name Test
service_description SMTP
check_command check_smtp
}
define service{
use generic-service
host_name Test
service_description POP3
check_command check_pop
}
define service{
use generic-service
host_name Test
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name Test
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name Test
service_description check-disk
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name Test
service_description zombie_procs
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name Test
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name Test
service_description total_procs
check_command check_nrpe!check_total_procs
}
define service {
use generic-service
host_name Test
service_description check_mysql
check_command check_mysql!192.168.0.110!3306!nagios!nagios!nagdb!60!600
}
这里面定义的是监控的对象,修改完成后保存退出,就可以了。
11、检查配置文件,重启nagios服务;
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart
12、此时可以访问该页面,相关的被监控的对象也将出现。
************************************** M ySQL监控配置 *************************************
1、在要监控的MYSQL数据库里新建库和相应的用户;
CREATE DATABASE nagdb DEFAULT CHARSET=utf8;
GRANT SELECT ON nagdb.* TO 'nagios'@'%';
UPDATE mysql.user SET 'Password' = PASSWORD('********') WHERE 'User' = 'nagios'
FLUSH PRIVILEGES;
2、修改command.cfg,添加对mysql和主从同步的定义;
vi /usr/local/nagios/etc/objects/command.cfg;
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -d $ARG5$
}
define command{
command_name check_mysql_slave
command_line $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -d $ARG5$ -S -w $ARG6$ -c $ARG7$
}
3、在被监控的主数据库和从数据库的cfg文件中分别添加;
define service {
use generic-service
host_name Master-Mysql
service_description check_mysql
check_command check_mysql!192.168.0.111!3306!nagios!******!nagdb
}
define service {
use generic-service
host_name Slave-Mysql
service_description check_mysql_slave
check_command check_mysql_slave!192.168.0.112!3306!nagios!******!nagdb!60!600
}
4、检查配置文件,重启nagios服务;
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart
5、到此MySQL的监控配置完成。
