cacti官方首页上这样描述:
The latest stable version is 0.8.8b, released 08/04/13.
Cacti requires MySQL, PHP, RRDTool, net-snmp, and a webserver that supports PHP such as Apache or IIS. Please see therequirements section of the manual for information on how to fulfill these requirements under certain operating systems. Please use the install guide for either Unix or Windows for information about installing Cacti.
在cacti概述中说过cacti是一个php程序,而它需要rrdtool工具进行绘图,需要snmp工具来收集数据,所以要想让cacti工作起你就需要一个php程序的运行环境、需要安装上rrdtool工作,以及snmp工具。
我们知道,
## 对mysql 进行安全配置
# /usr/bin/mysql_secure_installation
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> OK, LAMP环境已经安装完成。
4、安装net-snmp包
# net-snmp for => agent
# net-snmp-utils for => manager
[root@localhost ~]# yum -y install net-snmp net-snmp-utils
## 编辑snmpd.conf配置文件, 请根据实际情况更改,强烈建议修改 community ,以及 来源IP
[root@localhost ~]# vi /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
view all included .1
####
access notConfigGroup "" any noauth exact all none none
## 重启snmpd服务,并测试
[root@localhost ~]# chkconfig snmpd on
[root@localhost ~]# service snmpd restart
[root@localhost ~]# snmpnetstat -v2c -c public -Ca -Cp tcp localhost
Active Internet (tcp) Connections (including servers)
Proto Local Address Remote Address (state)
tcp *.ssh *.* LISTEN
tcp *.mysql *.* LISTEN
tcp localhost.smtp *.* LISTEN
tcp localhost.smux *.* LISTEN
tcp 192.168.11.103.ssh 192.168.11.4.60805 ESTABLISHED
5、安装rrdtool工具(建议yum安装,编译容易出现问题,比如缺少某字体,然后导致乱码)
[root@localhost ~]# yum -y install rrdtool
# 可以看到,下面依赖了很多font相关的包
Dependency Installed:
dejavu-fonts-common.noarch 0:2.30-2.el6
dejavu-lgc-sans-mono-fonts.noarch 0:2.30-2.el6
dejavu-sans-mono-fonts.noarch 0:2.30-2.el6
fontpackages-filesystem.noarch 0:1.41-1.1.el6
## 测试是否安装成功
[root@localhost ~]# rrdtool -v
RRDtool 1.3.8 Copyright 1997-2009 by Tobias Oetiker
Compiled Aug 21 2010 10:54:58 这里, 我也简单的介绍一下,如何编译安装 rrdtool 1.4.8 版本
1、下载 rrdtool
# wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.8.tar.gz
2、安装rrdtool之前需要安装相应的lib库,如下安装: # yum install cairo-devel libxml2-devel pango pango-devel -y
3、编译安装
# tar xf rrdtool-1.4.8.tar.gz -C /usr/local/src
# cd /usr/local/src/rrdtool-1.4.8/
# ./configure --prefix=/usr/local/rrdtool
# make && make install 报错如下:
Can't locateExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib/perl5/usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl/usr/lib/perl5 /usr/share/perl5 .) at Makefile.PL line 1.
BEGINfailed--compilation aborted at Makefile.PL line 1.
解决:
# yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
继续安装:
# make clean
# make && make install
# vi /etc/profile.d/rrdtool.sh
export PATH=$PATH:/usr/local/rrdtool/bin
# . /etc/profile.d/rrdtool.sh 检查配置环境
# for svc in mysqld snmpd httpd; do chkconfig --list $svc; done
mysqld 0:off1:off2:on3:on4:on5:on6:off
snmpd 0:off1:off2:on3:on4:on5:on6:off
httpd 0:off1:off2:on3:on4:on5:on6:off
# ss -tunl
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 *:161 *:*
tcp LISTEN 0 128 :::80 :::*
tcp LISTEN 0 128 :::22 :::*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 ::1:25 :::*
tcp LISTEN 0 100 127.0.0.1:25 *:*
tcp LISTEN 0 128 127.0.0.1:199 *:*
tcp LISTEN 0 50 *:3306 *:*
搞定, 终于把cacti所依赖的环境的搭好了,下面就开始安装cacti
DocumentRoot "/web/cacti"
ServerName cacti.monitor.com
ErrorLog logs/cacti_error_log
CustomLog logs/cacti_access_log common
Alias /cacti "/web/cacti"
Options Indexes FollowSymLinks
DirectoryIndex index.php index.html index.htm
AllowOverride None
Order allow,deny
Allow from all
## 创建cacti目录
[root@localhost ~]# mkdir -pv /web
mkdir: created directory `/web'
## 解压cacti.tar.gz 到刚才创建的目录
[root@localhost ~]# tar xf cacti-0.8.8b.tar.gz -C /web
[root@localhost ~]# cd /web
[root@localhost web]# ln -sv cacti-0.8.8b cacti 解释一下virtual.conf中配置的logfile,Contiguration and logfile names: If the fielnames you specify for many of the server's control files begin with "/"(or "drive:/" for win32),the server will use that explicit path. If the filenames do "not" begin with "/", the value of ServerRoot is prepended -- so "logs/foo.log" with ServerRoot set to "/etc/httpd" will be interpreted by the server as "/etc/httpd/logs/foo.log"
cacti在运行的过程中,需要向数据库中存储一些数据,所以我们需要创建所需的库以及表。在cacti的解压目录下,其中cacti.sql保存了所有建表的语句,但是没有创建数据库的语句。所以我们必须要先手动创建一个库。
## 创建名为cactidb的库
[root@localhost cacti]# mysqladmin -uroot -p create cactidb
## 导入建表语句,以及数据
[root@localhost cacti]# mysql -uroot -p cactidb < cacti.sql
mysql> show tables from cacti; #验证表是否创建
+---------------------------+
| Tables_in_cacti |
+---------------------------+
| cdef |
| cdef_items |
| colors |
| data_input |
| data_input_data |
| data_input_fields |
| data_local |
| data_template |
| data_template_data |
| data_template_data_rra |
| data_template_rrd |
| graph_local |
| graph_template_input |
| graph_template_input_defs |
| graph_templates |
| graph_templates_gprint |
| graph_templates_graph |
| graph_templates_item |
| graph_tree |
| graph_tree_items |
| host |
| host_graph |
| host_snmp_cache |
| host_snmp_query |
| host_template |
| host_template_graph |
| host_template_snmp_query |
| plugin_config |
| plugin_db_changes |
| plugin_hooks |
| plugin_realms |
| poller |
| poller_command |
| poller_item |
| poller_output |
| poller_reindex |
| poller_time |
| rra |
| rra_cf |
| settings |
| settings_graphs |
| settings_tree |
| snmp_query |
| snmp_query_graph |
| snmp_query_graph_rrd |
| snmp_query_graph_rrd_sv |
| snmp_query_graph_sv |
| user_auth |
| user_auth_perms |
| user_auth_realm |
| user_log |
| version |
+---------------------------+
52 rows in set (0.00 sec)
## 因为cacti需要访问数据库,所以我们得给cacti创建一个授权用户,最好不要使用root账号
## 所以我们为了安全,仅创建一个用户仅对cacti这个库有所有权限
[root@localhost cacti]# mysql -uroot -p -e "GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'"
[root@localhost cacti]# mysql -uroot -p -e 'FLUSH PRIVILEGES'
## 测试 cactiuser能够登录Mysql
[root@localhost cacti]# mysql -ucactiuser -pcactiuser
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cactidb |
+--------------------+
2 rows in set (0.00 sec) 接下来,我们编辑 cacti 的配置文件,配置如何连接mysql数据库:
[root@localhost cacti]# pwd
/web/cacti
[root@localhost cacti]# vi include/config.php
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;
/*
Edit this to point to the default URL of your Cacti install
ex: if your cacti install as at http://serverip/cacti/ this
would be set to /cacti/
*/
$url_path ="/cacti/"; # 这一行非常重要设置cacti程序访问路径的
#这一项是可选项,默认是“$url_path = "/cacti/”,表示在访问cacti控制台时需要加上"/cacti"这个URI,而修改为“$url_path = "/”后,访问cacti的控制台只需要“http://IP”即可
## 保存退出 好的,重启一下 httpd 服务
## 重启httpd, 重启mysqld
[root@localhost ~]# service httpd restart
[root@localhost ~]# service mysqld restart 然后通过浏览器访问一下: http://IP/cacti , 会弹出cacti初始化界面