当前位置:文档之家› Nagios+cacti+npc经典配置详解

Nagios+cacti+npc经典配置详解

Nagios+cacti+npc

铁锤居士作品

最新最全面个人文档

已测试通过-切莫错过

软件介绍+步骤详解+成功实现

完稿与2011-4-22

Cacti与rrdtool简介

一、概述

Linux下用的最多的是MRTG的性能监视,MRTG配置比较简单,MRTG的确是非常好的东东,但我认为它毕竟已经是一套很旧的软件了,其作者在多年前就已经开发了RRDTool代替该软件,现在已经发展得很成熟。既然有更好的选择,为什么我们还要用MRTG呢?

简单的说,rrdtool就是一个强大的绘图的引擎,很多语言都可以调用rrdtool绘图。

整个系统的架构是这样的:

基于SNMP协议,被监控端是服务器,或一些网络设备,

网络管理工作站,采用Linux(或Freebsd)操作系统,并且安装Net-SNMP工具,使用RRDTOOL采集数据,存储数据,并用Cacti调用rrdtool显示出来。

CACTI采用PHP编写,基于B/S结构。

二、介绍

MRTG的优点:简单、易上手,基本安装完了之后只要更改一下配置文件即可。

缺点:

1、使用文本式的数据库,数据不能重复使用;

2、只能按日、周、月、年来查看数据;

3、只能画两个DS(一条线、一个块);

4、每取一次数据即需要绘图一次,浪费系统资源;

5、无管理功能;

rrdtool的优点:

1、使用rrd存储格式,数据能重复使用,比如我可以将一个rrd文件中的数据与另一个rrd文件中的数据相加。

2、可以定义任意时间段画图,即你可以画出一张半年以来的数据的图,也可以画出一张半小时以来的图。

3、能画任意个DS。

4、CDEF让你能任意摆弄数据。

缺点:

1、rrdtool的作用只是存储数据和画图,它没有mrtg中集成的数据采集功能;

2、在命令行的使用非常复杂,参数极多。

3、无管理功能。

简单的说,rrdtool就是一个强大的绘图的引擎。

由于其非常复杂的命令,对用户非常不友好,我一度想自己用php写一套系统。幸运的是,半年前我找到了cacti(https://www.doczj.com/doc/0d3994763.html,)。对该工具我只有一个字形容:“great!”。

cacti 其实是一套php程序,它运用snmpget采集数据,使用rrdtool绘图。它的界面非常漂亮,能让你根本无需明白rrdtool的参数能轻易的绘出漂亮的图形。更难能可贵的是,它提供了强大的数据管理和用户管理功能,一张图是属于一个host的,每一个host又可以挂载到一个树状的结构上。用户的管理上,作为一个开源软件,它居然做到为指定一个用户能查看的“树”、host、甚至每一张图,还可以与LDAP结合进行用户的验证!我不由得佩服作者考虑的周到!Cacti还提供自己增加模板的功能,让你添加自己的snmp_query和script!可以说,cacti将rrdtool的所有“缺点”都补足了!

cacti 安装环境:

操作系统:Redhat Linux AS5.4

安装方式:全新安装并以文本方式与自定义安装软件

内核版本:2.6.18-164.el5

Apache:httpd-2.2.3-31.el5

PHP:php-5.1.6-23.2.el5_3

Mysql:mysql-5.0.77-3.el5

Net-snmp:net-snmp-5.3.2.2-7.el5

RRDtool:rrdtool-1.2.23-1.el5.rf

Cacti:cacti-0.8.7e.tar.gz

Cacti架构图:

数据实现层apache php

--------------------------------------------------------------------------------------------------

数据存储层 mysql rrdtool

--------------------------------------------------------------------------------------------------

数据采集层 net-snmp script

Cacti工作原理图:

全新linux系统安装以文本方式并自定义安装软件

……………………省略…………………….

去掉所有打勾

然后把红色标记移到development tools

接下来按F2,跳出详细菜单

选择OK就行了,

同样步骤把红色标记移到MySQL Database,按F2.除了默认打勾还要把以下三个一起打勾Mod_auth_mysql mysql-devel php-mysql

接下来同样步骤选择web server,去掉默认squid tux webalizer的安装

接下来选择system tools ,然后按回车,再选中它按F2,去掉所有默认安装只留Net-snmp-libs 与net-snmp-utils连个打上勾

安装完后重启

选择firewall configuration,禁用selinux

开放http-80端口

启动结束进入系统

=====================================================================

(大家也可以通过把yum源更换到光盘或centos资源库,具体可以参考我另外一篇bolg。https://www.doczj.com/doc/0d3994763.html,/844766/278402先yum mysql apache php

yum -y install mysql mysql-server php-mysql httpd php

再yum需要用到的包

yum -y install php-pdo lm_sensors net-snmp php-snmp net-snmp-utils perl-Net-Daemon perl-PlRPC perl-DBI perl-DBD-MySQL =====================================================================

设置 mysql Apache snmp 开机自动启动

[root@cacti-qmail soft]# chkconfig mysqld on

[root@cacti-qmail soft]# chkconfig httpd on

[root@cacti-qmail soft]# chkconfig snmpd on

[root@cacti-qmail soft]# service mysqld start

[root@cacti-qmail soft]# service httpd start

[root@cacti-qmail soft]# service snmpd start

PHP配置(默认已都激活)

激活PHP扩展

/etc/php.ini

Extension_dir=”usr/lib/php/modules”

激活mysql扩展

/etc/php.d/mysql.ini

Extension=mysql.so

Apache配置(默认已支持)

配置支持PHP:/etc/httpd/conf.d/php.conf

LoadModule php5_module modules/libphp5.so

AddHandler php5-script .php

AddType text/html .php

DirectoryIndex index.php

Mysql配置

为mysql数据库root账号设置密码

[root@cacti-qmail soft]# mysqladmin --user=root password viong0613

[root@cacti-qmail soft]# mysqladmin --user=root --password reload

Enter password: 输入刚设置密码,检验是否正确

Rrdtool安装

[root@cacti-qmail soft]# ll

总计 1100

-rw-r--r-- 1 root root 49815 02-22 22:18 perl-rrdtool-1.2.23-1.el5.rf.i386.rpm

-rw-r--r-- 1 root root 955176 02-22 21:53 rrdtool-1.2.23-1.el5.rf.i386.rpm

-rw-r--r-- 1 root root 5542 02-22 22:01 rrdtool-devel-1.2.23-1.el5.rf.i386.rpm

-rw-r--r-- 1 root root 65566 2004-05-19 rzsz-3.48.tar.gz

drwxrwxr-x 2 10127 wheel 4096 02-24 01:46 src

[root@cacti-qmail soft]#rpm –ivh perl-rrdtool-1.2.23-1.el5.rf.i386.rpm rrdtool-1.2.23-1.el5.rf.i386.rpm rrdtool-devel-1.2.23-1.el5.rf.i386.rpm

warning: perl-rrdtool-1.2.23-1.el5.rf.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6 Preparing... ########################################### [100%]

1:rrdtool ########################################### [ 33%]

2:perl-rrdtool ########################################### [ 67%]

3:rrdtool-devel ########################################### [100%]

Cacti安装

[root@cacti-qmail soft]# wget https://www.doczj.com/doc/0d3994763.html,/downloads/cacti-0.8.7e.tar.gz

[root@cacti-qmail soft]# tar -zxvf cacti-0.8.7e.tar.gz

[root@cacti-qmail soft]# mv cacti-0.8.7e /var/www/html/cacti

[root@cacti-qmail soft]# chown -R root.root /var/www/html/cacti/

修改cacti文件目录的拥有者

在mysql建立cacti数据库环境

[root@cacti-qmail soft]# mysql -u root -h 127.0.0.1 -p

Enter password:

mysql> create database cacti;

Query OK, 1 row affected (0.01 sec)

mysql> grant all on cacti.* to viong@localhost identified by 'viong0623';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> quit;

Bye

到cacti根目录下把cacti.sql中的数据导入到数据库cacti中

[root@cacti-qmail cacti]# mysql -uroot -pviong0613 cacti

配置mysql连接参数

[root@cacti-qmail cacti]# vi /var/www/html/cacti/include/config.php

/* make sure these values refect your actual database/host/user/password */

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "viong";

$database_password = "viong0623";

$database_port = "3306";

[root@cacti-qmail cacti]# vi /var/www/html/cacti/include/global.php

/* Default database settings*/

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "viong";

$database_password = "viong0623";

$database_port = "3306";

cacti-plugins插件安装

[root@cacti-qmail soft]#unzip cacti-plugin-0.8.7e-PA-v2.6.zip

[root@cacti-qmail soft]# cd cacti-plugin-arch/

[root@cacti-qmail cacti-plugin-arch]# ll

总计 124

-rw-r--r-- 1 root root 93070 11-22 13:50 cacti-plugin-0.8.7e-PA-v2.6.diff

drwxr-xr-x 5 root root 4096 11-22 13:03 files-0.8.7e

-rw-rw-rw- 1 root root 15237 2006-11-10 LICENSE

-rw-rw-rw- 1 root root 2037 2007-11-06 pa.sql

-rw-rw-rw- 1 root root 1230 11-22 13:50 Readme.txt

[root@cacti-qmail cacti-plugin-arch]# cp cacti-plugin-0.8.7e-PA-v2.6.diff /var/www/html/cacti/ [root@cacti-qmail cacti-plugin-arch]# cp pa.sql /var/www/html/cacti/

root@cacti-qmail cacti-plugin-arch]# cd /var/www/html/cacti/

[root@cacti-qmail cacti]# patch -p1 -N

[root@cacti-qmail cacti]# mysql -uroot -pviong0613 cacti

[root@cacti-qmail cacti]# vi include/global.php

修改一下参数

$config['url_path'] = '/cacti/';

保存退出

建立任务调度

[root@cacti-qmail cacti]# crontab –e

输入以下内容,代表每5分钟来执行后面PHP解析内容,把显示信息重定向到空的路径

*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

[root@cacti-qmail cacti]# crontab -l

*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

也可手工跑一次:/usr/bin/php /var/www/html/cacti/poller.php Cacti的web初始化

在浏览器输入http://192.168.15.67/cacti/登陆cacti

被监控主机snmp文件设置Linux

被监控主机需要配置snmp.

#vi /etc/snmp/snmpd.conf

1更改

com2sec notConfigUser default public

改为

com2sec notConfigUser 127.0.0.1 public

2、更改

access notConfigGroup "" any noauth exact systemview none none 改为

access notConfigGroup "" any noauth exact all none none

#view all included .1 80

将前面的 # 注释去掉。保存退出

测试snmp是否正常

#snmpwalk -c public -v 2c localhost

#snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

IP-MIB::ipAdEntIfIndex.61.xxx.xxx.xxx = INTEGER: 2 IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1 IP-MIB::ipAdEntIfIndex.172.xxx.xxx.xxx = INTEGER: 3

也可以用snmpd -f -Le 命令查看当前有没有出什么错

Windows

需要安装snmp服务

开启---运行—appwiz.cpl 把管理和监视工具打上勾,然后点详细信息进去,勾起我们需要用的组件

安装好后,

运行—services.msc,点snmp server设置一下选项

小插曲:很感谢方老师制作了一个cacti视频教程,自己用cacti也几年时间了。为了加固自己的知识。把这些整理出来当备用,并附上方老师发给我的一系列的视频教程.下载看附件

开源网管软件Cacti系列视频讲座

(一)Cacti架构与应用示例

(二)Cacti安装与部署(上)

(二)Cacti安装与部署(下)

(三)Cacti设备管理与模板应用

(四)Cacti的多种数据采集方式

(五)Cacti插件架构与插件安装

(六)Cacti高效轮询工具spine

Nagios简介

Nagios是一个用来监视系统和网络的开源应用软件,它通常运行于一个主服务器上,这个服务器运行 Liunx 或 Unix 操作系统。Nagios 利用其众多的插件实现对本机和远端服务的监控,当被监控对象出现异常,Nagios 就会及时给管理人员告警。它是一个基于TCP/IP协议的软件包,包含有nagios主程序和它的各个插件,配置非常灵活,可以监视的项目很多,也可以通过自定义 shell 脚本进行监控服务,非常适合各类企业的网络应用。

Nagios功能非常强大,它可以监控服务和主机,但是他自身并不包括这部分功能的代码,所有的监控、检测功能都是有插件来完成的。再说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是nagios很重要的功能之一。但是,同样的,nagios 自身也没有报警部分的代码,甚至没有插件,而是交给用户或者其他相关开源项目组去完成。nagios安装,是指基本平台,也就是nagios 软件包的安装。它是监控体系的框架,也是所有监控的基础。

打开nagios官方的文档,会发现nagios基本上没有什么依赖包,只要求系统是linux或者其他nagios支持的系统。不过如果你没有安装apache(http服务),那么你就没有那么直观的界面来查看监控信息了,所以apache姑且算是一个前提条件。

Nagios 系统的特点主要有下面几点:

?监控主机资源和网络服务

?

?允许用户通过设计实现简单的插件来监控自己特定的服务

?

?当被监控对象出现问题时,会及时通知管理人员

?

?事先定义事件处理程序,当对象出现问题时自动调用对应的处理程序

?

?通过 web 页面来监视对象状态,警告提示和日志文件。

需要安装软件列表:

php-devel-5.1.6-23.2.el5_3.i386.rpm

php-json-ext-1.2.1.tar.bz2

cacti-plugin-0.8.7e-PA-v2.6.zip

nagios-3.2.1.tar.gz

nagios-plugins-1.4.14

ndoutils-1.4b9.tar.gz

npc-2.0.4.tar.gz

Nagios安装

https://www.doczj.com/doc/0d3994763.html,/projects/nagios/files/

[root@cacti-qmail soft]# wget https://www.doczj.com/doc/0d3994763.html,/project/nagios/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz [root@cacti-qmail soft]# tar -zxvf nagios-3.2.1.tar.gz

[root@cacti-qmail soft]#cd nagios-3.2.1

[root@cacti-qmail nagios-3.2.1]# ./configure --prefix=/usr/local/nagios

[root@cacti-qmail nagios-3.2.1]#make all

输入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来安装主程序,CGI和HTML文件

make install-init

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

使用make install-init在/etc/rc.d/init.d安装启动脚本

make install-commandmode

- This installs and configures permissions on the

directory for holding the external command file

使用make install-commandmode来配置目录权限

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-commandmode来安装示例配置文件,安装的路径是/usr/local/nagios/etc

make install-webconf

- This installs the Apache config file for the Nagios

web interface

使用make install-webconf来安装apache的配置文件

=================================================================

make install在安装这个动作之前要增加一个nagios用户,并修改它的权限,不然会出现以下错误:=================================================================

cd ./base && make install

make[1]: Entering directory `/home/yahoon/nagios/nagios-2.9/base'

make install-basic

make[2]: Entering directory `/home/yahoon/nagios/nagios-2.9/base'

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin

/usr/bin/install: invalid user `nagios' 非法用户nagios

make[2]: *** [install-basic] Error 1

make[2]: Leaving directory `/home/yahoon/nagios/nagios-2.9/base'

make[1]: *** [install] Error 2

make[1]: Leaving directory `/home/yahoon/nagios/nagios-2.9/base'

make: *** [install] Error 2

=====================================================================

[root@cacti-qmail nagios-3.2.1]# useradd nagios

[root@cacti-qmail nagios-3.2.1]#mkdir /usr/local/nagios

[root@cacti-qmail nagios-3.2.1]#chown nagios.nagios /usr/local/nagios

[root@cacti-qmail nagios-3.2.1]#make all

[root@cacti-qmail nagios-3.2.1]#make install; make install-init;make install-commandmode;make install-config;make install-webconf

验证程序是否被正确安装

切换目录到安装路径(这里是/usr/local/nagios),看是否存在 etc、bin、 sbin、 share、 var这五个目录,如果存在则可以表明程序被正确的安装到系统了。后表是五个目录功能的简要说明:

bin Nagios执行程序所在目录,nagios文件即为主程序

etc Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件

sbin Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录

Share Nagios网页文件所在的目录

Var Nagios日志文件、spid 等文件所在的目录

修改nagios页面文件

[root@cacti-qmail nagios-3.2.1]# more /etc/httpd/conf/nagios.conf

# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER

# Last Modified: 11-26-2005

#

# This file contains examples of entries that need

# to be incorporated into your Apache web server

# configuration file. Customize the paths, etc. as

# needed to fit your system.

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/https://www.doczj.com/doc/0d3994763.html,ers

Require valid-user

相关主题
文本预览
相关文档 最新文档