前言:
Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。它通过snmpget来获取数据,使用RRDtool绘画图形,其功能相當完善,界面友好。Cacti最初是基于Linux的,但如果你對LINUX了解不多,比如像我一樣,那么你最好不要使用Cacti for Linux,自然CactiEZ例外,因為即使你在Linux上能夠按安裝步驟安裝,安裝中出現的任何問題,哪怕它再小,也會讓你備受折磨,所以使用CactiEZ吧,或者Cacti for Windows也行。另外以下安裝方法,只保證在Redhat Desktop 9可行,在后面會提及原因。 準備工作:
Linux平台:CentOS6.5
PHP+MySQL+SNMP:CentOS6.5自帶安裝包
Cacti:cacti-0.8.7e.tar.gz
Rrdtool:rrdtool-1.3.8-10.el6.i686
rrdtool-perl-1.3.8-10.el6.i686 Samba或vsftp:便于安裝過程中上傳文件,我使用的是samba 直接yum –y install lftp Yum:很多軟件使用yum安裝,事先配置好yum源會方便很多
步驟:
為你的監控電腦安裝Linux操作系統,在安裝過程中有詢問需要安裝那些軟件包,個人建議全選,因為PHP+MySQL+SNMP除了幾個安裝包外,還有十幾個Installing package for dependencies,漏選一個都麻煩,而且,你會在意硬盤多耗兩G空間?!所以,全選吧。如果你安装的不是Redhat Desktop 9,比如Linux4.0或Linux 5.0,那么你需要在安装的过程中将SELinux(Security-EnhancedLinux)选为disable,虽然SELinux能够在一定程度上保证系统的安全,但它对于进程只赋予最小的权限,会导致在安装后RRDtool调运拒绝,而无法正常运行出图。 - 架設PHP+MySQL+SNMP平臺
搭建LAMP环境环境
如果你按我上面说的,在安装Linux的过程中勾选了全部软件包,那么你现在会轻松很多,如果你没有的话,那么你得找回Linux安装盘,并使用yum -y install httpd mysql php mysql-serverphp-mysql net-snmp将其一一安装,LAMP环境就搭建好了。 2.启动服务
[iyunv@cacti html]# /etc/init.d/httpd start
[iyunv@cacti html]# /etc/init.d/mysqld start [iyunv@cacti html]# /etc/init.d/snmpd start 3.设置服务开机自启动
[iyunv@cacti ~]# chkconfig httpd on [iyunv@cacti ~]# chkconfig mysqld on [iyunv@cacti ~]# chkconfig snmpd on 当然你也可以直接使用setup命令,在system services里面直接勾选。 4.测试php、Mysql 在/var/www/html/内创建一个如下php.php文件测试php。 [iyunv@cacti html]#vi php.php #插入内容如下 <?php
phpinfo();
?> 浏览器测试http://服务器IP/php.php,如果能看到PHP信息则PHP环境搭建好了。 测试Mysql:打mysql命令能看到mysql>提示符就行了。 如果你使用的是.rpm安装包,那么按以下方式安装 [iyunv@cacti ~]# yum install libart_lgpl.i386libart_lgpl-devel.i386 [iyunv@cacti ~]#
rpm -ivh rrdtool-1.3.8-10.el6.i686rrdtool-perl-1.3.8-10.el6.i686
如果使用的是.tar.gz或者.tar.tar安装包,使用以下方式安装 [iyunv@cacti ~]# tar -zxvf rrdtool-1.2.25.tar.tar [iyunv@cacti ~]# cd rrdtool-1.2.25 [iyunv@cacti ~]# ./configure-prefix=/usr/local/rrdtool [iyunv@cacti ~]# make [iyunv@cacti ~]# make install 创建一个执行监控用的用户cactiuser [iyunv@ cacti ~]# useradd –p 你的密码-s /sbin/bash cactiuser -p指定密码 –s指定登录shell 然后进入mysql配置cacti数据库
mysql>create database cactidb; #创建database
Query OK, 1 row affected (0.00 sec) mysql>grant all on cactidb.* to root; #授权root用户所有权限
Query OK, 0 rows affected (0.01 sec) mysql>grant all on cactidb.* to root@localhost;
Query OK, 0 rows affected (0.01 sec) mysql>grant all on cactidb.* to cactiuser; #授权cactiuser
Query OK, 0 rows affected (0.00 sec) mysql>grant all on cactidb.* to cactiuser@localhost;
Query OK, 0 rows affected (0.01 sec) mysql>set password for cactiuser@localhost=password(’你的密码’);
Query OK, 0 rows affected (0.00 sec) mysql>exit [iyunv@cacti tasks]# tar -xzvf cacti-0.8.7b #解压cacti-0.8.7b ; [iyunv@cacti tasks]# mv cacti-0.8.7b/var/www/html/cacti #移动cacti文件夹到/var/www/html 目录并改名cacti; [iyunv@cacti cacti]# cd /var/www/html/cacti/ #进入cacti目录; [iyunv@cacti cacti]# mysql -u root -pcactidb<cacti.sql #执行cacti.sql语句并导入到cactidb数据库中; 编辑配置文件,具体根据实际情况:
[iyunv@cacti cacti]#vi /var/www/cacti/include/config.php $database_type = “mysql”;
$database_default = “cactidb”;
$database_hostname = “localhost”;
$database_username = “cactiuser”;
$database_password = “你的密码”; 为cactiuser用户加入数据更新,5分钟取一次。 [iyunv@cacti cacti]#crontab –u cactiuser –e 插入以下内容并保存
*/5 * * * * php -f /var/www/html/cacti/poller.php>/dev/null 2>&1 注意用户权限,如果是root用户就直接crontab –e 。 进入cacti页面进行初始化安装。 http://服务器IP/cacti 如果无法访问提示没有权限,请查看cacti文件夹是否赋予apache用户和组权限,因为默认访问cacti服务器的用户为apache。 RRDTool根据你安装的方式不同,RRDTool Binary Path可能需要更改,不然可能会出现RRDTOOL无法找到的现象。
初始用户名admin 密码admin 初次要更改密码: 进入初始页面,没有添加模板之前cacti页面只有console 和graphs两个选项。 但在安装插件时,必须先安装cacti的一个patch--Plugin Architecture 安装cacti-plugin-arch: [iyunv@cacti tasks]#tar -zxvf cacti-plugin-arch.tar.gz [iyunv@cacti tasks]#cp -a cacti-plugin-arch /var/www/html/cacti/ [iyunv@cacti tasks]#cd /var/www/html/cacti/ [iyunv@cacti cacti]#cp cacti-plugin-0.8.7b-PA-v2.1.diff /var/www/html/cacti/ [iyunv@cacti cacti]#patch -p1 -N <cacti-plugin-0.8.7b-PA-v2.1.diff 编辑include/global.php 文件: [iyunv@cacti cacti]#vi include/global.php 在 $plugins = array(); 下面加上:
$plugins[] = ‘thold’;
$plugins[] = ‘monitor’; //如果安装monitor的话 保存即可。 注意:有些插件默认不显示在页面上,需要在user managerment里将ViewThresholds或View minitore选择上。 具体安装过程如下: vi /var/www/html/cacti/include/config.php /* Default session name – Session name must containalpha characters */
#$cacti_session_name = "Cacti";
#在此处增加下面内容
$plugins = array();
$plugins[] = ‘thold’;
$plugins[] = ‘monitor’;
$plugins[] = ‘settings’;
$plugins[] = ‘update’;
?> 亦可在include/global.php 文件中添加,作用是一样的。
|