一、Cacti简介
Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。
简单的说Cacti 就是一个PHP 程序。它通过使用SNMP 协议获取远端网络设备和相关信息,(其实就是使用Net-SNMP 软件包的snmpget 和snmpwalk 命令获取)并通过Rrdtool 工具绘图,通过PHP 程序展现出来。我们使用它可以展现出监控对象一段时间内的状态或者性能趋势图。
二、准备和配置
1.准备所需要的软件包,apache、mysql、php、snmp通过yum安装
Rrdtool官网:http://oss.oetiker.ch/rrdtool/
Cacti官网:http://www.cacti.net/
[[email protected] ~]#yum -y install httpd
[[email protected] ~]#yum -y install mysql mysql-server mysql-devel
[[email protected] ~]#yum -y install php php-devel php-mysql php-pdo php-gd
[[email protected] ~]#yum -y install net-snmp php-snmp net-snmp-utils net-snmp-devel net-snmp-perl
[[email protected] ~]#yum -y install gcc gcc-c++
[[email protected] ~]#yum -y install libxml2-devel
[[email protected] ~]#yum -y install pango-devel pango
报错:由于我的yum不能安装这两个文件,我用光盘装了下
pango-devel-1.14.9-8.el5.centos.3.i386 from base has depsolving problems
--> Missing Dependency: pango = 1.14.9-8.el5.centos.3 is needed by package pango-devel-1.14.9-8.el5.centos.3.i386 (base)
Error: Missing Dependency: pango = 1.14.9-8.el5.centos.3 is needed by package pango-devel-1.14.9-8.el5.centos.3.i386 (base)
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest
挂载光盘到/mnt下
[[email protected] ~]#mount /dev/cdrom /mnt/
[[email protected] ~]# find /mnt/ -name "pango*rpm"
[[email protected] ~]#/mnt/CentOS/pango-1.14.9-6.el5.centos.i386.rpm
[[email protected] ~]#/mnt/CentOS/pango-devel-1.14.9-6.el5.centos.i386.rpm
[[email protected] ~]#rpm -ivh /mnt/CentOS/pango-1.14.9-6.el5.centos.i386.rpm
[[email protected] ~]#rpm -ivh /mnt/CentOS/pango-devel-1.14.9-6.el5.centos.i386.rpm
又报错,这是因为有依赖关系
[[email protected]alhost ~]# rpm -ivh /mnt/CentOS/pango-devel-1.14.9-6.el5.centos.i386.rpm
error: Failed dependencies:
cairo-devel >= 1.2.2 is needed by pango-devel-1.14.9-6.el5.centos.i386
fontconfig-devel >= 2.0 is needed by pango-devel-1.14.9-6.el5.centos.i386
freetype-devel >= 2.1.3-3 is needed by pango-devel-1.14.9-6.el5.centos.i386
glib2-devel >= 2.12.0-1 is needed by pango-devel-1.14.9-6.el5.centos.i386
libX11-devel is needed by pango-devel-1.14.9-6.el5.centos.i386
libXext-devel is needed by pango-devel-1.14.9-6.el5.centos.i386
libXft-devel is needed by pango-devel-1.14.9-6.el5.centos.i386
libXrender-devel is needed by pango-devel-1.14.9-6.el5.centos.i386
[[email protected] ~]#yum -y install cairo-devel fontconfig-devel freetype-devel glib2-devel libX11-devel libXext-devel libXft-devel libXrender-devel
继续安装
[[email protected] ~]#rpm -ivh /mnt/CentOS/pango-devel-1.14.9-6.el5.centos.i386.rpm
2.安装rrdtool
[[email protected] ~]#tar zxvf rrdtool-1.4.5.tar.gz
[[email protected] ~]#cd rrdtool-1.4.5
[[email protected] ~]#./configure --prefix=/usr/local/rrdtool
[[email protected] ~]#make && make install
[[email protected] ~]#ln -s /usr/local/rrdtool/bin/* /usr/local/bin/
3.安装cacti
[[email protected] ~]#tar zxvf cacti-0.8.8c.tar.gz
[[email protected] ~]#useradd -d /var/www/html/cacti cacti -s /sbin/nologin
[[email protected] ~]#mv cacti-0.8.8c/* /var/www/html/cacti
[[email protected] ~]#chown -R cacti:cacti /var/www/html/cacti
[[email protected] ~]#chmod 755 -R /var/www/html/cacti
4.安装轮询器:cacti-spine
[[email protected] ~]#tar zxvf cacti-spine-0.8.8c.tar.gz
[[email protected] ~]#cd cacti-spine-0.8.8c
[[email protected] ~]#./configure --prefix=/usr/local/spine
[[email protected] ~]#make && make install
报错:
[[email protected] cacti-spine-0.8.8c]# ./configure --prefix=/usr/local/spine
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... configure: error: newly created file is older than distributed files!
Check your system clock
设置时间2015年3月6号16:21
[[email protected] ~]# date -s "2015-03-06 16:21:40"
修改完后,输入:[[email protected] ~]#clock -w
把系统时间写入CMOS
5.拷贝配置文件
[[email protected] ~]#cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
6.重启服务
[[email protected] ~]#service httpd restart
[[email protected] ~]#service snmpd restart
[[email protected] ~]#service mysqld restart
7.修改mysql的root密码
[[email protected] ~]#/etc/init.d/mysqld start
修改mysql root密码为123456
[[email protected] ~]#mysqladmin -u root password "123456"
登录mysql测试
[[email protected] ~]#mysql -uroot -p123456
8.配置并导入数据库
mysql> create database cacti default character set utf8;
mysql> GRANT ALL privileges ON cacti.* TO [email protected] IDENTIFIED BY ‘123456‘;
mysql> flush privileges;
[[email protected] ~]# mysql -uroot -p cacti</var/www/html/cacti/cacti.sql
9.修改php配置文件
[[email protected] ~]#vi /etc/php.ini
添加时区: date.timezone = Asia/ShangHai
定时计划任务(这里很重要,出错了可能会导致你的网页监控刷新不了)
*/1 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /var/log/cacti.log 2>&1
10.修改cacti配置文件
[[email protected] ~]#vi /var/www/html/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;
11.修改轮训器配置文件:
# vi /usr/local/spine/etc/spine.conf
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass 123456
DB_Port 3306
DB_PreG 0
12.设置selinux为disabled
[[email protected] ~]# cat /etc/selinux/config
[[email protected] ~]#setenforce 0
13.访问web
http://192.168.88.150/cacti/
安装完成,默认用户名和密码是admin,第一次登录会要求更改密码
14.出图要等一会的
查看如果有图,没有曲线,重启apache,/usr/bin/php /var/www/html/cacti/poller.php
tail -f /var/log/messages
三、配置被监控Linux主机
1.在被监控主机上
[[email protected] ~]#egrep -v "^$|#" /etc/snmp/snmpd.conf
com2sec notConfigUser default public
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
access notConfigGroup "" any noauth exact all none none
view all included .1 80
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <[email protected]> (configure /etc/snmp/snmp.local.conf)
dontLogTCPWrappersConnects yes
2.重启snmpd服务
[[email protected] ~]#service snmpd restart
四、图形界面配置可以参考下面链接
http://www.linuxidc.com/Linux/2012-07/66918.htm