首页 > 代码库 > cacti监控的搭建

cacti监控的搭建

目前线上使用的是nagios监控,但是最近有监控交换机流量并且能够图像化监控的需求,虽然nagios能够实现监控但在画图方面无法满足需求,而mrtg画出的图无法满足我们自由查看某个时间段流量的需求;所以我们还是果断使用cacti吧,既能够完美画图,也符合我们日后nagios和cacti整合,以实现更细致的监控,下面就来了解下吧。

一.利用yum来安装lamp环境。

1.安装mysql-5.6数据库

[root@usvr-133 ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
[root@usvr-133 ~]# yum install mysql-community-server
[root@usvr-133 ~]# rpm -qa |grep mysql
mysql-community-release-el6-5.noarch
mysql-community-libs-compat-5.6.22-2.el6.x86_64
mysql-community-libs-5.6.22-2.el6.x86_64
mysql-community-client-5.6.22-2.el6.x86_64
mysql-community-server-5.6.22-2.el6.x86_64
php-mysql-5.3.3-40.el6_6.x86_64
mysql-community-common-5.6.22-2.el6.x86_64

2.安装apache

[root@usvr-133 ~]# yum -y install httpd 
[root@usvr-133 ~]# rpm -qa |grep httpd
httpd-tools-2.2.15-39.el6.centos.x86_64
httpd-2.2.15-39.el6.centos.x86_64
3.安装php

[root@usvr-133 ~]# yum -y install php php-mysql^C
[root@usvr-133 ~]# rpm -qa |grep php
php-5.3.3-40.el6_6.x86_64
php-gd-5.3.3-40.el6_6.x86_64
php-common-5.3.3-40.el6_6.x86_64
php-cli-5.3.3-40.el6_6.x86_64
php-mysql-5.3.3-40.el6_6.x86_64
php-pdo-5.3.3-40.el6_6.x86_64
4.安装需要的库文件

[root@usvr-133 ~]# yum -y install zlib
[root@usvr-133 ~]# yum -y install freetype
[root@usvr-133 ~]# yum -y install libjpeg
[root@usvr-133 ~]# yum -y install fontconfig
[root@usvr-133 ~]# yum -y install gd
[root@usvr-133 ~]# yum -y install libxml2
[root@usvr-133 ~]# yum -y install zlib freetype libjpeg fontconfig gd libxml2 php-gd
二.安装rrd工具

[root@usvr-133 ~]# yum -y install rrdtool rrdtool-devel
[root@usvr-133 ~]# rpm -qa |grep rrd
rrdtool-1.3.8-7.el6.x86_64
rrdtool-devel-1.3.8-7.el6.x86_64
三.安装并配置监控需要的snmp工具

1.安装

[root@usvr-133 ~]# yum -y install net-snmp net-snmp-devel net-snmp-utils
[root@usvr-133 ~]# rpm -qa |grep net-snmp
net-snmp-libs-5.5-50.el6_6.1.x86_64
net-snmp-devel-5.5-50.el6_6.1.x86_64
net-snmp-5.5-50.el6_6.1.x86_64
net-snmp-utils-5.5-50.el6_6.1.x86_64
2.配置snmp

[root@usvr-133 ~]# vim /etc/snmp/snmpd.conf
com2sec notConfigUser  default       public
改为:com2sec notConfigUser  127.0.0.1       public
access  notConfigGroup ""      any       noauth    exact  systemview none none
改为:access  notConfigGroup ""      any       noauth    exact  all none none
#view all    included  .1                               80	去掉注释
以上完成后启动相关服务

[root@usvr-133 ~]# service httpd start
[root@usvr-133 ~]# service mysqld start
[root@usvr-133 ~]# service snmpd start
四.安装并配置cacti

1.安装cacti

[root@usvr-133 ~]# wget http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz -P /usr/local/src
[root@usvr-133 ~]# cd /usr/local/src
[root@usvr-133 ~]# tar -zxvf cacti-0.8.7e.tar.gz
[root@usvr-133 ~]# mv cacti-0.8.7e /var/html/www/cacti
2.配置mysql

[root@usvr-133 ~]# mysql -u root
mysql> create database cacti;
grant all on cacti.* to cacti@localhost identified by 'cacti';
grant all on cacti.* to cacti@127.0.0.1 identified by 'cacti';
use cacti;
source /var/www/html/cacti/cacti.sql; #创建相关表
flush privileges;
在执行cacti.sql时报错:ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘TYPE=MyISAM’ at line 6.

这是由于mysql查询语句写法TYPE=MyISAM太老了,在mysql5.5上已经被禁用,将安装程序的TYPE=MyISAM全部改成ENGINE=MyISAM即可。

3.配置cacti

[root@usvr-133 ~]# vim /var/www/html/cacti/include/config.php 
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
4.设置相关权限

useradd cacti -d /var/www/html/cacti -s /bin/false
chown -R cacti /var/www/html/cacti/rra /var/www/html/cacti/log
5.设置计划任务

[root@usvr-133 ~]# cat /etc/crontab
*/5 * * * * root /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
五.初始化cacti

1.访问http://192.168.3.133/cacti

技术分享

2.直接点击next

技术分享

3.直接点击next

技术分享

4.直接点击finish

技术分享

5.输入默认用户名admin 密码admin,进入后需要先重新修改密码

技术分享

6.ok,已经进入页面,我们点击左上角的“graphs”,会出现监控的坐标轴。

技术分享

注:若没有出现坐标轴或是出现"X"图片无法显示,则需要查看apache错误日志,或直接运行/usr/bin/php /var/www/html/cacti/poller.php ,查看报错内容,主要是由于php版本过高导致,需要修改下源代码以适应新版本的语法。

(1)查看错误日志PHP Warning:  date(): It is not safe to rely on the system‘s timezone settings

vim /etc/php.ini

date.timezone =‘Asia/Shanghai‘

(2)直接运行/usr/bin/php /var/www/html/cacti/poller.php报错PHP Deprecated:  Assigning the return value of new by reference is deprecated in /var/www/html/cacti/lib/adodb/adodb.inc.php on line 866

vim /var/www/html/cacti/lib/adodb/adodb.inc.php  由于php5.3不支持“=&”,将所有的“=&”改为“=”

(3)日志报错PHP Deprecated:  Function split() is deprecated in /var/www/html/cacti/poller.php on line 77

还是由于版本的问题

vim /etc/php.ini

; error_reporting
;   Default Value: E_ALL & ~E_NOTICE
;   Development Value: E_ALL | E_STRICT
;   Production Value: E_ALL & ~E_DEPRECATED
error_reporting = E_ALL & ~E_DEPRECATED
修改完后重启apache即可,来看下图像是否全都显示。






cacti监控的搭建