cacti的介绍、安装、配置、及维护
一、cacti的介绍
Cacti 在英文中的意思是仙人掌的意思,Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。它通过snmpget来获取数据,使用 RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数。它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结 构、host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,功能非常强大完善。
cacti工作流程图:
具体详见cacti官网:http://www.cacti.net/
cacti 安装环境:Cacti requires MySQL, PHP, RRDTool, net-snmp, and a webserver that supports PHP such as Apache or IIS.
二、安装:
1、配置LAMP环境
yum -y install mysql mysql-server mysql-devel
yum -y install httpd php php-mysql
2、安装rrdtool工具和SNMP包
检查安装依赖包:yum -y install zlib freetype libjpeg fontconfig gd libxml2 php-gd
rrdtool安装:yum -y install perl-Net-Daemon perl-PlRPC perl-DBI rrdtool perl-rrdtool perl-DBD-MySQL
snmp安装:yum -y install php-pdo lm_sensors net-snmp php-snmp net-snmp-utils
3、cacti安装
tar -zxvf cacti-0.8.8b.tar.gz
mv cacti-0.8.8b /var/www/html/cacti
4、配置cacti
a>配置httpd服务
vim /etc/httpd/conf.d/cacti.conf (添加如下行,或在/etc/httpd/conf/httpd.conf)
Alias /cacti /var/www/html/cacti
<Directory /var/www/html/cacti>
DirectoryIndex index.php
AllowOverride all
order deny,allow
deny from all
allow from all
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc on
php_flag track_vars on
</Directory>
vim /etc/httpd/conf/httpd.conf (修改如下行:)
ServerName localhost:80 (276行)
vim /etc/php.ini
date.timezone = PRC (946行)
启动httpd服务:service httpd start
b>配置mysql并导入cacti.sql
service mysqld start
mysqladmin -u root password '123456' (设置数据库密码)
mysql -uroot -p123456
1 mysql> create database cacti;
2 mysql> grant all on cacti.* to cacti@'localhost' identified by '123456';
3 mysql> flush privileges;
mysql -u cacti -p123456 -D cacti < /var/www/html/cacti/cacti.sql (导入数据库)
c>安装配置snmpd服务
vim /etc/snmp/snmpd.conf (修改如下行:)
1 41 com2sec notConfigUser 127.0.0.1 public 2 62 access notConfigGroup "" any noauth exact all none none 3 85 view all included .1 80
启动snmpd服务:service snmpd start
d> 配置cacti目录权限
useradd cacti -d /var/www/html/cacti -s /bin/false
chown -R root:root /var/www/html/cacti/
chown -R cacti:cacti /var/www/html/cacti/rra /var/www/html/cacti/log
e> 配置cacti连接数据库
vim /var/www/html/cacti/include/config.php
1 $database_type = "mysql"; 2 $database_default = "cacti"; 3 $database_hostname = "localhost"; 4 $database_username = "cacti"; 5 $database_password = "123456"; (cacti密码:grant allon cacti.* to cacti@'localhost' identified by'123456';)
6 $database_port = "3306";
7 $database_ssl = false;
f> 配置完成,设置服务开机自启动
chkconfig httpd on
chkconfig mysqld on
chkconfig snmpd on
g> 配置cron计划任务
crontab -u cacti -e
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php &>/dev/null
5.插件setting,thold,monitor 安装:
下载地址:http://docs.cacti.net/plugins
在安装thold插件,必须先安装settings插件,后安装thold插件。因为settings插件提供email的相关设置,thold插件的报警功能是根据settings里的设置来决定发送邮的。
1 tar xf settings-v0.71-1.tgz -C /var/www/html/cacti/plugins
2 tar xf thold-v0.4.9-3.tgz -C /var/www/html/cacti/plugins
3 tar xf monitor-v1.3-1.tgz -C /var/www/html/cacti/plugins
vim /var/www/html/cacti/include/config.php
//$url_path = "/cacti/"; 在这一行下面添加一行
$plugins[] = 'settings';
$plugins[] = 'thold';
$plugins[] = 'monitor';
保存后,打开cacti网页,
保证最后一个页面没有红色报错,完成。
首次登陆用户名密码:admin、admin
启用插件console-->plugin management-->将插件安装与启用,如下图表示已经正确启用。
a>设置邮件报警通知
# 设置邮件发送服务:https://www.cnblogs.com/weijie0717/p/10309584.html
在Console---->setting------>mail/DNS中修改!选择 Mail Services :SMTP
7.安装spine
下载地址:http://www.cacti.net/downloads/spine/
tar zxf cacti-spine-0.8.8b.tar.gz
cd cacti-spine-0.8.8b
./configure --prefix=/usr/local/cacti-spine
如果安装报错:configure: error: Cannot find SNMP headers. Use --with-snmp= to specify non-default path.
解决方案:
#yum -y install net-snmp-devel
重新执行:
1 #./configure --prefix=/usr/local/cacti-spine
2 #make && make install
3 #cd /usr/local/cacti-spine/etc/
4 #cp spine.conf.dist spine.conf
#vim spine.conf
1 DB_Host localhost
2 DB_Database cacti
3 DB_User cacti
4 DB_Pass 123456
5 DB_Port 3306
6 DB_PreG 0
使用:#/usr/local/cacti-spine/bin/spine --conf=/usr/local/cacti-spine/etc/spine.conf 命令测试spine是否正确安装,如果输入下面信息表示安装成功:
SPINE: Using spine config file [/usr/local/cacti-spine/etc/spine.conf]
SPINE: Version 0.8.8b starting
SPINE: Time: 0.2112 s, Threads: 5, Hosts: 4
打开cacti网页 Console->setting-> poller 将poller type 改为:spine
setting-> Paths-->Spine Poller File Path添加路径: /usr/local/cacti-spine/bin/spine 保存。
8.安装 weathermap 插件
weathermap是cacti中大家使用最多的插件之一,用它可以制作出漂亮的网络拓扑图,并且可以使点到点之间的流量表现的更加直观具体。
安装weathermap包:
1 wget http://network-weathermap.com/files/php-weathermap-0.97c.zip
2
3 unzip php-weathermap-0.97c.zip -d /var/www/html/cacti/plugins
4
5 chown -R apache:apache /var/www/html/cacti/plugins/weathermap/configs/
6
7 chown -R apache:apache /var/www/html/cacti/plugins/weathermap/output/
启用插件console-->plugin management-->将插件安装与启用,如下图表示已经正确启用。
vim /var/www/html/cacti/include/config.php
//$url_path = "/cacti/"; 在这一行下面添加一行
$plugins[] = 'weathermap';
如果出现如下错误:
修改 /var/www/html/cacti/plugins/weathermap/editor.php
$ENABLED=false 改为 true。
$ignore_cacti=False 改为:true
点击:Editor