天天看點

cacti

Cacti是一套基于PHP,MySQL,SNMP及RRDTool開發的網絡流量監測圖形分析工具

Cacti是通過 snmpget來擷取資料,使用 RRDtool繪畫圖形,而且你完全可以不需要了解RRDtool複雜的參數。它提供了非常強大的資料和使用者管理功能,可以指定每一個使用者能檢視樹狀結構、host以及任何一張圖,還可以與LDAP結合進行使用者驗證,同時也能自己增加模闆,功能非常強大完善。界面友好。

cacti

實驗環境

centos 5.5

實驗軟體

cacti-0.8.8a.tar.gz

cacti-spine-0.8.8a.tar.gz

rrdtool-1.3.8.tar.gz

軟體安裝

yum install httpd* mysql* php php-mysql* mod_ssl mod_mod_auth_mysql mod_auth_mysql mod_perl php-gd php-xml xml php-mbstring php-ldap php-pear php-xmlrpc -y

yum install mysql-connector-odbc mysql-devel libdbi-dbd-mysql -y

yum install net-snmp* pango-devel* cairo-devel* intltool -y

yum install zlib libpng freetype libart_lgpl libart_lgpl-devel libxml* pango*  -y

service httpd restart

service mysqld restart

service snmpd restart

chkconfig --level 35 httpd on  

chkconfig --level 35 snmpd on  

chkconfig --level 35 mysqld on

setenforce 0  

vim /etc/httpd/conf/httpd.conf

ServerName           *:80  改為

#AddType application/x-tar .tgz 找到

#AddType application/x-tar .tgz

AddType application/x-tar .tgz  改為

AddType application/x-httpd-php .php

<a href="https://s2.51cto.com/wyfs02/M01/08/54/wKiom1nfiyHArQIJAAFuDfVq42Q089.jpg-wh_500x0-wm_3-wmp_4-s_794471625.jpg" target="_blank"></a>

touch /var/www/html/test.php

vim /var/www/html/test.php 

&lt;?php

phpinfo();

?&gt;

<a href="http://192.168.1.102/test.php" target="_blank">http://伺服器ip/test.php</a>

<a href="https://s3.51cto.com/wyfs02/M02/08/54/wKiom1nfi6ORP8U6AAFFA2PazDg957.jpg-wh_500x0-wm_3-wmp_4-s_1407132545.jpg" target="_blank"></a>

netstat -tuplna | grep httpd

tcp        0      0 :::80                       :::*                        LISTEN      16796/httpd         

tcp        0      0 :::443                      :::*                        LISTEN      16796/httpd   

netstat -tuplna | grep mysqld

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17003/mysqld

ps -aux | grep httpd

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

root     16796  0.0  1.3 313176 13284 ?        Ss   22:58   0:00 /usr/sbin/httpd

apache   16798  0.0  0.6 313176  6924 ?        S    22:58   0:00 /usr/sbin/httpd

apache   16799  0.0  0.6 313176  6924 ?        S    22:58   0:00 /usr/sbin/httpd

ps -aux | grep mysqld

root     16901  0.0  0.1 108188  1596 pts/3    S    22:58   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql

mysql    17003  0.0  3.1 367516 32380 pts/3    Sl   22:58   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

root     27873  0.0  0.0 103324   888 pts/5    S+   23:19   0:00 grep mysqld

mysqladmin -uroot password 資料庫密碼

mysql -uroot -p資料庫密碼

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.1.73 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&gt; create database cacti;  建立資料庫

mysql&gt; grant all privileges on  cacti.*to  cacti@localhost identified by 'cacti'; 授權使用者保留root最高權限

mysql&gt; select host,user from mysql.user; 檢視使用者以及權限

+-----------+-------+

| host      | user  |

| 127.0.0.1 | root  |

| centos6   |       |

| centos6   | root  |

| localhost |       |

| localhost | cacti |

| localhost | root  |

6 rows in set (0.00 sec)

mysql&gt; flush privileges; 重新整理權限

mysql -ucacti -pcacti   檢視授權使用者是否可以登入資料庫

Your MySQL connection id is 4

mysql&gt; show databases;

+--------------------+

| Database           |

| information_schema |

| cacti              |

| test               |

3 rows in set (0.00 sec)

tar zxvf cacti-0.8.8a.tar.gz 

mv cacti-0.8.8a /var/www/html/cacti

tar zxvf rrdtool-1.3.8.tar.gz 

cd rrdtool-1.3.8

./configure --prefix=/usr/local/rrdtool

make &amp;&amp; make install

tar zxvf cacti-spine-0.8.8a.tar.gz 

cd cacti-spine-0.8.8a

./configure  --prefix=/usr/local/spine

mysql -ucacti -pcacti cacti &lt; /var/www/html/cacti/cacti.sql 導入sql檔案

mysql -ucacti -pcacti 

Your MySQL connection id is 10

mysql&gt; show databases; 

| cacti              |

mysql&gt; use cacti; 

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql&gt; show tables;

+---------------------------+

| Tables_in_cacti           |

| cdef                      |

| cdef_items                |

| colors                    |

| data_input                |

| data_input_data           |

| data_input_fields         |

| data_local                |

| data_template             |

| data_template_data        |

| data_template_data_rra    |

| data_template_rrd         |

| graph_local               |

| graph_template_input      |

| graph_template_input_defs |

| graph_templates           |

| graph_templates_gprint    |

| graph_templates_graph     |

| graph_templates_item      |

| graph_tree                |

| graph_tree_items          |

| host                      |

| host_graph                |

| host_snmp_cache           |

| host_snmp_query           |

| host_template             |

| host_template_graph       |

| host_template_snmp_query  |

| plugin_config             |

| plugin_db_changes         |

| plugin_hooks              |

| plugin_realms             |

| poller                    |

| poller_command            |

| poller_item               |

| poller_output             |

| poller_reindex            |

| poller_time               |

| rra                       |

| rra_cf                    |

| settings                  |

| settings_graphs           |

| settings_tree             |

| snmp_query                |

| snmp_query_graph          |

| snmp_query_graph_rrd      |

| snmp_query_graph_rrd_sv   |

| snmp_query_graph_sv       |

| user_auth                 |

| user_auth_perms           |

| user_auth_realm           |

| user_log                  |

| version                   |

52 rows in set (0.00 sec)

mysql&gt; 

vim /var/www/html/cacti/include/config.php 

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cacti";  授權使用者

$database_password = "cacti";  授權使用者密碼

$database_port = "3306";

$database_ssl = false;

vim /var/www/html/cacti/include/global.php 

/* Default database settings*/

$database_username = "cacti"; 授權使用者

$database_password = "cacti"; 授權使用者密碼

vim /etc/crontab                       

*/5 * * * * root php /var/www/html/cacti/poller.php

cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf

vim /etc/spine.conf

DB_Host       localhost

DB_Database    cacti 

DB_User       cacti 授權使用者

DB_Pass       cacti 授權使用者密碼

DB_Port       3306

DB_PreG       0

<a href="http://blog.51cto.com/cacti">http://伺服器ip/cacti</a>

find /usr/local/ -name rrdtool

/usr/local/rrdtool-1.3.8/bin/rrdtool 複制路徑重新整理即可

預設使用者名  admin  admin

修改密碼 給為 新的密碼

cacti搭建完畢

cacti搭建完成,為了能更好使用需要修改snmp配置檔案

vim  /etc/snmp/snmpd.conf

找到

com2sec notConfigUser  default       public

更改為

com2sec notConfigUser  all           public  

access  notConfigGroup ""      any       noauth    exact  systemview none none

access  notConfigGroup ""      any       noauth    exact  all none none

#view all    included  .1                               80

view all    included  .1                               80

#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc

改為

view mib2   included  .iso.org.dod.internet.mgmt.mib-2  fc

/etc/rc.d/init.d/crond restart

Stopping crond: [  OK  ]

Starting crond: [  OK  ]

vim /etc/php.ini

找到 ;date.timezone =

改為 date.timezone = Asia/shanghai

測試rrdtool,是否生成圖檔的指令

php /var/www/html/cacti/poller.php

05/23/2013 10:39:23 PM - POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval!  The Poller Interval is '60' seconds, with a maximum of a '300' second Cron, but 262 seconds have passed since the last poll!

OK u:0.00 s:0.01 r:7.62

OK u:0.00 s:0.01 r:10.25

05/23/2013 10:39:34 PM - SYSTEM STATS: Time:10.9177 Method:spine Processes:1 Threads:1 Hosts:17 HostsPerProcess:17 DataSources:20 RRDsProcessed:10

OK u:0.00 s:0.01 r:10.82

OK u:0.00 s:0.01 r:10.83

OK u:0.00 s:0.01 r:10.84

看到這個提示,證明rrdtool已經獲得了資料

檢查snmp獲得資料是否正常可以使用

snmpwalk -v 2c -c public 127.0.0.1 if

IF-MIB::ifIndex.1 = INTEGER: 1

IF-MIB::ifIndex.2 = INTEGER: 2

IF-MIB::ifIndex.3 = INTEGER: 3

IF-MIB::ifIndex.4 = INTEGER: 4

IF-MIB::ifDescr.1 = STRING: lo

IF-MIB::ifDescr.2 = STRING: eth0

IF-MIB::ifDescr.3 = STRING: eth1

IF-MIB::ifDescr.4 = STRING: sit0

IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)

IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)

IF-MIB::ifType.3 = INTEGER: ethernetCsmacd(6)

IF-MIB::ifType.4 = INTEGER: tunnel(131)

IF-MIB::ifMtu.1 = INTEGER: 16436

IF-MIB::ifMtu.2 = INTEGER: 1500

IF-MIB::ifMtu.3 = INTEGER: 1500

IF-MIB::ifMtu.4 = INTEGER: 1480

IF-MIB::ifSpeed.1 = Gauge32: 10000000

IF-MIB::ifSpeed.2 = Gauge32: 1000000000

IF-MIB::ifSpeed.3 = Gauge32: 1000000000

IF-MIB::ifSpeed.4 = Gauge32: 0

IF-MIB::ifPhysAddress.1 = STRING: 

IF-MIB::ifPhysAddress.2 = STRING: 0:50:56:b2:dd:6a

IF-MIB::ifPhysAddress.3 = STRING: 0:50:56:b2:4a:bf

IF-MIB::ifPhysAddress.4 = STRING: 

IF-MIB::ifAdminStatus.1 = INTEGER: up(1)

IF-MIB::ifAdminStatus.2 = INTEGER: up(1)

IF-MIB::ifAdminStatus.3 = INTEGER: down(2)

IF-MIB::ifAdminStatus.4 = INTEGER: down(2)

IF-MIB::ifOperStatus.1 = INTEGER: up(1)

IF-MIB::ifOperStatus.2 = INTEGER: up(1)

IF-MIB::ifOperStatus.3 = INTEGER: down(2)

IF-MIB::ifOperStatus.4 = INTEGER: down(2)

IF-MIB::ifLastChange.1 = Timeticks: (0) 0:00:00.00

IF-MIB::ifLastChange.2 = Timeticks: (0) 0:00:00.00

IF-MIB::ifLastChange.3 = Timeticks: (0) 0:00:00.00

IF-MIB::ifLastChange.4 = Timeticks: (0) 0:00:00.00

IF-MIB::ifInOctets.1 = Counter32: 456696

IF-MIB::ifInOctets.2 = Counter32: 13011691

IF-MIB::ifInOctets.3 = Counter32: 0

IF-MIB::ifInOctets.4 = Counter32: 0

IF-MIB::ifInUcastPkts.1 = Counter32: 3736

IF-MIB::ifInUcastPkts.2 = Counter32: 82264

IF-MIB::ifInUcastPkts.3 = Counter32: 0

IF-MIB::ifInUcastPkts.4 = Counter32: 0

IF-MIB::ifInNUcastPkts.1 = Counter32: 0

IF-MIB::ifInNUcastPkts.2 = Counter32: 0

IF-MIB::ifInNUcastPkts.3 = Counter32: 0

IF-MIB::ifInNUcastPkts.4 = Counter32: 0

IF-MIB::ifInDiscards.1 = Counter32: 0

IF-MIB::ifInDiscards.2 = Counter32: 0

IF-MIB::ifInDiscards.3 = Counter32: 0

IF-MIB::ifInDiscards.4 = Counter32: 0

IF-MIB::ifInErrors.1 = Counter32: 0

IF-MIB::ifInErrors.2 = Counter32: 119

IF-MIB::ifInErrors.3 = Counter32: 0

IF-MIB::ifInErrors.4 = Counter32: 0

IF-MIB::ifInUnknownProtos.1 = Counter32: 0

IF-MIB::ifInUnknownProtos.2 = Counter32: 0

IF-MIB::ifInUnknownProtos.3 = Counter32: 0

IF-MIB::ifInUnknownProtos.4 = Counter32: 0

IF-MIB::ifOutOctets.1 = Counter32: 456696

IF-MIB::ifOutOctets.2 = Counter32: 38508110

IF-MIB::ifOutOctets.3 = Counter32: 0

IF-MIB::ifOutOctets.4 = Counter32: 0

IF-MIB::ifOutUcastPkts.1 = Counter32: 3736

IF-MIB::ifOutUcastPkts.2 = Counter32: 70719

IF-MIB::ifOutUcastPkts.3 = Counter32: 0

IF-MIB::ifOutUcastPkts.4 = Counter32: 0

IF-MIB::ifOutNUcastPkts.1 = Counter32: 0

IF-MIB::ifOutNUcastPkts.2 = Counter32: 0

IF-MIB::ifOutNUcastPkts.3 = Counter32: 0

IF-MIB::ifOutNUcastPkts.4 = Counter32: 0

IF-MIB::ifOutDiscards.1 = Counter32: 0

IF-MIB::ifOutDiscards.2 = Counter32: 0

IF-MIB::ifOutDiscards.3 = Counter32: 0

IF-MIB::ifOutDiscards.4 = Counter32: 0

IF-MIB::ifOutErrors.1 = Counter32: 0

IF-MIB::ifOutErrors.2 = Counter32: 0

IF-MIB::ifOutErrors.3 = Counter32: 0

IF-MIB::ifOutErrors.4 = Counter32: 0

IF-MIB::ifOutQLen.1 = Gauge32: 0

IF-MIB::ifOutQLen.2 = Gauge32: 0

IF-MIB::ifOutQLen.3 = Gauge32: 0

IF-MIB::ifOutQLen.4 = Gauge32: 0

IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero

IF-MIB::ifSpecific.2 = OID: SNMPv2-SMI::zeroDotZero

IF-MIB::ifSpecific.3 = OID: SNMPv2-SMI::zeroDotZero

IF-MIB::ifSpecific.4 = OID: SNMPv2-SMI::zeroDotZero

如果出現這一些,證明snmp可以正常抓取資料

<a href="http://blog.51cto.com/attachment/201305/120148262.png" target="_blank"></a>

如果出現這個,證明cacti正常工作

配置用戶端,用戶端以windows xp為例

1 控制台-添加删除程式-添加删除windows元件-管理與監視工具-snmp有兩個選項,全部勾線安裝

2 cmd-services.msc

3 找到snmp服務

<a href="http://blog.51cto.com/attachment/201305/101956333.png" target="_blank"></a>

右鍵-屬性

<a href="http://blog.51cto.com/attachment/201305/101956361.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201305/101956383.png" target="_blank"></a>

團體名字預設為public(可以更改),但是要和伺服器端名字相同

接收來自snmp包的ip位址為伺服器端ip位址,點選應用-确定

重新開機用戶端snmp服務

<a href="http://blog.51cto.com/attachment/201305/102339334.png" target="_blank"></a>

右鍵-重新開機服務

<a href="http://blog.51cto.com/attachment/201305/102505945.png" target="_blank"></a>

這樣windows xp用戶端配置就完成了

介紹如何,配置用戶端,用戶端以linux(centos) 為例

yum -y install net-snmp

com2sec notConfigUser  cacti服務端ip          public  

如果監控Linux用戶端出現snmp檢測不到網卡,處理方法是,添加主機選擇 ccd/netSNMPHost 這個模版

本文轉自 mailfile 51CTO部落格,原文連結:http://blog.51cto.com/mailfile/1199311,如需轉載請自行聯系原作者