Nagios+PNP4nagios+Nagiosql
1.首先安装下面的包:
yum install libjpeg-devel libpng-devel pango* libart_lgpl-devel pango-devel* cairo-devel* libxml2-devel libjpeg-devel libpng-devel php-gd gd-devel perl-GD libtoul-ltdl-devel rrdtool-perl perl-devel perl-ExtUtils-Embed perl-Time-HiRes yum groupinstall "Development Tools" libjpeg-devel libpng-devel pango* libart_lgpl-devel pango-devel* cairo-devel* libxml2-devel libjpeg-devel libpng-devel php-gd gd-devel perl-GD libtoul-ltdl-devel rrdtool-perl perl-devel perl-ExtUtils-Embed perl-Time-HiRes
2.接着我们再安装下面的包
yum install httpd gd gd-devel php php-mysql mysql-devel mysql mysql-server gcc glibc glibc-common
注:原机器有的包,可以通过rpm -qa|grep 包名 检查下,如有上述包的可以不装。
3.添加nagios运行所需的用户和组
groupadd nagcmd
useradd -G nagcmd nagios
passwd nagios
4.把apache也添加到nagcmd的组里
usermod-a -G nagcmd apache
5.编译安装nagios
tar -zxvf nagios-3.5.1.tar.gz
./configure --with-command-group=nagcmd --enable-event-broker
*** Configuration summary for nagios 3.5.1 08-30-2013 ***:
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.
make all#编译所有
*** Compile finished ***
If 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
make install-exfoliation
- This installs the Exfoliation theme for the Nagios
web interface
make install-classicui
- This installs the classic theme 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 documentation on the Nagios Library at:
http://library.nagios.com
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://support.nagios.com
*************************************************************
Enjoy.
make install#安装
*** Main program, CGIs and HTML files installed ***
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
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
make[1]: Leaving directory `/usr/local/src/nagios'
make install-init#安装开机启动脚本
[root@localhost nagios]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
*** Init script installed ***
make install-commandmode#安装命令模式
[root@localhost nagios]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
make install-config#安装生成配置文件
*** Config files installed ***
Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
make install-webconf#创建与apache关联
[root@localhost nagios]# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
*** Nagios/Apache conf file installed ***
make install-exfoliation#服务器接口主题
[root@localhost nagios]# make install-exfoliation
cp -rf contrib/exfoliation/stylesheets/* /usr/local/nagios/share/stylesheets
cp -rf contrib/exfoliation/images/* /usr/local/nagios/share/images
6.关闭 selinux
6.1编辑配置文件#永久生效,需要重启机器
vim /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled#把这行的改成disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
6.2写进内核,立即生效,重启机器后会失效
setenforce 0
7.创建密码认证文件
htpasswd -c/usr/local/nagios/etc/htpasswd.users nagiosadmin#创建用于web的登录的文件
注:该命令的执行要到安装的nagios的目录下,这里是/usr/local/nagios
[root@localhost nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
8. 启动服务
service httpd start
9.把nagios加入服务
chkconfig --add nagios#加为服务
chkconfig nagios on#设为开机启动
10.安装nagios-plugins
tar -zxvf nagios-plugins-1.4.15.tar.gz#解压文件
./configure--with-nagios-user=nagios --with-nagios-group=nagios #配置nagios插件
--with-apt-get-command:
--with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
--with-ping-command: /bin/ping -n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql: /usr/bin/mysql_config
--with-openssl: yes
--with-gnutls: no
--enable-extra-opts: no
--with-perl: /usr/bin/perl
--enable-perl-modules: no
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
--enable-libtap: no
make&&make install#编译安装
/usr/bin/install -c -o nagios -g nagios 'check_breeze' '/usr/local/nagios/libexec/check_breeze'
/usr/bin/install -c -o nagios -g nagios 'check_disk_smb' '/usr/local/nagios/libexec/check_disk_smb'
/usr/bin/install -c -o nagios -g nagios 'check_flexlm' '/usr/local/nagios/libexec/check_flexlm'
/usr/bin/install -c -o nagios -g nagios 'check_ircd' '/usr/local/nagios/libexec/check_ircd'
/usr/bin/install -c -o nagios -g nagios 'check_log' '/usr/local/nagios/libexec/check_log'
/usr/bin/install -c -o nagios -g nagios 'check_oracle' '/usr/local/nagios/libexec/check_oracle'
/usr/bin/install -c -o nagios -g nagios 'check_rpc' '/usr/local/nagios/libexec/check_rpc'
/usr/bin/install -c -o nagios -g nagios 'check_sensors' '/usr/local/nagios/libexec/check_sensors'
/usr/bin/install -c -o nagios -g nagios 'check_wave' '/usr/local/nagios/libexec/check_wave'
/usr/bin/install -c -o nagios -g nagios 'check_ifstatus' '/usr/local/nagios/libexec/check_ifstatus'
/usr/bin/install -c -o nagios -g nagios 'check_ifoperstatus' '/usr/local/nagios/libexec/check_ifoperstatus'
/usr/bin/install -c -o nagios -g nagios 'check_mailq' '/usr/local/nagios/libexec/check_mailq'
/usr/bin/install -c -o nagios -g nagios 'check_file_age' '/usr/local/nagios/libexec/check_file_age'
/usr/bin/install -c -o nagios -g nagios 'utils.sh' '/usr/local/nagios/libexec/utils.sh'
/usr/bin/install -c -o nagios -g nagios 'utils.pm' '/usr/local/nagios/libexec/utils.pm'
装完/usr/local/nagios/libexec目录下应该有下面的一些插件
[root@localhost libexec]# ls
check_apt check_disk_smb check_ide_smart check_mailq check_nt check_pop check_ssh check_wave
check_breeze check_dns check_ifoperstatus check_mrtg check_ntp check_procs check_ssmtp negate
check_by_ssh check_dummy check_ifstatus check_mrtgtraf check_ntp_peer check_real check_swap urlize
check_clamd check_file_age check_imap check_mysql check_ntp_time check_rpc check_tcp utils.pm
check_cluster check_flexlm check_ircd check_mysql_query check_nwstat check_sensors check_time utils.sh
check_dhcp check_ftp check_jabber check_nagios check_oracle check_simap check_udp
check_dig check_http check_load check_nntp check_overcr check_smtp check_ups
check_disk check_icmp check_log check_nntps check_ping check_spop check_users
11.登录nagios界面
注:要关闭主机防火墙,或者在防火墙中开放主机web的访问端口。
在浏览器中输入http://服务器IP/nagios,输入nagiosadmin,和刚才设置的密码。
安装成功。
12.安装nrpe#nagios监控远程的机器必须用nrpe,所以我们这边装nrpe这个插件,要说的一点是nagios服务器只需装nrpe 插件,不需要装nrpe demon也就是守护进程。并且nrpe不需要启动服务的。
tar -zxvf nrpe-2.15.tar.gz
./configure --with-nrpe-user=nagios \
> --with-nrpe-group=nagios \
> --with-nagios-user=nagios \
> --with-nagios-group=nagios \
> --enable-command-args \#改命令必须加,需要使用nrpe后面加参数
> --enable-ssl
*** Configuration summary for nrpe 2.15 09-06-2013 ***:
General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
Review the options above for accuracy. If they look okay,
type 'make all' to compile the NRPE daemon and client.
make all
*** Compile finished ***
If the NRPE daemon and client compiled without any errors, you
can continue with the installation or upgrade process.
Read the PDF documentation (NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.
make install-plugin
[root@localhost nrpe-2.15]# make install-plugin
cd ./src/ && make install-plugin
make[1]: Entering directory `/usr/local/src/nrpe-2.15/src'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios check_nrpe /usr/local/nagios/libexec
make[1]: Leaving directory `/usr/local/src/nrpe-2.15/src'
在本地主机测试远程的服务
[root@localhost libexec]# ./check_nrpe -H192.168.1.10
NRPE v2.15#测试成功
注意:监控端(服务器)的nrpe可以不启动服务,5666的端口不可以被占用。防火墙打开的话要开放5666端口的访问。nrpe通信双方的版本要一样的。监控客户机的nrpe要以守护进程的方式启动。
13.安装pnp4nagios是一个基于php和perl,用rrdtool将nagios采集的数据绘制图表的工具,
所以这里我们来安装rrdtool。
tar -xzf rrdtool-1.4.8.tar.gz
cd rrdtool-1.4.8
./configure --prefix=/usr/local/rrdtool
config is DONE!
With MMAP IO: yes
Build rrd_getopt: no
Build rrd_graph: yes
Static programs: no
Perl Modules: perl_piped perl_shared
Perl Binary: /usr/bin/perl
Perl Version: 5.10.1
Perl Options: PREFIX=/usr/local/rrdtool INSTALL_BASE= LIB=/usr/local/rrdtool/lib/perl/5.10.1
Ruby Modules:
Ruby Binary: no
Ruby Options: sitedir=/usr/local/rrdtool/lib/ruby
Build Lua Bindings: no
Build Tcl Bindings: no
Build Python Bindings: no
Build rrdcgi: yes
Build librrd MT: yes
Use gettext: yes
With libDBI: no
With libwrap: no
make
make install
[root@localhost bin]# ll#/usr/local/rrdtool/bin目录下有这几个文件并且文件的读写权限也要注意下
总用量 536
-rwxr-xr-x 1 root root 121317 10月 28 18:33 rrdcached
-rwxr-xr-x 1 root root 59346 10月 28 18:33 rrdcgi
lrwxrwxrwx 1 root root 9 10月 28 18:33 rrdcreate -> rrdupdate
lrwxrwxrwx 1 root root 9 10月 28 18:33 rrdinfo -> rrdupdate
-rwxr-xr-x 1 root root 62270 10月 28 18:33 rrdtool
-rwxr-xr-x 1 root root 295195 10月 28 18:33 rrdupdate
14.安装pnpnagios
tar -zxvf pnp4nagios-0.6.25.tar.gz
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool#加上rrdtool的路径
*** Configuration summary for pnp4nagios-0.6.25 03-01-2015 ***
General Options:
------------------------- -------------------
Nagios user/group: nagios nagios
Install directory: /usr/local/pnp4nagios
HTML Dir: /usr/local/pnp4nagios/share
Config Dir: /usr/local/pnp4nagios/etc
Location of rrdtool binary: /usr/local/rrdtool/bin/rrdtool Version 1.4.8
RRDs Perl Modules: FOUND (Version 1.3008)
RRD Files stored in: /usr/local/pnp4nagios/var/perfdata
process_perfdata.pl Logfile: /usr/local/pnp4nagios/var/perfdata.log
Perfdata files (NPCD) stored in: /usr/local/pnp4nagios/var/spool
Web Interface Options:
------------------------- -------------------
HTML URL: http://localhost/pnp4nagios
Apache Config File: /etc/httpd/conf.d/pnp4nagios.conf
Review the options above for accuracy. If they look okay,
type 'make all' to compile.
make all
*** Compile finished ***
make install
- This installs the main program and HTML files
make fullinstall
- This installs the main program, runlevel scripts, config and HTML files
Enjoy.
make install#普通安装
*** Main program, Scripts and HTML files installed ***
Please run 'make install-webconf' to install the
web configuration file
Please run 'make install-config' to install sample
configuration files
Please run 'make install-init' if you want to use
BULK Mode with NPCD
make install-webconf#安装web接口配置文件,关联apache
*** Apache config file installed ***
Restart your apache webserver to activete your changes.
Please run 'make install-config' to install sample
configuration files
Please run 'make install-init' if you want to use
BULK Mode with NPCD
make install-config#安装pnp4nagios配置文件
*** PNP4Nagios sample config files installed ***
Please run 'make install-init' if you want to use
BULK Mode with NPCD
make install-init#安装启动脚本,可以直接使用npcd的方式启动
[root@localhost pnp4nagios-0.6.25]# make install-init
cd ./scripts && make install-init
make[1]: Entering directory `/usr/local/src/pnp4nagios-0.6.25/scripts'
/usr/bin/install -c -m 755 -o root -g root -d /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root rc.npcd /etc/rc.d/init.d/npcd
/usr/bin/install -c -m 755 -o root -g root rc.pnp_gearman_worker /etc/rc.d/init.d/pnp_gearman_worker
make[1]: Leaving directory `/usr/local/src/pnp4nagios-0.6.25/scripts'
注意:也可以在上面的配置完的选项中直接make fullinstall
15. 进入到pnp4nagios的目录/usr/local/pnp4nagios/etc中,把相关后缀带sample文件变更成无sample后缀
例如:mvweb_traffic.cfg-sample web_traffic.cfg
16.配置Nagios来启用PNP4nagios
pnp4nagios有五种工作模式,常用的有三种
如下图所示:
16.1.Synchronous Mode
nagios.cfg 文件里改
process_performance_data=1
enable_environment_macros=1
service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata
command.cfg文件里改
define command {
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
define command {
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
注:template.cfg和定义的host.cfg里要把添加的主机模板和服务模板都加进去。这里我先介绍下几种模式。具体的模板和主机的改法我会在下面介绍。
16.2.Bulk Mode
nagios.cfg里改
注意:下面的改法,可以在原本注释的文件里去掉注释,也可以直接复制过来加在文件的最后面。
process_performance_data=1
#
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
#
# host performance data starting with Nagios 3.0
#
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
commands.cfg里改
define command{
command_name process-service-perfdata-file
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata
}
define command{
command_name process-host-perfdata-file
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata
}
16.3.Bulk Mode with NPCD
process_performance_data=1
#
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
#
# host performance data starting with Nagios 3.0
#
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
command.cfg更改
define command{
command_name process-service-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}
define command{
command_name process-host-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}
npcd启动方式: /usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg
16.4.Bulk Mode with NPCD and npcdmod
16.5.Gearman Mode
这两种模式就先不介绍了,一般用不到。想了解的话,详见官网:https://docs.pnp4nagios.org/pnp-0.6/config
pnp4nagios有很多种工作模式,这里我们选用Bulk模式,这里先把pnp4nagios执行数据收集的文件拷贝到nagios的libexec下,方便统一命令的执行路径.
cp/usr/local/pnp4nagios/libexec/process_perfdata.pl /usr/local/nagios/libexec/
其实在/usr/local/pnp4nagios/etc下的nagios.cfg的文件里已经有了对bulk等模式的定义,我们打开nagios.cfg的文件看看。注意:是在/usr/local/pnp4nagios/etc下的nagios.cfg
#
# Bulk / NPCD mode
#
process_performance_data=1
# *** the template definition differs from the one in the original nagios.cfg
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
# *** the template definition differs from the one in the original nagios.cfg
#
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHO
STSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
然后修改 /usr/local/nagios/etc/commands.cfg文件,修改命令如下
注意:这两个命令可以定义到配置文件的最下面,把本来机器上带的# 'process-host-perfdata' command definition 注释掉
#
# Bulk mode
#
#define command {
# command_name process-service-perfdata-file
# command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk /usr/local/pnp4nagios/var/service-perfdata
#}
#define command {
# command_name process-host-perfdata-file
# command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk /usr/local/pnp4nagios/var/host-perfdata
#}
然后修改/usr/local/nagios/etc/templates.cfg文件
define host {
name host-pnp action_url /pnp4nagios/index.php/graphhost=$HOSTNAME$&srv=_HOST_'rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
process_perf_data 1
register 0
}
define service {
name srv-pnp
action_url /pnp4nagios/index.php/graphhost=$HOSTNAME$&srv=$SERVICEDESC$'rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data 1
register 0
}
注意:要把process_perf_data 1加进去。
然后修改需要的主机这里以/usr/local/nagios/etc/localhost.cfg
这里我就简单的举几个例子。
# Define a host for the local machine
define host{
use linux-server,host-pnp #加上模板 ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}
# Define a service to "ping" the local machine
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
17.然后添加小太阳模版,镶嵌在nagios页面上
你只需要把鼠标移动到太阳图标上面就会自动弹出图形出来
拷贝status-header.ssi到/usr/local/nagios/share/ssi/目录下面来(这一步很重要,要不然移动到太阳标记上出不来图)到pnp4原安装的目录的Contrib目录下拷贝。
cp status-header.ssi/usr/local/nagios/share/ssi/
18.检查nagios配置并重启服务。
service npcd start
service nagios restart
service httpd restart
效果如下图所示:
已经出图,证明pnp4nagios安装成功!
19.下面我们来安装nagiosql
tar -zxvf nagiosql_311.tar.gz
mv nagiosql /usr/local/nagios/#把解压出来的文件,迁移到/usr/local/nagios/下面
20. 建立nagiosql导出nagios配置文件的目录并修改权限
mkdir -p/etc/nagiosql/{hosts,services,backup/{,hosts,services},import}
chown -R apache:nagios /etc/nagiosql/
chmod -R 755 /etc/nagiosql
chmod 777 /usr/local/nagios/nagiosql/config
21. Nagios相关文件权限的设定
chown nagios:apache /usr/local/nagios/etc
chown nagios:apache /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
chown nagios:apache /usr/local/nagios/etc/*
chmod 664 /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
chmod 775 /usr/local/nagios/etc
22. 设定nagios二进制文件的权限,以便其能够通过Web程序执行
chown nagios:apache /usr/local/nagios/bin/nagios
chmod 750 /usr/local/nagios/bin/nagios
chown -R apache.nagios /usr/local/nagios/var/spool/
chown nagios:apache /usr/local/nagios/var/rw/nagios.cmd
chmod 660 /usr/local/nagios/var/rw/nagios.cmd
23. 为apache添加nagiosQL虚拟目录
vim /etc/httpd/conf.d/nagios.conf 最后增加如下内容:
Alias /nagiosQL "/usr/local/nagios/nagiosql"
<Directory "/usr/local/nagios/nagiosql">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
24. 建立nagiosql安装文件
touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER
25. 重启httpd服务
service httpd restart
26.会看见出现nagiosql管理界面
进去把页面设置为中文。
27. 登入管理界面
(1).管理域,配置对一些域的参数。
(2)工具-导入数据 右边会列出一些配置文件,选择导入即可。
导入只是把配置文件内容导入到Mysql数据库,而使用其配置文件时,是一个个cfg文件,所以下面要进行写入过程,写完并检查写入文件。
(3)检查配置并重启nagios
(4)写入之后就可以看到相应的cfg文件了,查看写入是否成功
ll /etc/nagiosql
(5) 修改nagios的配置文件,将原有以cfg_file开头项全部注释掉,加入面新写入的配置文件
加入新的配置文件路径
cfg_dir=/etc/nagiosql/hosts/
cfg_dir=/etc/nagiosql/services/
cfg_file=/etc/nagiosql/commands.cfg
cfg_file=/etc/nagiosql/contactgroups.cfg
cfg_file=/etc/nagiosql/contacts.cfg
cfg_file=/etc/nagiosql/contacttemplates.cfg
cfg_file=/etc/nagiosql/hostdependencies.cfg
cfg_file=/etc/nagiosql/hostescalations.cfg
cfg_file=/etc/nagiosql/hostextinfo.cfg
cfg_file=/etc/nagiosql/hostgroups.cfg
cfg_file=/etc/nagiosql/hosttemplates.cfg
cfg_file=/etc/nagiosql/servicedependencies.cfg
cfg_file=/etc/nagiosql/serviceescalations.cfg
cfg_file=/etc/nagiosql/serviceextinfo.cfg
cfg_file=/etc/nagiosql/servicegroups.cfg
cfg_file=/etc/nagiosql/servicetemplates.cfg
cfg_file=/etc/nagiosql/timeperiods.cfg
(6) 定义要监控的命令
例如:nrpe
(7) 添加要监控的主机。
(8)添加要监控的服务
注意:主机的模板要加上host-pnp,服务的模板srv-pnp都要加上。监控端命令行配置的命令,要与被监控端的nrpe.cfg配置的文件一致。
(9) 重启nagios,看看显示效果。
先要导入配置:
然后点 “工具”-"nagios控制“再执行下图所示的几个步骤:
(10) 执行完,会有下图所示的效果:
(11)添加监控mysql数据库服务
mysql> create database nagdb defaultCHARSET=utf8;
Query OK, 1 row affected(0.01 sec)
mysql> grant select on nagdb.* to 'nagios'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> update mysql.user set password =password('nagios') where user='nagios';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@localhost libexec]# ./check_mysql -H127.0.0.1 -u nagios -d nagdb -p nagios;
Uptime: 150 Threads: 1 Questions: 8 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables:8 Queries per second avg: 0.53
然后定义监控的命令
定义要监控的主机和服务
导入定义好的数据
按照以下的几个步骤:写入检测数据、写入其他数据、检查配置文件、重启nagios
检测效果:
(12) 添加告警邮件设置:
先定义联系人
再定义需监控的主机
再定义需监控的服务
检查服务也设置一下
主机的检查也设置下
然后重启一下nagios服务