大纲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/Qbe5Wnnd7WLzw 。sql
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();
?>
|
注,用浏览器访问测试一下。
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
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
|
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分钟收集一下数据!
注,嘿嘿。再等一会,就能够看到图形了。下面是最终效果图,
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 ,咱们这里已经下载好了,因此真使用。
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“。
注,大概过了五分钟左右咱们就能够看到图形了。以下图,
注,最终效果图以下。
4、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模板与自定义脚本监控。最后,但愿你们有所收获^_^……