成都创新互联网站制作重庆分公司

Cacti安装配置Cacti监控本机

大纲

成华网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。创新互联自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。

一、前言

二、Cacti 概述

三、Cacti 工作流程

四、Cacti 安装

五、配置Cacti监控本机

注,操作系统 CentOS 6.4 x86_84,软件版本 Cacti-0.8.8b 目前最新版。 (说明:本博文的一些图片自于开源社区与官方网站并不是所有内容全是原创)

一、前言

在 前面的几篇博客中我们讲解了,监控的概述、SNMP原理与实战、RRDTool绘图工具使用,这几篇博文都是做为铺垫来为我们讲解Cacti监控工具做准 备,通过上面博文的讲解,我们知道可以通过snmp协议来收集远程主机的系统状态信息,如CPU使用率、内存的使用率、网卡流量、TCP连接数据等,然后 将收集的数据保存在RRD文件中,再通过RRTool复杂的命令行工具来绘图。通过实际操作我们会发现,虽然RRDTool绘图工具功能很强大,但是使用 非常的复杂。还有以下缺点,

RRDTool只能存储数据和画图,它没有像MRTG中集成的数据采集功能,要手动收集数据或写脚本收集数据。

在命令行下的使用非常复杂,参数极多。

无用户、图像管理功能

然后我们就会说了,有没有什么工具能补全以上缺点呢?答案是肯定有的,下面我们就来说一说我们这篇博文的主角Cacti。

二、Cacti概述

Cacti 在英文中的意思是仙人掌的意思,Cacti是一套基于PHP、MySQL、SNMP及RRDTool开发的网络流量监测图形分析工具。它通过 snmpget来获取数据,使用 RRDtool绘画图形,它的界面非常漂亮,能让你根本无需明白rrdtool的参数能轻易的绘出漂亮的图形。而且你完全可以不需要了解RRDtool复 杂的参数。它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结 构、host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,让你添加自己的snmp_query和script!功能非常强 大完善,界面友好。可以说,Cacti将rrdtool的所有“缺点”都补足了!下图是Cacti运行的主界面,

好了,Cacti的简单介绍我们就说到这里了,下面我们来看一下Cacti的工作流程。

三、Cacti 工作流程

下面我们来简单的说明一下Cacti的工作流程,

步骤一,snmp协议收集远程服务器的数据

步骤二,将snmp收集的数据内容保存到rrd数据库中

步骤三,若用户查看某台设备上的流量或其它状态信息

步骤四,在mysql数据库中查找该设备对应的rra数据库文件的名称

步骤五,通过rrdtool命令进行绘图即可

好了,在前面的几篇博客中我们讲解了SNMP协议,也讲解了RRDTool工具的使用,现在再来学习Cacti就非常的简单了,下面我们来安装并使用Cacti。

四、Cacti 安装

注,Cacti的运行是基于LAMP环境的首先我们来安装LAMP环境。(LAMP环境安装有两种方法,有时间的博友可以使用源码安装,不想用源码安装的博友可以参考我的安装方法全部用yum安装。)下面我们来具体演示一下,

1.安装yum源

1
2
3
4
[root@node1 ~] # rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
Retrieving http: //pkgs .repoforge.org /rpmforge-release/rpmforge-release-0 .5.3-1.el6.rf.x86_64.rpm
Preparing... ########################################### [100%]
package rpmforge-release-0.5.3-1.el6.rf.x86_64 is already installed #我这边已经安装好了

2.同步时间

1
2
[root@node1 ~] # ntpdate 202.120.2.101
12 Oct 11:03:56 ntpdate[13805]: adjust time server 202.120.2.101 offset 0.000661 sec

3.安装LAMP环境

首先,用yum安装相关软件包,

1
[root@node1 ~]# yum install -y httpd php php-mysql php-snmp php-xml php-gd mysql mysql-server gd gd-devel

设置开机自启动并启动服务,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@node1 ~] # chkconfig httpd on
[root@node1 ~] # service httpd start
正在启动 httpd: [确定]
[root@node1 ~] # chkconfig mysqld on
[root@node1 ~] # service mysqld start
正在启动 mysqld: [确定]
[root@node1 ~] # netstat -ntulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1045 /sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1122 /master
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 13786 /sshd
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 17820 /sshd
tcp 0 0 127.0.0.1:6013 0.0.0.0:* LISTEN 31664 /sshd
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 13017 /snmpd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 13375 /mysqld
tcp 0 0 :::80 :::* LISTEN 13917 /httpd
tcp 0 0 :::22 :::* LISTEN 1045 /sshd
tcp 0 0 ::1:25 :::* LISTEN 1122 /master
tcp 0 0 ::1:6010 :::* LISTEN 13786 /sshd
tcp 0 0 ::1:6012 :::* LISTEN 17820 /sshd
tcp 0 0 ::1:6013 :::* LISTEN 31664 /sshd
udp 0 0 0.0.0.0:161 0.0.0.0:* 13017 /snmpd

提供php页面并测试php环境,

1
2
3
4
5
[root@node1 ~] # cd /var/www/html/
[root@node1 html] # vim index.php
phpinfo();
?>

好了,当大家看到这个页面时,就说明我们php环境安装完成,下面我们来测试mysql数据库。

[

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
root@node1 ~] # mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 96186
Server version: 5.1.69 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 |
| mysql |
| test |
| testdb |
+--------------------+
4 rows in set (0.08 sec)
mysql>

好了,到这里我们LAMP环境就安装完成了,下面我们来安装net-snmp与RRDTool。

4.安装net-snmp

1
[root@node1 ~] # yum install -y net-snmp net-snmp-utils

下面我们来修改一下配置文件,

1
2
3
4
5
[root@node1 ~] # vim /etc/snmp/snmpd.conf
修改前,
view systemview included .1.3.6.1.2.1.1
修改后,
view systemview included .1.3.6.1.2.1

接下来启动net-snmp并测试一下,

1
2
3
4
5
6
7
8
9
10
11
[root@node1 ~] # service snmpd start
正在启动 snmpd: [确定]
[root@node1 ~] # snmpnetstat -v 2c -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 localhost.x11- ssh - *.* LISTEN
tcp 192.168.18.201. ssh 192.168.18.138.61353 ESTABLISHED

好了,到这里我们net-snmp安装完成,下面我们来安装RRDTool绘图工具。

5.安装RRDTool

1
[root@node1 ~] # yum install -y rrdtool

下面来测试一下,

1
2
3
4
5
6
7
8
9
10
[root@node1 ~] # rrdtool -v
RRDtool 1.3.8 Copyright 1997-2009 by Tobias Oetiker
Compiled Aug 21 2010 10:57:18
Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv, dump, restore,
last, lastupdate, first, info, fetch, tune,
resize, xport
RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org /copyleft/gpl .html)
For more information read the RRD manpages

好了,到这里我们基本环境准备就全部完成了,下面我们来安装与配置Cacti。

6.安装与配置Cacti

首先我们去下载Cacti,

1
2
3
4
5
6
7
8
9
10
11
12
[root@node1 ~] # wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
[root@node1 ~] # ll -h
总用量 2.8M
-rw-------. 1 root root 970 8月 17 18:50 anaconda-ks.cfg
-rw-r--r-- 1 root root 2.2M 8月 7 09:42 cacti-0.8.8b. tar .gz
-rw-r--r-- 1 root root 176 10月 11 16:06 getselect.sh
-rw-r--r-- 1 root root 152 10月 11 16:15 insert.sh
-rw-r--r--. 1 root root 16K 8月 17 18:50 install .log
-rw-r--r--. 1 root root 4.1K 8月 17 18:48 install .log.syslog
-rw-r--r-- 1 root root 11K 10月 11 16:23 mysql.png
-rw-r--r-- 1 root root 294K 10月 11 16:47 mysql.rrd
-rw-r--r-- 1 root root 294K 10月 10 21:53 rrdtool-1.3.8-6.el6.x86_64.rpm

大家都知道Cacti就是个PHP程序是基于LAMP环境运行的,下面我们来为Cacti配置虚拟主机,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@node1 ~] # vim /etc/httpd/conf/httpd.conf
DocumentRoot /web/vhosts/cacti
ServerName cacti. test .com
ErrorLog logs /cacti . test .com-error_log
CustomLog logs /cacti . test .com-access_log common
Options Indexes FollowSymLinks
DirectoryIndex index.php index.html index.htm
AllowOverride None
Order allow,deny
Allow from all
< /Directory >
< /VirtualHost >

下面我们来建立Cacti文档目录,

1
2
3
4
[root@node1 ~] # mkdir -pv /web/vhosts/cacti
mkdir : 已创建目录 "/web"
mkdir : 已创建目录 "/web/vhosts"
mkdir : 已创建目录 "/web/vhosts/cacti"

接下来我们来解压刚才下载的Cacti压缩包并将Cacti程序移动到/web/vhosts/cacti下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@node1 ~] # tar xf cacti-0.8.8b.tar.gz
[root@node1 ~] # cd cacti-0.8.8b
[root@node1 cacti-0.8.8b] # mv * /web/vhosts/cacti/
[root@node1 cacti-0.8.8b] # cd /web/vhosts/cacti/
[root@node1 cacti] # ls
about.php data_templates.php graph_templates.php log scripts
auth_changepassword.php docs graph_view.php logout .php script_server.php
auth_login.php gprint_presets.php graph_xport.php plugins script_server.pl
cacti.sql graph_image.php host.php plugins.php settings.php
cdef.php graph.php host_templates.php poller_commands.php templates_export.php
cli graph_settings.php images poller_export.php templates_import.php
cmd.php graphs_items.php include poller.php tree.php
color.php graphs_new.php index.php README user_admin.php
data_input.php graphs.php install resource utilities.php
data_queries.php graph_templates_inputs.php lib rra
data_sources.php graph_templates_items.php LICENSE rra.php

其中cacti.sql是保存了cacti到所有表的语句,但是没有创建数据库的语句,所以下面我们来配置一下Cacti数据库,

1
2
[root@node1 cacti] # mysqladmin create cactidb
[root@node1 cacti] # mysql cactidb < cacti.sql

因为cacti要访问数据库,所以我们得给cacti创建一个授权用户,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@node1 cacti] # mysql -e "GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY \'cactiuser\'"
[root@node1 cacti] # mysqladmin flush-privileges
[root@node1 cacti] # mysql -ucactiuser -pcactiuser
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 96192
Server version: 5.1.69 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 |
| test |
+--------------------+
3 rows in set (0.02 sec)
mysql>

下面我们来修改cacti程序的配置文件,

1
2
3
4
5
6
7
8
9
10
11
12
[root@node1 ~] # cd /web/vhosts/cacti/
[root@node1 cacti] # cd include/
[root@node1 include] # vim 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 ;
$url_path = "/" ; #这一行非常重要设置cacti程序访问路径的

下面我们来创建一个cacti用户(安装初始化cacti)并修改相关目录权限,

1
2
3
[root@node1 ~] # cd /web/vhosts/cacti/
[root@node1 cacti] # useradd cactiuser
[root@node1 cacti] # chown -R cactiuser:cactiuser log/ rra/

接下来重新启动一下httpd并初始化cacti,首先我们得修改 Win 7的hosts文件,C:WindowsSystem32driversetchosts,新增一行:

1
192.168.18.201 cacti. test .com

下面我们用浏览器访问一下:http://cacti.test.com/install,会弹出cacti初始化界面,如下图

我们点击”Next”继续,

接下来让你选择全新安装还是升级安装,我们这里肯定选择”New Install”,点击“Next”继续,

接下来会检查所有配置选项,若有不符合要求的会用红色标出,我们这里全部符合要求,点击“Finish”继续,

直接跳转到cacti的登录页面,到这里我们cacti初始化就全部完成了,下面我们登录一下,默认用户名和密码都为”admin”。

第一下次登录时让你修改默认的用户名和密码,自己设置一个即可。

好了,到这里我们已经可以看cacti的配置界面了,下面我们就来详细的看一下。从上图中我们可以看到最上面有两个标签一个是红颜色的“console”控制台标签,另一个是“graphs”图像标签,下面我们点击一下“graphs”标签,如下图:

大家可以从图上看到,由于我们还没做任何配置,所以这里没有任何图像。好了,下面我们就来详细说一说这两个标签中内容。先说,console 标签。

大家先看左边这一栏,从图中我们可以看出,大致分为七个大项和多个项目。下面我们来的罗列一下,分别讲解。

(1).Create 创建

New Graphs 添加新图形

(2).Management 管理

Graph Management 图形管理。可以在此删除、复制图像,Cacti会自动创建图像。不过如果我们有特殊的需要,比如将几张图上的数据合并在一张图像上的话也可以在此手工新建图像;

Graph Trees 图形树。在graphs界面里,图像或devices是树状结构显示的,可以在此设置树的结构;

Data Sources 数据源。记要用来管理rrd文件的,一般无需修改,Cacti会自己创建rrd文件;

Devices 设备管理。这是我们最经常需要修改的地方,可以在此创建新的设备或修改其名称等信息。

(3).Collection Methods 数据收集方法,一般我们无需对这两项进行修改。(非常重要在下面的内容中进行详解)

Data Queries 数据查询,

Data Input Methods 数据输入方法

(4).Templates 模板,这些模板可以导出、导入也可以自己编写,一般无需修改。

Graph Templates 图形模板

Host Templates 主机模板

Data Templates 数据模板

(5).Import/Export 导入/导出,对上述模板的导入、导出。我们可以在Cacti的官方网站上找到这些模板,不过需要注意模板对于的Cacti的版本。

Import Templates 导入模板

Export Templates 导出模板

(6).Configuration 配置

Settings 系统设置,Cacti的主要配置菜单;可以在此重新设置对应的程序的路径、版本等信息。也可以设置图像的输出方式(允许ftp)、显示效果、登陆方式(允许使用LDAP)等。

Plugin Management 插件管理

(7).Utilities 工具

System Utilities 系统工具,显示Cacti系统的一些cache和log信息,如果log文件太大建议直接到后台查看;

User Management 用户管理,可以在此添加、删除用户,并对每个用户设置详细的权限;

Logout User 用户退出

里面的具体内容请大家自己去看,下面我们来讲解一下第三大项收集方法,收集方法即数据收集方法。其中,有两种方法:

数据查询:xml格式数据收集方法

数据输入方法:命令或脚本(比较常用)

注,脚本只需要指定如何获取数据,并且获取到的数据经过处理后要按元宝输出。案例,

1
2
TAG:data TAG:data
input:30 output:40

好了,我们用脚本定义了收集数据方法,也指定了数据输出,那脚本多长时间执行一次呢?执行的时间是cacti程序设置的,下面我们来配置cacti安装的最重要的一步也是最后一步,设置cacti收集数据的默认的任务计划。

1
2
3
4
5
6
7
8
9
10
11
12
[root@node1 cacti] # ls
about.php data_templates.php graph_templates.php log scripts
auth_changepassword.php docs graph_view.php logout .php script_server.php
auth_login.php gprint_presets.php graph_xport.php plugins script_server.pl
cacti.sql graph_image.php host.php plugins.php settings.php
cdef.php graph.php host_templates.php poller_commands.php templates_export.php
cli graph_settings.php images poller_export.php templates_import.php
cmd.php graphs_items.php include poller.php tree.php
color.php graphs_new.php index.php README user_admin.php
data_input.php graphs.php install resource utilities.php
data_queries.php graph_templates_inputs.php lib rra
data_sources.php graph_templates_items.php LICENSE rra.php

这里任务计划是由poller.php程序执行的,需要说明的是poller.php是由php写的,单线程的功能相对较弱,为此cacti官方单独开发了一个多线程Spine工具,适合大规模监控应用。好了下面我们就来配置一下任务计划并查看。

1
2
3
[root@node1 cacti] # echo \'*/5 * * * * /usr/bin/php /web/vhosts/cacti/poller.php &>/dev/null\' > /var/spool/cron/cactiuser
[root@node1 cacti] # crontab -u cactiuser -l
* /5 * * * * /usr/bin/php /web/vhosts/cacti/poller .php &> /dev/null

为了防止这个任务计划不执行,我们最好手动验证一下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[root@node1 cacti] # su - cactiuser
[cactiuser@node1 ~]$ /usr/bin/php /web/vhosts/cacti/poller .php
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 165
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 165
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 166
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 166
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 167
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 167
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 168
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 168
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 169
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 169
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 170
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 170
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 171
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_constants .php on line 171
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 671
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 671
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 672
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 672
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 673
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 673
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 674
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 674
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 675
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 675
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 676
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 676
PHP Warning: strtotime(): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 677
PHP Warning: date (): It is not safe to rely on the system \'s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected \' Asia /Chongqing \' for \' CST /8 .0 /no DST\' instead in /web/vhosts/cacti/include/global_arrays .php on line 677
[cactiuser@node1 ~]$

大家可以看到上面报了一大堆错,是什么错误哟?主要是因为我们php.ini的时区设置的不对,下面我们来修改一下php时区。

1
2
3
4
5
[root@node1 cacti] # vim /etc/php.ini
date .timezone = Asia /Shanghai
[root@node1 cacti] # service httpd restart
停止 httpd: [确定]
正在启动 httpd: [确定]

接下来我们再来测试一下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@node1 cacti] # su - cactiuser
[cactiuser@node1 ~]$ /usr/bin/php /web/vhosts/cacti/poller .php
[root@node1 cacti] # chown -R cactiuser:cactiuser log/ rra/ #修改一下cacti程序中的log和rra目录的所属者与所属组
[cactiuser@node1 cacti]$ /usr/bin/php /web/vhosts/cacti/poller .php
10 /12/2013 04:18:26 PM - SYSTEM STATS: Time:0.2288 Method:cmd.php Processes:1 Threads:N /A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5
OK u:0.00 s:0.00 r:0.14
OK u:0.00 s:0.00 r:0.14
OK u:0.00 s:0.00 r:0.14
OK u:0.00 s:0.00 r:0.14
OK u:0.00 s:0.01 r:0.15
OK u:0.00 s:0.01 r:0.15
OK u:0.00 s:0.01 r:0.15
OK u:0.00 s:0.01 r:0.15
OK u:0.00 s:0.01 r:0.16
OK u:0.00 s:0.01 r:0.16

查看一下执行日志,

1
2
3
[cactiuser@node1 cacti]$ cd log
[cactiuser@node1 log]$ tail cacti.log
10 /12/2013 04:18:26 PM - SYSTEM STATS: Time:0.2288 Method:cmd.php Processes:1 Threads:N /A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5

好的,Cacti安装到这里就全部完成了,下面我们来配置Cacti让它来监控本机。

五、配置Cacti监控本机

首先我们点击一下“Devices”标签,出下以下界面,大家从图中可以看出,默认的主机就是Localhost。

接下来我们点击一下“Localhost”主机,出现以下界面。

上图是默认的配置,我们只要修改一处即可,便是“SNMP Options”。如下图,

只要选择SNMP版本为“Version2”,点击下面的“Save”即可。效果图如下

接下来我们选择右上脚的“Create Graphs for this Host”(为这个主机增加监控图形),

我们选择监控本地主机的磁盘空间,点击“Create”即可。下面我们来点击最上面的“Graph”标签 。如下图,

从图中我们可以看到我们新增加的监控磁盘空间的图形还没有出图,我们得等个几分钟才会出现图形,请博友耐心等待。好了,过几分钟就会出现下面的效果图,

再过几分钟就会出现最终效果图,如下图

好了,到这里我们配置Cacti监控localhost就全部完成了。在一下篇博文中我们主要讲解Cacti怎么监控远程主机与Cacti的高级应用。最后,希望大家有所收获吧^_^……


网页题目:Cacti安装配置Cacti监控本机
文章分享:http://cxhlcq.com/article/chddcj.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部