Nagios 配置笔记

运维 系统运维
需要安装:gcc、glibc、gd、gd-devel、openssl-devel、httpd-devel、per-GD、net-snmp-devel、php-pdo、php-gd、perl-Crypt-DES,为了方便避开烦人的包依赖问题,我直接 yum install httpd*、php*、net-snmp、mysql*、glibc*;

一、前提:系统、PHPApacheMySQLMail都工作正常,在这不做介绍;
二、需要安装:gccglibcgdgd-developenssl-develhttpd-develper-GDnet-snmp-develphp-pdophp-gdperl-Crypt-DES,为了方便避开烦人的包依赖问题,我直接
yum install httpd*php*net-snmpmysql*glibc*;
需要下载的源码包:
nagios: http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.2.tar.gz
nagios-plugins: http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
nrpe: http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
nagios-snmp-plugins: http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz
###############################################  开始安装、配置  #####################################################
1、修改/etc/snmpd/snmped.conf,完成后的文件;
[root@Monitor nagios]# cat /etc/snmp/snmpd.conf | grep -v "#"
sec.name  source          community            //去掉此处的#
com2sec notConfigUser  127.0.0.1       public  
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1
group          context sec.model sec.level prefix read   write  notif           //去掉此处的#
access  notConfigGroup ""      any       noauth    exact  systemview none none
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root  (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat

2、启动snmpd
service snmpd start

3、安装Nagios;
groupadd nagios
useradd -g nagios nagios
passwd nagios

mkdir /usr/local/nagios
chown -R nagios:nagios /usr/local/nagios
chmod 755 /usr/local/nagios/
usermod -G nagios apache    //apachenagios用户加入到nagios组里;
usermod -G nagios nagios

tar zxf nagios-3.2.2.tar.gz

cd nagios-3.2.2
./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --enable-event-broker
根据如下提示:
the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

make install
- This installs the main program, CGIs, and HTML files

make install-init
- This installs the init script in /etc/rc.d/init.d

make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file

make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios.  Read the HTML documentation for more info
on doing this.  Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!

make install-webconf
- This installs the Apache config file for the Nagios
web interface
*** Support Notes *******************************************

If you have questions about configuring or running Nagios,
please make sure that you:

- Look at the sample config files
- Read the HTML documentation
- Read the FAQs online at http://www.nagios.org/faqs

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:

- What version of Nagios you are using
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
For more information on obtaining support for Nagios, visit:

http://www.nagios.org/support/

依次执行如下操作:
make all
make all install
make install-init               
make install-commandmode
make install-config        
make install-webconfig

4、安装nagios-plugins;
tar zxf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios-plugins
make
make install

安装完成以后在/usr/local/nagios-plugins会产生一个libexec的目录,
将该目录全部移动到/usr/local/nagios目录下即可。
如下:
mv /usr/local/nagios-plugins/libexec /usr/local/nagios/
5、安装nagios-snmp-plugins
tar xzf nagios-snmp-plugins.1.1.1.tgz
cd nagios_plugins
perl -MCPAN -e shell
接着一直回车;
直到提示符变为cpan>时输入:
cpan>install Net::SNMP
完成安装后退出:quit
最后执行./install.sh
6Apache里的配置文件自动加了nagios.conf,路径为/etc/httpd/conf.d 内容如下:
ScriptAlias /nagios/cgi-bin "/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


Alias /nagios "/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


重启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 加入了自己的邮箱地址;

Bvi /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服务器)
下载如下安装包:
Anagios-plugins:wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
Bnrpe: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.X127.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.cfgnagios.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的监控配置完成。

责任编辑:春晓
相关推荐

2010-05-31 10:22:31

Nagios pnp

2011-03-28 15:22:00

nagios

2010-05-31 11:10:37

Nagios pnp

2010-05-31 12:22:13

Nagios pnp

2011-03-28 08:48:00

Nagios

2011-03-21 09:17:06

Nagios

2011-03-31 16:05:18

Redhat配置nagios

2011-08-22 12:25:02

nagios

2011-03-25 10:37:17

2011-03-25 16:49:33

nagios服务

2011-03-31 16:05:18

Redhat配置nagios

2011-03-23 14:43:10

Nagiosnagios.cfg

2011-03-22 10:10:21

Nagios配置

2011-03-28 11:03:09

配置Nagios

2011-03-24 09:15:54

Nagios飞信

2013-06-08 16:55:22

Nagios

2011-03-31 16:05:15

Redhat配置nagios

2011-03-28 13:57:57

2011-03-25 17:13:37

Nagios配置文件

2011-03-28 09:07:26

Nagios配置文件
点赞
收藏

51CTO技术栈公众号