cacti詳解(一)

原文地址:http://freeloda.blog.51cto.com/2033581/1308140

大綱

一、前言

二、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運行的主界面,

c1

官方網站:http://www.cacti.net。好了,Cacti的簡單介紹我們就說到這裏了,下面我們來看一下Cacti的工作流程。


三、Cacti 工作流程

c2

下面我們來簡單的說明一下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 timeserver 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/Programname
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
<?php
phpinfo();
?>

c3

好了,當大家看到這個頁面時,就說明我們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 idis 96186
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, Oracle and/orits affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/orits
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or '\h'forhelp. Type '\c'to clearthe current input statement.
mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| mysql       |
| test|
| testdb       |
+--------------------+
4 rows inset(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.ssh192.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 <[email protected]>
Compiled Aug 21 2010 10:57:18
Usage: rrdtool [options] commandcommand_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 moreinformation readthe 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
<VirtualHost *:80>
DocumentRoot /web/vhosts/cacti
ServerName cacti.test.com
ErrorLog logs/cacti.test.com-error_log
CustomLog logs/cacti.test.com-access_log common
<Directory "/web/vhosts/cacti">
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         installresource       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 idis 96192
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, Oracle and/orits affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/orits
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or '\h'forhelp. Type '\c'to clearthe current input statement.
mysql> show databases;
+--------------------+
| Database      |
+--------------------+
| information_schema |
| cactidb      |
| test|
+--------------------+
3 rows inset(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
/* makesure 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:\Windows\System32\drivers\etc\hosts,新增一行:

1
192.168.18.201  cacti.test.com

下面我們用瀏覽器訪問一下:http://cacti.test.com/install,會彈出cacti初始化界面,如下圖

c4

我們點擊”Next”繼續,

c5

接下來讓你選擇全新安裝還是升級安裝,我們這裏肯定選擇”New Install”,點擊“Next”繼續,

c6

接下來會檢查所有配置選項,若有不符合要求的會用紅色標出,我們這裏全部符合要求,點擊“Finish”繼續,

c8

直接跳轉到cacti的登錄頁面,到這裏我們cacti初始化就全部完成了,下面我們登錄一下,默認用戶名和密碼都爲”admin”。

c9

第一下次登錄時讓你修改默認的用戶名和密碼,自己設置一個即可。

c10

好了,到這裏我們已經可以看cacti的配置界面了,下面我們就來詳細的看一下。從上圖中我們可以看到最上面有兩個標籤一個是紅顏色的“console”控制檯標籤,另一個是“graphs”圖像標籤,下面我們點擊一下“graphs”標籤,如下圖:

c11

大家可以從圖上看到,由於我們還沒做任何配置,所以這裏沒有任何圖像。好了,下面我們就來詳細說一說這兩個標籤中內容。先說,console 標籤。

c12

大家先看左邊這一欄,從圖中我們可以看出,大致分爲七個大項和多個項目。下面我們來的羅列一下,分別講解。

(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         installresource       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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/noDST' insteadin/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/201304:18:26 PM - SYSTEM STATS: Time:0.2288 Method:cmd.php Processes:1 Threads:N/AHosts: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]$ cdlog
[cactiuser@node1 log]$ tailcacti.log
10/12/201304:18:26 PM - SYSTEM STATS: Time:0.2288 Method:cmd.php Processes:1 Threads:N/AHosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5

好的,Cacti安裝到這裏就全部完成了,下面我們來配置Cacti讓它來監控本機。


五、配置Cacti監控本機

首先我們點擊一下“Devices”標籤,出下以下界面,大家從圖中可以看出,默認的主機就是Localhost。

c14

接下來我們點擊一下“Localhost”主機,出現以下界面。

c15

c16

上圖是默認的配置,我們只要修改一處即可,便是“SNMP Options”。如下圖,

c17

只要選擇SNMP版本爲“Version2”,點擊下面的“Save”即可。效果圖如下,

c18

接下來我們選擇右上腳的“Create Graphs for this Host”(爲這個主機增加監控圖形),

c19

我們選擇監控本地主機的磁盤空間,點擊“Create”即可。下面我們來點擊最上面的“Graph”標籤 。如下圖,

c20

c21

從圖中我們可以看到我們新增加的監控磁盤空間的圖形還沒有出圖,我們得等個幾分鐘纔會出現圖形,請博友耐心等待。好了,過幾分鐘就會出現下面的效果圖,

c22

c23

再過幾分鐘就會出現最終效果圖,如下圖

c24

c25

好了,到這裏我們配置Cacti監控localhost就全部完成了。在一下篇博文中我們主要講解Cacti怎麼監控遠程主機與Cacti的高級應用。最後,希望大家有所收穫吧^_^……


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章