search
HomeDatabaseMysql TutorialCacti使用安装详解_MySQL

      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团体名、端口号、模板信息等变量。

       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

[root@cacti ~]# yum -y install httpd mysql-server php php-mysql mysql-devel

[root@cacti ~]# chkconfig httpd on

[root@cacti ~]# chkconfig mysqld on

[root@cacti ~]# /etc/init.d/httpd start

[root@cacti ~]# /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用户

[root@squid-2 ~]# useradd -m cacti

[root@squid-2 ~]# passwd 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账号:

  1. mysql> set names utf8;
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> create database cacti;
  4. Query OK, 1 row affected (0.09 sec)
  5. mysql>
  6. mysql> grant all on cacti.* to cacti_user@/

登录mysql,删除掉’’@localhost以及’’@hostname这2个用户名为空串的mysql账号,就OK了。

  1. [cacti@squid-2 ~]$ /usr/local/spine/bin/spine
  2. SPINE: Using spine config file [/etc/spine.conf]
  3. MYSQL: Connection Failed: Error:/'2002/', Message:/'Can/'t connect to local MySQL server through socket /'/var/lib/mysql/mysql.sock/' (2)/'
  4. MYSQL: Connection Failed: Error:/'2002/', Message:/'Can/'t connect to local MySQL server through socket /'/var/lib/mysql/mysql.sock/' (2)/'
  5. MYSQL: Connection Failed: Error:/'2002/', Message:/'Can/'t connect to local MySQL server through socket /'/var/lib/mysql/mysql.sock/' (2)/'
  6. MYSQL: Connection Failed: Error:/'2002/', Message:/'Can/'t connect to local MySQL server through socket /'/var/lib/mysql/mysql.sock/' (2)/'
  7. MYSQL: Connection Failed: Error:/'2002/', Message:/'Can/'t connect to local MySQL server through socket /'/var/lib/mysql/mysql.sock/' (2)/'
  8. 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的路径,做一个软连接:

  1. [root@mysqlvm2 bin]# find / -name mysql.sock
  2. /usr/local/mysql/mysql.sock
  3. [root@mysqlvm2 bin]#
  4. [root@mysqlvm2 bin]# ln -s /usr/local/mysql/mysql.sock /var/lib/mysql/mysql.sock
  5. [root@mysqlvm2 bin]#

再次启动,有报错如下:

  1. [root@mysqlvm2 bin]# /usr/local/spine/bin/spine
  2. SPINE: Using spine config file [/etc/spine.conf]
  3. 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

  1. [cacti@squid-2 cacti-0.8.8b] tar -xvf cacti-0.8.8b.tar.gz
  2. [cacti@squid-2 cacti-0.8.8b] cd cacti-0.8.8b
  3. [root@mysqlvm2 bin]# type mysql
  4. mysql is hashed (/usr/local/mysql/bin/mysql)
  5. [cacti@squid-2 cacti-0.8.8b]$
  6. mysql -u cacti_user -pcacti05261743 -h127.0.0.1 cacti /cacti/cacti-0.8.8b/cacti.sql
  7. [cacti@squid-2 cacti-0.8.8b]$ /usr/local/spine/bin/spine
  8. SPINE: Using spine config file [/etc/spine.conf]
  9. SPINE: Version 0.8.8b starting
  10. SPINE: Time: 0.1386 s, Threads: 5, Hosts: 2
  11. [cacti@squid-2 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服务的用户名,密码,端口等。

  1. vim /var/www/html/cacti/include/config.php
  2. #
  3.  $database_type = /"mysql/";
  4. $database_default = /"cacti/";
  5. $database_hostname = /"localhost/";
  6. $database_username = /"cacti_user/";
  7. $database_password = /"cacti_user05161610/";
  8. $database_port = /"3306/";
  9. $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文件

[root@mysqlvm2 cacti]# vim login.php

simple demo

phpinfo();

?>

如下图所示:

打开网址页面:
启动完httpd之后,可以打开  http://10.xx.1.xx/,界面如下:

遇到的小问题,打开index.php是空页面,如下所示:

去查看日志,日志没有任何信息:


问题在哪里呢?

找到apache的配置文件httpd.conf

  1. [root@mysqlvm2 www]# vim /etc/httpd/conf/httpd.conf
  2. Search error_log
  3. 日志路径 /var/log/httpd/error_log
  4. [root@mysqlvm2 cacti]# cd /var/log/httpd/
  5. [root@mysqlvm2 httpd]# ll
  6. 总计 20
  7. -rw-r--r-- 1 root root 9228 05-16 18:39 access_log
  8. -rw-r--r-- 1 root root 2049 05-16 18:14 error_log
  9. -rw-r--r-- 1 root root 0 05-16 17:18 ssl_access_log
  10. -rw-r--r-- 1 root root 1422 05-16 18:14 ssl_error_log
  11. -rw-r--r-- 1 root root 0 05-16 17:18 ssl_request_log

逐个查看log信息,在ssl_error_log里面发现错误信息:

  1. [root@mysqlvm2 httpd]# tail -f ssl_error_log
  2. [Fri May 16 18:00:36 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
  3. [Fri May 16 18:00:36 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain/' does NOT match server name!?
  4. [Fri May 16 18:14:39 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
  5. [Fri May 16 18:14:39 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain/' does NOT match server 
  6. [Fri May 16 18:14:39 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
  7. [Fri May 16 18:14:39 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain/' does NOT match server name!?
  8. [Fri May 16 18:48:48 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
  9. [Fri May 16 18:48:48 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain/' does NOT match server 
  10. [Fri May 16 18:48:48 2014] [warn] RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
  11. [Fri May 16 18:48:48 2014] [warn] RSA server certificate CommonName (CN) `localhost.localdomain/

经过朋友的提醒,还需要安装php-mysql组件

[root@mysqlvm2 httpd]# yum install -y php-mysql

之后,再打开页面,http://10.254.1.12/cacti/install/,就有信息如下:

点击next,继续下一步,其他的都死默认选项,默认登录用户名密码是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'; 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Apr 16, 2025 am 12:20 AM

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL: Database Management System vs. Programming LanguageMySQL: Database Management System vs. Programming LanguageApr 16, 2025 am 12:19 AM

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL: Managing Data with SQL CommandsMySQL: Managing Data with SQL CommandsApr 16, 2025 am 12:19 AM

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

MySQL's Purpose: Storing and Managing Data EffectivelyMySQL's Purpose: Storing and Managing Data EffectivelyApr 16, 2025 am 12:16 AM

MySQL is an efficient relational database management system suitable for storing and managing data. Its advantages include high-performance queries, flexible transaction processing and rich data types. In practical applications, MySQL is often used in e-commerce platforms, social networks and content management systems, but attention should be paid to performance optimization, data security and scalability.

SQL and MySQL: Understanding the RelationshipSQL and MySQL: Understanding the RelationshipApr 16, 2025 am 12:14 AM

The relationship between SQL and MySQL is the relationship between standard languages ​​and specific implementations. 1.SQL is a standard language used to manage and operate relational databases, allowing data addition, deletion, modification and query. 2.MySQL is a specific database management system that uses SQL as its operating language and provides efficient data storage and management.

Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.