Cacti使用安装具体解释
Posted mthoutai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cacti使用安装具体解释相关的知识,希望对你有一定的参考价值。
Cacti是一套基于php,mysql,SNMP及RRDTool开发的网络流量监測图形分析工具。Cacti是通过 snmpget来获取数据。使用 RRDtool绘绘图形,而且你全然能够不须要了解RRDtool复杂的參数。它提供了很强大的数据和用户管理功能。能够指定每个用户能查看树状结构、host以及不论什么一张图。还能够与LDAP结合进行用户验证,同一时候也能自己增加模板。功能很强大完好。界面友好。
软件 Cacti 的发展是基于让 RRDTool 使用者更方便使用该软件,除了主要的 Snmp 流量跟系统资讯监控外。Cacti 也可外挂 Scripts 及加上 Templates 来作出各式各样的监控图。
cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户须要查看数据的时候用rrdtool生成图表呈现给用户。
因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。
Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、port号、模板信息等变量。
snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件里(在cacti根文件夹的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理。rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。
关于RRDTool的知识请參阅RRDTool教学。
前期准备工作:
Cacti官网:http://www.cacti.net/download_cacti.php
找到Linux/Unix in tar.gz format连接图标,
下载地址: http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
下载地址: http://www.cacti.net/downloads/spine/cacti-spine-0.8.8b.tar.gz
确保前期安装须要准备的软件:
- net-snmp-devel
- mysql
- mysql-devel
- openssl-devel
准备所须要的软件包
Apache http://www.apache.org/
Mysql http://www.mysql.com/
Php http://www.php.net
Rrdtool http://oss.oetiker.ch/rrdtool/
Net-snmp http://www.net-snmp.org/
Cacti http://www.cacti.net/
当中apache、mysql、php通过yum安装
以下简述安装过程:
一、安装RRDTool和SNMP
1 安装RRDTool
yum -y install rrdtool
启动rrdtool服务而且增加启动列表
service rrdcached start 失败报错:rrdcached: 未被识别的服务
chkconfig rrdcached on 失败
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.8.tar.gz
也chkconfig失败
2 安装snmp支持工具
能够yum安装。也能够源代码安装,比方
Wget http://sourceforge.net/projects/net-snmp/files/net-snmp/5.6.2.1/net-snmp-5.6.2.1.tar.gz/download
yum -y install net-snmp
yum -y install net-snmp-utils
启动snmpd服务而且增加启动列表
service snmpd start
chkconfig snmpd on
3 安装LAMP
[[email protected] ~]# yum -y install httpd mysql-server php php-mysql mysql-devel
[[email protected] ~]# chkconfig httpd on
[[email protected] ~]# chkconfig mysqld on
[[email protected] ~]# /etc/init.d/httpd start
[[email protected] ~]# /etc/init.d/mysqld start
启动完httpd之后,能够打开 http://10.xx.1.xx/。界面例如以下:
二、然后下载cacti
到这里去下载 wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
下载当前最新版 wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8b.tar.gz
和cacti-spine,http://www.cacti.net/downloads/spine/
下载当前最新版 cacti-spine,wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8b.tar.gz
三、開始安装cacti-spine
1,建立cacti用户
[[email protected] ~]# useradd -m cacti
[[email protected] ~]# passwd cacti
password:cacti
2,首先安装几个编译cacti-spine须要的devel包:
yum install net-snmp-devel -y
yum install mysql-devel -y
yum install openssl-devel -y
3。安装gcc和libtool
yum install gcc -y
yum install libtool -y
4,下载cactid并解压:
tar -xf cacti-spine-0.8.8b.tar.gz
编译安装:
cd cacti-spine-0.8.8b
aclocal
libtoolize --force
autoheader
autoconf
automake
./configure
make
make install
5,安装好以后。我们须要再配置一下:
vim /etc/spine.conf
DB_Host localhost
DB_Database cacti
DB_User cacti_user
DB_Pass cacti05261743
DB_Port 3306,
6。启动一下看看
#/usr/local/spine/bin/spine
一般显示
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8a starting
SPINE: Time: 0.1190 s, Threads: 5, Hosts: 2
7,创建mysql账号:
- mysql> set names utf8;
- Query OK, 0 rows affected (0.00 sec)
- mysql> create database cacti;
- Query OK, 1 row affected (0.09 sec)
- mysql>
- mysql> grant all on cacti.* to [email protected]\
登录mysql。删除掉’’@localhost以及’’@hostname这2个username为空串的mysql账号,就OK了。
- [[email protected] ~]$ /usr/local/spine/bin/spine
- SPINE: Using spine config file [/etc/spine.conf]
- MYSQL: Connection Failed: Error:\‘2002\‘, Message:\‘Can\‘t connect to local MySQL server through socket \‘/var/lib/mysql/mysql.sock\‘ (2)\‘
- MYSQL: Connection Failed: Error:\‘2002\‘, Message:\‘Can\‘t connect to local MySQL server through socket \‘/var/lib/mysql/mysql.sock\‘ (2)\‘
- MYSQL: Connection Failed: Error:\‘2002\‘, Message:\‘Can\‘t connect to local MySQL server through socket \‘/var/lib/mysql/mysql.sock\‘ (2)\‘
- MYSQL: Connection Failed: Error:\‘2002\‘, Message:\‘Can\‘t connect to local MySQL server through socket \‘/var/lib/mysql/mysql.sock\‘ (2)\‘
- MYSQL: Connection Failed: Error:\‘2002\‘, Message:\‘Can\‘t connect to local MySQL server through socket \‘/var/lib/mysql/mysql.sock\‘ (2)\‘
- 05/16/2014 04:11:43 PM - SPINE: Poller[0] FATAL: Connection Failed, Error:\‘2002\‘, Message:\‘Can\‘t connect to local MySQL server through socket \‘/var/lib/mysql/mysql.sock\‘ (2)\‘ (Spine init)
找到正在执行的mysql.sock的路径,做一个软连接:
- [[email protected] bin]# find / -name mysql.sock
- /usr/local/mysql/mysql.sock
- [[email protected] bin]#
- [[email protected] bin]# ln -s /usr/local/mysql/mysql.sock /var/lib/mysql/mysql.sock
- [[email protected] bin]#
再次启动,有报错例如以下:
- [[email protected] bin]# /usr/local/spine/bin/spine
- SPINE: Using spine config file [/etc/spine.conf]
- 05/16/2014 04:16:40 PM - SPINE: Poller[0] FATAL: MySQL Error:\‘1146\‘, Message:\‘Table \‘cacti.settings\‘ doesn\‘t exist\
须要导入默认的cacti.sql,解压缩.tar.gz,获得cacti.sql
- [[email protected] cacti-0.8.8b] tar -xvf cacti-0.8.8b.tar.gz
- [[email protected] cacti-0.8.8b] cd cacti-0.8.8b
- [[email protected] bin]# type mysql
- mysql is hashed (/usr/local/mysql/bin/mysql)
- [[email protected] cacti-0.8.8b]$
- mysql -u cacti_user -pcacti05261743 -h127.0.0.1 cacti </home/cacti/cacti-0.8.8b/cacti.sql
- [[email protected] cacti-0.8.8b]$ /usr/local/spine/bin/spine
- SPINE: Using spine config file [/etc/spine.conf]
- SPINE: Version 0.8.8b starting
- SPINE: Time: 0.1386 s, Threads: 5, Hosts: 2
- [[email protected] cacti-0.8.8b]$
启动成功了。
8。最后。等cacti安装完之后在cacti的web配置界面选择setting
settings->paths->Spine Poller File Path [/usr/local/spine/bin/spine]
settings->poller->Poller Type [spine]
console->settings->poller->Maximum Threads per Process [5]
save完毕。
四、我们開始安装正主cacti
1 配置
解压并放到apache文档文件夹(/var/www/html)
tar -xf cacti-0.8.8b.tar.gz
mv cacti-0.8.8b /var/www/html/cacti
cd /var/www/html/
编辑CentOS cacti配置文件,连接MySQL服务的username。password,port等。
- vim /var/www/html/cacti/include/config.php
- #
- $database_type = \"mysql\";
- $database_default = \"cacti\";
- $database_hostname = \"localhost\";
- $database_username = \"cacti_user\";
- $database_password = \"cacti_user05161610\";
- $database_port = \"3306\";
- $database_ssl = false;
2增加计划任务(使cacti每5分钟获得一次数据)
#crontab -e
*/1 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1 //让系统每1分钟收集
3 数据库配置
在前面的第三步已经配置好了。创建数据库cacti以及用户。
4 測试,建立一个login.jsp文件
[[email protected] cacti]# vim login.php
simple demo
<?
php
phpinfo();
?>
例如以下图所看到的:
打开网址页面:
启动完httpd之后,能够打开 http://10.xx.1.xx/,界面例如以下:
遇到的小问题,打开index.php是空页面,例如以下所看到的:
去查看日志。日志没有不论什么信息:
问题在哪里呢?
找到apache的配置文件httpd.conf
- [[email protected] www]# vim /etc/httpd/conf/httpd.conf
- Search error_log
- 日志路径 /var/log/httpd/error_log
- [[email protected] cacti]# cd /var/log/httpd/
- [[email protected] httpd]# ll
- 总计 20
- -rw-r--r-- 1 root root 9228 05-16 18:39 access_log
- -rw-r--r-- 1 root root 2049 05-16 18:14 error_log
- -rw-r--r-- 1 root root 0 05-16 17:18 ssl_access_log
- -rw-r--r-- 1 root root 1422 05-16 18:14 ssl_error_log
- -rw-r--r-- 1 root root 0 05-16 17:18 ssl_request_log
逐个查看log信息。在ssl_error_log里面发现错误信息:
- [[email protected] httpd]# tail -f ssl_error_log
- [Fri May 16 18:00:36 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
- [Fri May 16 18:00:36 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain\‘ does NOT match server name!?
- [Fri May 16 18:14:39 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
- [Fri May 16 18:14:39 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain\‘ does NOT match server
- [Fri May 16 18:14:39 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?
)
- [Fri May 16 18:14:39 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain\‘ does NOT match server name!?
- [Fri May 16 18:48:48 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
- [Fri May 16 18:48:48 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain\‘ does NOT match server
- [Fri May 16 18:48:48 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
- [Fri May 16 18:48:48 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain\
经过朋友的提醒,还须要安装php-mysql组件
[[email protected] httpd]# yum install -y php-mysql
之后,再打开页面,http://10.254.1.12/cacti/install/。就有信息例如以下:
点击next。继续下一步,其它的都死默认选项,默认登录usernamepassword是admin:
五:Cacti监控mysql报表流量图:
wget https://mysql-cacti-templates.googlecode.com/files/better-cacti-templates-1.1.8.tar.gz
tar –xvf better-cacti-templates-1.1.8.tar.gz
cd better-cacti-templates-1.1.8
将better-cacti-templates-1.1.8\scripts下的 ss_get_mysql_stats.php 这个脚本 这个脚本须要放在cacti的服务端。
比方cacti部署在/var/www/html文件夹下,那么就cp到/var/www/html/cacti/scripts/下
cp /root/better-cacti-templates-1.1.8/scripts/ss_get_mysql_stats.php /var/www/html/cacti/scripts/
改动ss_get_mysql_stats.php 文件 第30行
$mysql_user = ‘cacti_user‘;
$mysql_pass = ‘cacti_user05161610‘;
$cache_dir = "/xok.la/cacti/cache/";
chown -R apache.apache /var/www/html/cacti/scripts
chmod -R 755 /var/www/html/cacti/scripts
使用 http 訪问 cacti主机 导入
/opt/mysql-cacti-templates-1.1.2/cacti_host_template_x_db_server_ht_0.8.6i.xml
然后创建mysql用户:
grant process,super on *.* to ‘cacti_user‘@‘%‘ identified by ‘cacti_user05161610‘;
以上是关于Cacti使用安装具体解释的主要内容,如果未能解决你的问题,请参考以下文章