Cacti+Nagios完全攻略,cactinagios既然有更好的选择,为


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(www.cacti.net)。对该工具我只有一个字形容:“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.el5Apache:httpd-2.2.3-31.el5PHP:php-5.1.6-23.2.el5_3Mysql:mysql-5.0.77-3.el5Net-snmp:net-snmp-5.3.2.2-7.el5RRDtool:rrdtool-1.2.23-1.el5.rfCacti:cacti-0.8.7e.tar.gzCacti架构图:数据实现层apache php--------------------------------------------------------------------------------------------------数据存储层mysql rrdtool--------------------------------------------------------------------------------------------------数据采集层net-snmp scriptCacti工作原理图:

全新linux系统安装以文本方式并自定义安装软件……………………省略…………………….去掉所有打勾然后把红色标记移到development tools

接下来按F2,跳出详细菜单选择OK就行了,

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

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

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

安装完后重启选择firewall configuration,禁用selinux

开放http-80端口

启动结束进入系统=====================================================================(大家也可以通过把yum源更换到光盘或centos资源库,具体可以参考我另外一篇bolg。http://viong.blog.51cto.com/844766/278402先yum mysql apache phpyum -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-DBIperl-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 startPHP配置(默认已都激活)激活PHP扩展/etc/php.iniExtension_dir=”usr/lib/php/modules”激活mysql扩展/etc/php.d/mysql.iniExtension=mysql.soApache配置(默认已支持)配置支持PHP:/etc/httpd/conf.d/php.confLoadModule php5_module modules/libphp5.soAddHandler php5-script .phpAddType text/html .phpDirectoryIndex index.phpMysql配置为mysql数据库root账号设置密码[root@cacti-qmail soft]#mysqladmin --user=root password viong0613[root@cacti-qmail soft]#mysqladmin --user=root --password reloadEnter password:输入刚设置密码,检验是否正确Rrdtool安装[root@cacti-qmail soft]#ll总计 1100-rw-r--r-- 1 rootroot 49815 02-22 22:18perl-rrdtool-1.2.23-1.el5.rf.i386.rpm-rw-r--r-- 1 rootroot955176 02-22 21:53rrdtool-1.2.23-1.el5.rf.i386.rpm-rw-r--r-- 1 rootroot 5542 02-22 22:01rrdtool-devel-1.2.23-1.el5.rf.i386.rpm-rw-r--r-- 1 rootroot 65566 2004-05-19 rzsz-3.48.tar.gzdrwxrwxr-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.rpmrrdtool-1.2.23-1.el5.rf.i386.rpm rrdtool-devel-1.2.23-1.el5.rf.i386.rpmwarning: perl-rrdtool-1.2.23-1.el5.rf.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6Preparing... ########################################### [100%]1:rrdtool ########################################### [ 33%]2:perl-rrdtool ########################################### [ 67%]3:rrdtool-devel ########################################### [100%]Cacti安装[root@cacti-qmail soft]# wget http://www.cacti.net/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 -pEnter 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<cacti.sql配置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.diffdrwxr-xr-x 5 root root4096 11-22 13:03 files-0.8.7e-rw-rw-rw- 1 root root 15237 2006-11-10 LICENSE-rw-rw-rw- 1 root root2037 2007-11-06 pa.sql-rw-rw-rw- 1 root root1230 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 <cacti-plugin-0.8.7e-PA-v2.6.diff[root@cacti-qmail cacti]# mysql -uroot -pviong0613 cacti<pa.sql[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.phpCacti的web初始化在浏览器输入http://192.168.15.67/cacti/登陆cacti

被监控主机snmp文件设置Linux被监控主机需要配置snmp.#vi /etc/snmp/snmpd.conf1更改com2sec notConfigUser default public改为com2sec notConfigUser 127.0.0.1 public2、更改access notConfigGroup "" any noauth exactsystemview none none改为access notConfigGroup "" any noauth exactall none none#view all included .1 80将前面的 # 注释 去掉。 保存退出测试snmp是否正常#snmpwalk -c public -v 2c localhost#snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndexIP-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

相关内容

    暂无相关文章