Cacti使用安装详解_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账号:
- 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 cacti_user@/
登录mysql,删除掉’’@localhost以及’’@hostname这2个用户名为空串的mysql账号,就OK了。
- [cacti@squid-2 ~]$ /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的路径,做一个软连接:
- [root@mysqlvm2 bin]# find / -name mysql.sock
- /usr/local/mysql/mysql.sock
- [root@mysqlvm2 bin]#
- [root@mysqlvm2 bin]# ln -s /usr/local/mysql/mysql.sock /var/lib/mysql/mysql.sock
- [root@mysqlvm2 bin]#
再次启动,有报错如下:
- [root@mysqlvm2 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
- [cacti@squid-2 cacti-0.8.8b] tar -xvf cacti-0.8.8b.tar.gz
- [cacti@squid-2 cacti-0.8.8b] cd cacti-0.8.8b
- [root@mysqlvm2 bin]# type mysql
- mysql is hashed (/usr/local/mysql/bin/mysql)
- [cacti@squid-2 cacti-0.8.8b]$
- mysql -u cacti_user -pcacti05261743 -h127.0.0.1 cacti /cacti/cacti-0.8.8b/cacti.sql
- [cacti@squid-2 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
- [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服务的用户名,密码,端口等。
- 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文件
[root@mysqlvm2 cacti]# vim login.php
simple demo
phpinfo();
?>
如下图所示:
打开网址页面:
启动完httpd之后,可以打开 http://10.xx.1.xx/,界面如下:
遇到的小问题,打开index.php是空页面,如下所示:
去查看日志,日志没有任何信息:

问题在哪里呢?
找到apache的配置文件httpd.conf
- [root@mysqlvm2 www]# vim /etc/httpd/conf/httpd.conf
- Search error_log
- 日志路径 /var/log/httpd/error_log
- [root@mysqlvm2 cacti]# cd /var/log/httpd/
- [root@mysqlvm2 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里面发现错误信息:
- [root@mysqlvm2 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组件
[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';

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This article will introduce the solution to the problem that the globe symbol is displayed on the Win10 system network but cannot access the Internet. The article will provide detailed steps to help readers solve the problem of Win10 network showing that the earth cannot access the Internet. Method 1: Restart directly. First check whether the network cable is not plugged in properly and whether the broadband is in arrears. The router or optical modem may be stuck. In this case, you need to restart the router or optical modem. If there are no important things being done on the computer, you can restart the computer directly. Most minor problems can be quickly solved by restarting the computer. If it is determined that the broadband is not in arrears and the network is normal, that is another matter. Method 2: 1. Press the [Win] key, or click [Start Menu] in the lower left corner. In the menu item that opens, click the gear icon above the power button. This is [Settings].

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

1. Check the wifi password: Make sure the wifi password you entered is correct and pay attention to case sensitivity. 2. Confirm whether the wifi is working properly: Check whether the wifi router is running normally. You can connect other devices to the same router to determine whether the problem lies with the device. 3. Restart the device and router: Sometimes, there is a malfunction or network problem with the device or router, and restarting the device and router may solve the problem. 4. Check the device settings: Make sure the wireless function of the device is turned on and the wifi function is not disabled.

In daily life and work, we often need to share files and folders between different devices. Windows 11 system provides convenient built-in folder sharing functions, allowing us to easily and safely share the content we need with others within the same network while protecting the privacy of personal files. This feature makes file sharing simple and efficient without worrying about leaking private information. Through the folder sharing function of Windows 11 system, we can cooperate, communicate and collaborate more conveniently, improving work efficiency and life convenience. In order to successfully configure a shared folder, we first need to meet the following conditions: All devices (participating in sharing) are connected to the same network. Enable Network Discovery and configure sharing. Know the target device

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Douyin is one of the most popular short video platforms in China, attracting more than 500 million monthly active users, making Douyin a hot target for advertisers and content creators. Douyin’s high traffic has the following significant advantages, attracting many interested friends, so you might as well take a look. 1. What are the benefits of having high Douyin traffic? The high traffic of Douyin means that the advertising coverage is broad. As the number of users increases, advertisers can reach more potential consumers on Douyin. This is a huge opportunity for branding to expose your product or service to a larger audience, increasing awareness and exposure. Increasing Douyin traffic can help increase sales. Through proper promotion and publicity on Douyin, companies can attract more users to learn about and purchase their products. Douyin with

Android development is a busy and exciting job, and choosing a suitable Linux distribution for development is particularly important. Among the many Linux distributions, which one is most suitable for Android development? This article will explore this issue from several aspects and give specific code examples. First, let’s take a look at several currently popular Linux distributions: Ubuntu, Fedora, Debian, CentOS, etc. They all have their own advantages and characteristics.
