cacti導入Linux主機模板 Windows主機模板

大綱php

1、實驗環境說明 html

2、Cacti 監控服務器完整搭建過程演示(基於spine採集器)node

3、Cacti 高級應用之Linux主機模板mysql

4、Cacti 高級應用之Windows主機模板web

注,操做系統 CentOS 6.4 x86_64,軟件版本 Cacti 0.8.8b (目前最新版)。本博文中涉及的全部軟件或文檔請點擊這裏下載:http://yunpan.cn/Qbe5Wnnd7WLzwsql


1、實驗環境說明 數據庫

1.實驗拓撲vim

實驗拓撲

2.同步節點時間瀏覽器

1
2
[root@cacti  ~]             # ntpdate 202.120.2.101
[root@node2 ~]             # ntpdate 202.120.2.101

3.安裝yum源服務器

1
2
[root@cacti  ~]             # rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@node2 ~]             # rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm


2、Cacti 監控服務器完整搭建過程演示(基於spine採集器)

1.安裝net-snmp工具

注,用yum安裝net-snmp net-snmp-utils net-snmp-devel。

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

注,修改配置文件。

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

注,啓動snmpd服務。

1
2
[root@cacti  ~]             # service snmpd start
正在啓動 snmpd:                      [肯定]

注,測試一下net-snmp。

1
2
3
4
5
6
7
8
[root@cacti  ~]             # snmpnetstat -v 2c -c public -Cna -Cp tcp 127.0.0.1
Active Internet (tcp) Connections (including servers)
Proto Local Address     Remote Address     (state)
tcp  *.22          *.*          LISTEN
tcp  127.0.0.1.25      *.*          LISTEN
tcp  127.0.0.1.199     *.*          LISTEN
tcp  127.0.0.1.6010     *.*          LISTEN
tcp  192.168.18.201.22   192.168.18.19.53322  ESTABLISHED

2.安裝rrdtool工具

注,安裝rrdtool rrdtool-devel。

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

注,測試一下。

1
2
3
4
5
6
7
8
9
10
[root@cacti  ~]             # rrdtool
RRDtool 1.3.8 Copyright 1997-2009 by Tobias Oetiker <tobi@oetiker.ch>
                     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

3.安裝LAMP環境

注,安裝httpd php php-mysql php-snmp php-xml php-gd mysql mysql-server gd gd-devel。

1
[root@cacti  ~]             # yum install -y httpd php php-mysql php-snmp php-xml php-gd mysql mysql-server mysql-devel 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
[root@cacti  ~]             # chkconfig snmpd on
[root@cacti  ~]             # chkconfig httpd on
[root@cacti  ~]             # chkconfig mysqld on
[root@node1 ~]             # chkconfig httpd on
[root@node1 ~]             # service httpd start
正在啓動 httpd:           [肯定]
[root@node1 ~]             # chkconfig mysqld on
[root@node1 ~]             # service mysqld start
正在啓動 mysqld:           [肯定]
[root@cacti  ~]             # 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   1016             /sshd    
tcp    0   0 127.0.0.1:25        0.0.0.0:*          LISTEN   1093             /master   
tcp    0   0 127.0.0.1:6010       0.0.0.0:*          LISTEN   1128             /sshd    
tcp    0   0 127.0.0.1:199        0.0.0.0:*          LISTEN   1272             /snmpd   
tcp    0   0 0.0.0.0:3306        0.0.0.0:*          LISTEN   6498             /mysqld   
tcp    0   0 :::80            :::*            LISTEN   6298             /httpd   
tcp    0   0 :::22            :::*            LISTEN   1016             /sshd    
tcp    0   0 ::1:25           :::*            LISTEN   1093             /master   
tcp    0   0 ::1:6010          :::*            LISTEN   1128             /sshd    
udp    0   0 0.0.0.0:161         0.0.0.0:*                1272             /snmpd

4.測試LAMP環境

注,提供php頁面。

1
2
3
4
[root@cacti  html]             # vim index.php
<?php
                 phpinfo();
?>

注,用瀏覽器訪問測試一下。

php測試頁面

5.安裝cacti

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@cacti  ~]             # cd /var/www/html/
[root@cacti  html]             # rm -rf *
[root@cacti  html]             # ls
[root@cacti  ~]             # tar xf cacti-0.8.8b.tar.gz
[root@cacti  ~]             # cd cacti-0.8.8b
[root@cacti  cacti-0.8.8b]             # mv * /var/www/html/
[root@cacti  cacti-0.8.8b]             # cd /var/www/html/
[root@cacti  html]             # 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用戶並受權。

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[root@cacti  html]             # useradd cacti
[root@cacti  html]             # chown -R cacti.cacti ./*
[root@cacti  html]             # ll
總用量 1088
-rw-r--r-- 1 cacti cacti  5945 8月  7 10:31 about.php
-rw-r--r-- 1 cacti cacti  5348 8月  7 10:31 auth_changepassword.php
-rw-r--r-- 1 cacti cacti 14288 8月  7 10:31 auth_login.php
-rw-r--r-- 1 cacti cacti 178349 8月  7 10:31 cacti.sql
-rw-r--r-- 1 cacti cacti 21658 8月  7 10:31 cdef.php
drwxr-xr-x 2 cacti cacti  4096 8月  7 10:31 cli
-rw-r--r-- 1 cacti cacti 26620 8月  7 10:31 cmd.php
-rw-r--r-- 1 cacti cacti  6974 8月  7 10:31 color.php
-rw-r--r-- 1 cacti cacti 25068 8月  7 10:31 data_input.php
-rw-r--r-- 1 cacti cacti 35505 8月  7 10:31 data_queries.php
-rw-r--r-- 1 cacti cacti 60117 8月  7 10:31 data_sources.php
-rw-r--r-- 1 cacti cacti 32920 8月  7 10:31 data_templates.php
drwxr-xr-x 5 cacti cacti  4096 8月  7 10:31 docs
-rw-r--r-- 1 cacti cacti  6107 8月  7 10:31 gprint_presets.php
-rw-r--r-- 1 cacti cacti  3657 8月  7 10:31 graph_image.php
-rw-r--r-- 1 cacti cacti 13469 8月  7 10:31 graph.php
-rw-r--r-- 1 cacti cacti  9208 8月  7 10:31 graph_settings.php
-rw-r--r-- 1 cacti cacti 17426 8月  7 10:31 graphs_items.php
-rw-r--r-- 1 cacti cacti 40166 8月  7 10:31 graphs_new.php
-rw-r--r-- 1 cacti cacti 60571 8月  7 10:31 graphs.php
-rw-r--r-- 1 cacti cacti 10006 8月  7 10:31 graph_templates_inputs.php
-rw-r--r-- 1 cacti cacti 18542 8月  7 10:31 graph_templates_items.php
-rw-r--r-- 1 cacti cacti 26703 8月  7 10:31 graph_templates.php
-rw-r--r-- 1 cacti cacti 40313 8月  7 10:31 graph_view.php
-rw-r--r-- 1 cacti cacti  6022 8月  7 10:31 graph_xport.php
-rw-r--r-- 1 cacti cacti 60091 8月  7 10:31 host.php
-rw-r--r-- 1 cacti cacti 20031 8月  7 10:31 host_templates.php
drwxr-xr-x 2 cacti cacti  4096 4月  4 2012 images
drwxr-xr-x 4 cacti cacti  4096 10月 17 09:49 include
-rw-r--r-- 1 cacti cacti  2313 8月  7 10:31 index.php
drwxr-xr-x 2 cacti cacti  4096 8月  7 10:31             install
drwxr-xr-x 3 cacti cacti  4096 8月  7 10:31 lib
-rw-r--r-- 1 cacti cacti 15141 4月  4 2012 LICENSE
drwxr-xr-x 2 cacti cacti  4096 4月  4 2012 log
-rw-r--r-- 1 cacti cacti  2838 8月  7 10:31             logout             .php
drwxr-xr-x 2 cacti cacti  4096 8月  7 10:31 plugins
-rw-r--r-- 1 cacti cacti 27362 8月  7 10:31 plugins.php
-rw-r--r-- 1 cacti cacti  4310 8月  7 10:31 poller_commands.php
-rw-r--r-- 1 cacti cacti  2243 8月  7 10:31 poller_export.php
-rw-r--r-- 1 cacti cacti 18056 8月  7 10:31 poller.php
-rw-r--r-- 1 cacti cacti   48 4月  4 2012 README
drwxr-xr-x 5 cacti cacti  4096 4月  4 2012 resource
drwxr-xr-x 2 cacti cacti  4096 10月 17 10:51 rra
-rw-r--r-- 1 cacti cacti  7394 8月  7 10:31 rra.php
drwxr-xr-x 2 cacti cacti  4096 8月  7 10:31 scripts
-rw-r--r-- 1 cacti cacti 10820 8月  7 10:31 script_server.php
-rw-r--r-- 1 cacti cacti  353 4月  4 2012 script_server.pl
-rw-r--r-- 1 cacti cacti  5761 8月  7 10:31 settings.php
-rw-r--r-- 1 cacti cacti  6345 8月  7 10:31 templates_export.php
-rw-r--r-- 1 cacti cacti  5835 8月  7 10:31 templates_import.php
-rw-r--r-- 1 cacti cacti 19529 8月  7 10:31 tree.php
-rw-r--r-- 1 cacti cacti 44997 8月  7 10:31 user_admin.php
-rw-r--r-- 1 cacti cacti 65635 8月  7 10:31 utilities.php

注,修改cacti配置文件。

1
2
3
4
5
6
7
8
9
10
[root@cacti  html]             # cd include/
[root@cacti  include]             # vim config.php
$database_type =             "mysql"             ;
$database_default =             "cacti"             ;
$database_hostname =             "localhost"             ;
$database_username =             "cactiuser"             ;
$database_password =             "cactiuser"             ;
$database_port =             "3306"             ;
$database_ssl =             false             ;
$url_path =             "/"             ;

注,爲cacti建立數據庫並導入表結構。

1
2
[root@cacti  ~]             # mysqladmin create cacti
[root@cacti  ~]             # mysql cacti < /var/www/html/cacti.sql

注,建立cacti數據庫管理用戶並受權。

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

注,下面咱們初始化一下cacti。(下面的內容我就不所有註釋在上一篇博文中所有講解過,不清楚的博友能夠參考一下這篇博文:http://freeloda.blog.51cto.com/2033581/1308140 。)

t1

t2

t3

t4

t5

t6

注,最後增長crontab讓net-snmp每5分鐘抓取一次數據。

1
2
3
[root@cacti  html]             # echo '*/5 * * * * /usr/bin/php /var/www/html/poller.php &>/dev/null' > /var/spool/cron/cacti
[root@cacti  html]             # crontab -u cacti -l
*             /5             * * * *             /usr/bin/php             /var/www/html/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
[root@cacti  html]             # su - cacti
[cacti@cacti  ~]$             /usr/bin/php/var/www/html/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

注,你們能夠看到上面報了一大堆錯,是什麼錯誤喲?主要是由於咱們php.ini的時區設置的不對,下面咱們來修改一下php時區。

1
2
3
4
5
[root@cacti  ~]             #  vim /etc/php.ini
date             .timezone = Asia             /Shanghai
[root@cacti  ~]             #  service httpd restart
中止 httpd:            [肯定]
正在啓動 httpd:           [肯定]

注,接下來咱們再來測試一下。

1
2
3
4
5
6
7
8
9
10
[cacti@cacti  ~]$             /usr/bin/php             /var/www/html/poller             .php --force
OK u:0.00 s:0.00 r:0.06
OK u:0.00 s:0.01 r:0.08
OK u:0.00 s:0.01 r:0.08
OK u:0.00 s:0.01 r:0.08
OK u:0.00 s:0.01 r:0.11
OK u:0.00 s:0.01 r:0.11
OK u:0.00 s:0.01 r:0.11
OK u:0.00 s:0.01 r:0.11
10             /17/2013             11:30:11 AM - SYSTEM STATS: Time:0.2451 Method:spine Processes:3 Threads:5 Hosts:2 HostsPerProcess:1 DataSources:11 RRDsProcessed:8

6.安裝spine多線程採集器

注,解壓並編譯安裝sipne。

1
2
3
4
[root@cacti  ~]             # tar xf cacti-spine-0.8.8b.tar.gz
[root@cacti  ~]             # cd cacti-spine-0.8.8b
[root@cacti  cacti-spine-0.8.8b]             # ./configure
[root@cacti  cacti-spine-0.8.8b]             # make && make install

注,提供配置文件並根據需求修改。

1
2
3
4
5
6
7
8
9
[root@cacti  cacti-spine-0.8.8b]             # cd /usr/local/spine/etc/
[root@cacti  etc]             # cp spine.conf.dist spine.conf
[root@cacti  etc]             # vim spine.conf
DB_Host     localhost
DB_Database   cacti
DB_User     cactiuser
DB_Pass     cactiuser
DB_Port     3306
DB_PreG     0

注,測試一下spine。

1
2
3
4
[root@cacti  etc]             # /usr/local/spine/bin/spine
SPINE: Using spine config             file             [spine.conf]
SPINE: Version 0.8.8b starting
SPINE: Time: 1.3157 s, Threads: 5, Hosts: 2

注,修改cacti裏設置spine路徑。

t7

注,修改Cacti使用的Poller Type。

t8

7.測試(監控Localhost)

注,點擊「Devices」-> 你們能夠看到默認已經有Localhost主機,咱們把它刪除從新新建一個默認主機。

t9

注,你們能夠看到咱們勾選上「Locahost」主機,點擊刪除便可。

t10

注,刪除時會讓你選擇,上面是指只刪除圖形模板保留數據文件,下面是指刪除所有包括圖形模板與數據文件。咱們這裏選擇下面選項,由於咱們這是剛剛安裝的沒有什麼數據。

t11

注,到這裏咱們就刪除默認主機了,下面咱們新一個默認主機即監控cacti自己。

t12

注,點擊「Add」按鈕,咱們就能夠增長主機了,下面是增長主機界面。咱們輸入相應的選項便可,通常只要輸入下面幾項:

  • General Host Options

  • SNMP Options

t13

注,輸入相關選項(以下圖),點擊「Create」按鈕便可。

t14

注,下面咱們爲cacti主機增長圖形模板。點擊右上腳的「Create Graphs for this Host」按鈕。

170646351.png

注,由於咱們默認安裝cacti模板比較少,咱們得後期增長模板才能符合咱們線上的監控要求。咱們先用默認模板增長,在下面的博文中咱們會具體講解怎麼增長模板。

t16

注,我們選中咱們要監控的選項,點擊 」Create「便可,以下圖。

t17

注,這邊是圖形模板顏色選項,咱們用默認便可。點擊」Create「

t18

好了,到這裏咱們的cacti主機就增長完成了。爲了咱們查看圖形方便,咱們將cacti主機加入」Graph Trees「中查看。

t19

注,點擊 」Graph Trees「 –> 點擊」Default Tree「(固然你也能夠增長新的圖形樹)。

t20

注,進入默認的圖形樹,咱們選擇 」Add「 按鈕,以下圖。

t21

注,在 」Tree Item Type「 中,咱們選擇 」Host「,其它默認便可。點擊 」Create「。

t22

注,到這裏咱們的圖形樹就增長完成了,咱們點擊 」Save「 便可。

t23

注,下面咱們查看一下 」graphs「 頁面,你們能夠看到顯示的是 Default Tree 是裏有臺 cacti主機。圖形要過一會才能出現,你們耐心等一下默認5分鐘收集一下數據!

t24

注,嘿嘿。再等一會,就能夠看到圖形了。下面是最終效果圖,

t25

t26


3、Cacti 高級應用之Linux主機模板

1.查看一下默認主機模板

注,你們在圖中能夠看出默認主機模板只有幾個,分別爲:

  • Cisco Router

  • Generic SNMP-enabled Host

  • Karlnet Wireless Bridge

  • Local Linux Machine

  • Netware 4/5 Server

  • ucd/net SNMP Host

  • Windows 2000/XP Host

其中,沒有咱們須要的監控模板如,Linux 主機模板或Windows主機模板。 下面咱們先來說解怎麼樣增長Linux主機模板。首先,說明一下全部的模板能夠到官方網站去下載:http://forums.cacti.net/viewforum.php?f=12&sid=fe2532345bf037678cb1e9fb07b40f16 ,咱們這裏已經下載好了,因此真使用。

t27

2.增長Linux主機模板的具體過程

注,點擊 」Import Templates「 頁面。以下圖,咱們能夠在這裏導入咱們下載到的模板,點擊 」瀏覽「。

t28

注,選擇咱們要導入的模板,點擊 」import「 便可。

t29

注,下圖顯示是的模板的具體細節。包括圖形模板與數據模板等。

t30

注,到這裏咱們模板就導入完成了,下面咱們來查看一下。

t31

注,你們能夠看到咱們Linux Host模板已導入完成了。下面咱們增長一個Linux主機測試一下!

t32

3.監控Linux主機具體配置過程

注,點擊 」Devices「 頁面,-> 」Addr「 來增長一臺新主機。以下圖,

170847614.png

注,填寫相關參數,主要配置的參數有:

  • General Host Options

  • SNMP Options

具體參數以下圖,

170920505.png

注,這裏是填寫的相關數據。以下圖,這裏選擇的模板咱們新增長的模板 」Linux Host「。

t35

注,點擊右上腳的 」Create Graphs for this Host「 頁面,咱們爲主機增長監控圖形。

t36

注,在這裏咱們選擇咱們要監控的相關圖形。

t37

t38

注,在上圖中的 」Data Query [TCP]「 時,咱們發如今一個錯誤,咱們下面便來解決一下這裏錯誤。首先,咱們來去看一下 」Data Query「。以下圖,

t39

注,」Data Queries「 是數據收集方法的一種,主要是xml腳本,來幫助咱們收集數據。在圖中咱們能夠看新增長的TCP收集方法,咱們來點擊一下 」TCP「收集方法,看看裏面的內容。以下圖,

t40

注,你們要圖中能夠看到有紅色字體提醒咱們說 TCP 收集方法的 XML 文件沒有,從圖中咱們也能夠看到 tcp.xml文件在安裝目錄下的resource目錄中的script_server目錄下,那下面咱們就來增長一下tcp.xml文件吧。

t41

注,將下載下來的tcp.xml腳本,上傳到/var/www/html/resource/script_server下,咱們點擊 」Save「。以下圖,

t42

注,好了到這裏咱們的Tcp.xml腳本就增長完成了,下面咱們繼續去增長圖形。以下圖,

171002621.png

注, 從圖中能夠看出,咱們 TCP 收集方法好低像仍是有問題,如今不是顯示錯誤,而是顯示一段提示,咱們來回具體看一下這些提示,This data query returned 0 rows, perhaps there was a problem executing this data query. You can run this data query in debug mode to get more information.(譯文:這個數據的查詢返回了0行,也許這是一個執行該查詢數據的問題。你能夠在調試模式下運行此查詢來獲取更多的信息。本人翻 譯能力有限,大概意思是沒有查詢到數據,讓咱們度一下調試模式查詢更多信息。)那咱們就點一下圖中的藍色字體進入調試模式。以下圖,

171019565.png

注,我們在調試模式中咱們能夠看到tcp.xml文檔依賴於tcp.php程序,咱們還得繼續增長tcp.php程序到scripts下。以下圖,

t45

注,好了到這裏咱們的tcp.php腳本上傳到/var/www/html/scripts中了,下機咱們來簡單看一下tcp.php文件。

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[root@cacti  ~]             #
[root@cacti  ~]             # cat /var/www/html/scripts/tcp.php 
<?php
$no_http_headers =             true             ;
/* display No errors */
error_reporting(E_ERROR);
include_once(             dirname             (__FILE__) .             "/../include/global.php"             );
include_once(             dirname             (__FILE__) .             "/../lib/snmp.php"             );
if             (!isset($called_by_script_server)) {
               array_shift($_SERVER[             "argv"             ]);
//print_r             ($_SERVER[             "argv"             ]);
               print call_user_func_array(             "TCP"             , $_SERVER[             "argv"             ]);
}
function             TCP($             hostname             , $host_id, $cmd, $rien, $arg2=             ""             , $arg3=             ""             ) {
//print             "xxx"             .$cmd;
              global $config;
              $filename = $config[             "base_path"             ].             '/scripts/ports.inc'             ;
              $host_method=db_fetch_cell(             "SELECT availability_method FROM `host` where id='"             . $host_id .             "'"             );
              if             ($host_method ==             "3"             ) {               //ping             enabled
               $val_limite=db_fetch_cell(             "SELECT ping_timeout FROM `host` where id='"             . $host_id .             "'"             );
              }
              if             ( ($host_method ==             "1"             ) || ($host_method ==             "2"             ) ) {               //snmp             enabled
               $val_limite=db_fetch_cell(             "SELECT snmp_timeout FROM `host` where id='"             . $host_id .             "'"             );
              }
              $val_limite=floor($val_limite             /1000             );
              if             ($val_limite ==             "0"             ) {
               $val_limite =             "1"             ;
              }
              if             ($cmd ==             "query"             ) {
               if             (is_readable($filename)) {
                $lines =             file             ($filename);
                foreach ($lines as $line) {
                 $             v             = explode(             "#"             ,$line);
                 $socket = @fsockopen(strtolower($             hostname             ), trim($             v             [0]), $error_number, $error, (float) $val_limite);
                 if             ($socket) { 
                  print trim($             v             [0]).             "!"             . trim($             v             [0]) .             "\n"             ;
                  fclose ($socket);
                 }
                }
               }
              }
              if             ($cmd ==             "get"             ) {
               $socket = @fsockopen(strtolower($             hostname             ), $arg2, $error_number, $error, (float) $val_limite);
               if             (!$socket) { 
                print             "0"             ;
               }             else             {
                print             "1"             ;
                fclose ($socket);
               }
              }
}
?>

注,這是個簡單的php程序,從上文中咱們能夠看出tcp.php文件還依賴一下文件ports.inc。咱們再來看下ports.inc內容,首先將ports.inc上傳到/var/www/html/scripts目錄下。以下圖,

t46

注,下面咱們來查看一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@cacti  ~]             # cat /var/www/html/scripts/ports.inc
80             #HTTP
443             #HTTP SSL
110             #POP
995             #POP SSL
25             #SMTP
21             #FTP
53             #DNS
389             #LDAP
23             #Telnet
22             #SSH
3306             #MYSQL
143             #IMAP
993             #IMAP SSL
514             #RSH
8003             #NAV GW
1433             #SQL Server
10000             #Ipsec
8090             #X-Ray
8080             #Zope
5903             #VNC
3389             #Mstsc

注,你們能夠看到這個文件是經常使用服務的端口號。好了,到這裏咱們的Linux Host模板才真正的增長完成,下面咱們來繼續爲Node2主機增長監控的主機圖形。

t47

注,你們從圖中能夠看到咱們的 」Data Query [TCP]「能夠成功的監控到咱們Node2上開戶的22號端口。下面咱們來選擇咱們要監控有圖形,以下圖:

171346309.pngt49

注, 我這裏選擇監控全部圖形,由於這個模板是專門爲Linux主機作的,因此顯示出來的圖形都是重要的。這裏特別要說明的是源於網卡流量的問題,由於我這裏測 試的主機是CentOS 6.4 x86_64系統,因此這裏的網卡流量類型應該選擇 」In/Out Bytes (64-bit Counters)「。如果32位系統應該選擇 」In/Out Bytes「。不然網卡流量監測會不許確,切記!

171408930.png

注,選擇好圖形後,點擊 」Create「 便可。下圖顯示的是全部圖形模板,繼續點擊 」Create「。

t51

注,爲了查看方便咱們將Node2主機增長到圖形樹中。增長圖形樹的過程我就不解釋了,上面已經演示不少遍了。

t52

注,我這裏增長一個新的圖形樹 」Remote Host「。以下圖,

t53

注,下面開始增長Node2主機。以下圖,

t54

注,增長完成Node2主機,點擊 」Create「 便可。

t55

171621870.png

注,下面咱們來查看一下新的圖形樹,你們能夠看到有兩個圖形樹,一個上」Default Tree「,另外一個是咱們剛剛增長的圖形樹」Remote Host「。

t57

注,大概過了五分鐘左右咱們就能夠看到圖形了。以下圖,

171639145.png

注,最終效果圖以下。

t59

4、Cacti 高級應用之Windows主機模板

1.增長Windows主機監控模板具體過程

t60

注,點擊 「瀏覽」,選擇Windows主機模板。

t61

注,點擊 」Import「,導入模板。

t62

注,查看一下導入的Windows主機模板。

t63

注,查看一下」Data Queries「。

t

注,沒有win32_procs.xml文件。

171758223.png

注,上傳win32_procs.xml文件。

t66

注,保存win32_procs.xml文件。

t69

注,沒有win_services.xml文件。

171816565.png

注,上傳 win_services.xml 文件。

t67

注,上傳win_services.php腳本。

t68

注,保存win_services.xml文件。

t70

好了,到這裏咱們的Windows主機模板增長完成。

開啓Windowssnmp服務

經過SNMP監控Windows主機須要在被監控的服務器上安裝簡單網絡管理協議(SNMP)的Windows組件,以Windows 7系統爲例:
首先,在控制面板中找到卸載程序
在彈出的窗口中單擊「打開或關閉Windows功能」;
勾選彈出窗口中的「簡單網絡管理協議(SNMP)」項後單擊「肯定」並根據提示完成安裝便可。
完成SNMP服務的安裝後,右鍵單擊「計算機」選擇「管理」 在彈出的「計算機管理」窗口中左側導航欄中找到「服務」,並在右側找到
「SNMP Service」項,啓動snmp服務;

下面咱們增一個Windows 測試主機。

2.增長Windows測試主機

注,因爲這臺主機是線上的生產主機因此對IP作了處理,請你們諒解。(說明:我們作測試的時候還得在Windows主機上安裝SNMP協議,怎麼安裝我就不具體說明了,你們都應該會的,不會的博友 ,請google一下。

t71

t72t73t74t75

t76

t77t78

t79

t80t81

3.將Windows主機增長到圖形樹中

t82

t83

t84

t85

4.最終效果圖

t86

好了,今天的博客就到這裏吧,在下一篇博客中咱們主要講解Cacti的多CPU模板與自定義腳本監控。最後,但願你們有所收穫^_^……

相關文章
相關標籤/搜索