大纲
一、实验环境说明
二、Cacti 监控服务器完整搭建过程演示(基于spine采集器)
三、Cacti 高级应用之Linux主机模板
四、Cacti 高级应用之Windows主机模板
注,操作系统 CentOS 6.4 x86_64,软件版本 Cacti 0.8.8b (目前最新版)。本博文中涉及的所有软件或文档请点击这里下载:http://yunpan.cn/Qbe5Wnnd7WLzw 。
一、实验环境说明
1.实验拓扑
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
|
二、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 <[email protected]>
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();
?>
|
注,用浏览器访问测试一下。
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 。)
注,最后增加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路径。
注,修改Cacti使用的Poller Type。
7.测试(监控Localhost)
注,点击“Devices”-> 大家可以看到默认已经有Localhost主机,我们把它删除重新新建一个默认主机。
注,大家可以看到我们勾选上“Locahost”主机,点击删除即可。
注,删除时会让你选择,上面是指只删除图形模板保留数据文件,下面是指删除全部包括图形模板与数据文件。我们这里选择下面选项,因为我们这是刚刚安装的没有什么数据。
注,到这里我们就删除默认主机了,下面我们新一个默认主机即监控cacti本身。
注,点击“Add”按钮,我们就可以增加主机了,下面是增加主机界面。我们输入相应的选项即可,一般只要输入下面几项:
General Host Options
SNMP Options
注,输入相关选项(如下图),点击“Create”按钮即可。
注,下面我们为cacti主机增加图形模板。点击右上脚的“Create Graphs for this Host”按钮。
注,因为我们默认安装cacti模板比较少,我们得后期增加模板才能符合我们线上的监控要求。我们先用默认模板增加,在下面的博文中我们会具体讲解怎么增加模板。
注,咱们选中我们要监控的选项,点击 ”Create“即可,如下图。
注,这边是图形模板颜色选项,我们用默认即可。点击”Create“
好了,到这里我们的cacti主机就增加完成了。为了我们查看图形方便,我们将cacti主机加入”Graph Trees“中查看。
注,点击 ”Graph Trees“ –> 点击”Default Tree“(当然你也可以增加新的图形树)。
注,进入默认的图形树,我们选择 ”Add“ 按钮,如下图。
注,在 ”Tree Item Type“ 中,我们选择 ”Host“,其它默认即可。点击 ”Create“。
注,到这里我们的图形树就增加完成了,我们点击 ”Save“ 即可。
注,下面我们查看一下 ”graphs“ 页面,大家可以看到显示的是 Default Tree 是里有台 cacti主机。图形要过一会才能出现,大家耐心等一下默认5分钟收集一下数据!
注,嘿嘿。再等一会,就可以看到图形了。下面是最终效果图,
三、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 ,我们这里已经下载好了,所以真使用。
2.增加Linux主机模板的具体过程
注,点击 ”Import Templates“ 页面。如下图,我们可以在这里导入我们下载到的模板,点击 ”浏览“。
注,选择我们要导入的模板,点击 ”import“ 即可。
注,下图显示是的模板的具体细节。包括图形模板与数据模板等。
注,到这里我们模板就导入完成了,下面我们来查看一下。
注,大家可以看到我们Linux Host模板已导入完成了。下面我们增加一个Linux主机测试一下!
3.监控Linux主机具体配置过程
注,点击 ”Devices“ 页面,-> ”Addr“ 来增加一台新主机。如下图,
注,填写相关参数,主要配置的参数有:
General Host Options
SNMP Options
具体参数如下图,
注,这里是填写的相关数据。如下图,这里选择的模板我们新增加的模板 ”Linux Host“。
注,点击右上脚的 ”Create Graphs for this Host“ 页面,我们为主机增加监控图形。
注,在这里我们选择我们要监控的相关图形。
注,在上图中的 ”Data Query [TCP]“ 时,我们发现在一个错误,我们下面便来解决一下这里错误。首先,我们来去看一下 ”Data Query“。如下图,
注,”Data Queries“ 是数据收集方法的一种,主要是xml脚本,来帮助我们收集数据。在图中我们可以看新增加的TCP收集方法,我们来点击一下 ”TCP“收集方法,看看里面的内容。如下图,
注,大家要图中可以看到有红色字体提醒我们说 TCP 收集方法的 XML 文件没有,从图中我们也可以看到 tcp.xml文件在安装目录下的resource目录中的script_server目录下,那下面我们就来增加一下tcp.xml文件吧。
注,将下载下来的tcp.xml脚本,上传到/var/www/html/resource/script_server下,我们点击 ”Save“。如下图,
注,好了到这里我们的Tcp.xml脚本就增加完成了,下面我们继续去增加图形。如下图,
注, 从图中可以看出,我们 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行,也许这是一个执行该查询数据的问题。你可以在调试模式下运行此查询来获取更多的信息。本人翻 译能力有限,大概意思是没有查询到数据,让我们度一下调试模式查询更多信息。)那我们就点一下图中的蓝色字体进入调试模式。如下图,
注,咱们在调试模式中我们可以看到tcp.xml文档依赖于tcp.php程序,我们还得继续增加tcp.php程序到scripts下。如下图,
注,好了到这里我们的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目录下。如下图,
注,下面我们来查看一下。
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主机增加监控的主机图形。
注,大家从图中可以看到我们的 ”Data Query [TCP]“可以成功的监控到我们Node2上开户的22号端口。下面我们来选择我们要监控有图形,如下图:
注, 我这里选择监控所有图形,因为这个模板是专门为Linux主机做的,所以显示出来的图形都是重要的。这里特别要说明的是源于网卡流量的问题,因为我这里测 试的主机是CentOS 6.4 x86_64系统,所以这里的网卡流量类型应该选择 ”In/Out Bytes (64-bit Counters)“。若是32位系统应该选择 ”In/Out Bytes“。否则网卡流量监测会不准确,切记!
注,选择好图形后,点击 ”Create“ 即可。下图显示的是所有图形模板,继续点击 ”Create“。
注,为了查看方便我们将Node2主机增加到图形树中。增加图形树的过程我就不解释了,上面已经演示很多遍了。
注,我这里增加一个新的图形树 ”Remote Host“。如下图,
注,下面开始增加Node2主机。如下图,
注,增加完成Node2主机,点击 ”Create“ 即可。
注,下面我们来查看一下新的图形树,大家可以看到有两个图形树,一个上”Default Tree“,另一个是我们刚刚增加的图形树”Remote Host“。
注,大概过了五分钟左右我们就可以看到图形了。如下图,
注,最终效果图如下。
四、Cacti 高级应用之Windows主机模板
1.增加Windows主机监控模板具体过程
注,点击 “浏览”,选择Windows主机模板。
注,点击 ”Import“,导入模板。
注,查看一下导入的Windows主机模板。
注,查看一下”Data Queries“。
注,没有win32_procs.xml文件。
注,上传win32_procs.xml文件。
注,保存win32_procs.xml文件。
注,没有win_services.xml文件。
注,上传 win_services.xml 文件。
注,上传win_services.php脚本。
注,保存win_services.xml文件。
好了,到这里我们的Windows主机模板增加完成。
开启Windows的snmp服务
通过SNMP监控Windows主机需要在被监控的服务器上安装简单网络管理协议(SNMP)的Windows组件,以Windows 7系统为例:
首先,在控制面板中找到“卸载程序”;
在弹出的窗口中单击“打开或关闭Windows功能”;
勾选弹出窗口中的“简单网络管理协议(SNMP)”项后单击“确定”并根据提示完成安装即可。
完成SNMP服务的安装后,右键单击“计算机”选择“管理” 在弹出的“计算机管理”窗口中左侧导航栏中找到“服务”,并在右侧找到 “SNMP Service”项,启动snmp服务;
下面我们增一个Windows 测试主机。
2.增加Windows测试主机
注,由于这台主机是线上的生产主机所以对IP做了处理,请大家谅解。(说明:咱们做测试的时候还得在Windows主机上安装SNMP协议,怎么安装我就不具体说明了,大家都应该会的,不会的博友 ,请google一下。)
3.将Windows主机增加到图形树中
4.最终效果图
好了,今天的博客就到这里吧,在下一篇博客中我们主要讲解Cacti的多CPU模板与自定义脚本监控。最后,希望大家有所收获^_^……