Linux 监控工具之Cacti使用详解(三)推荐

大纲

一、实验环境说明

二、Cacti 监控服务器完整搭建过程演示(基于spine采集器)

三、Cacti 高级应用之Linux主机模板

四、Cacti 高级应用之Windows主机模板

注,操作系统 CentOS 6.4 x86_64,软件版本 Cacti 0.8.8b (目前最新版)。本博文中涉及的所有软件或文档请点击这里下载:http://yunpan.cn/QhIWp3BZAw5Cu 提取码 81f7 。

一、实验环境说明

1.实验拓扑

2.同步节点时间

[root@cacti~]#ntpdate202.120.2.101[root@node2~]#ntpdate202.120.2.101

3.安装yum源

[root@cacti~]#rpm-ivhhttp://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm[root@node2~]#rpm-ivhhttp://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。

[root@cacti~]#yuminstall-ynet-snmpnet-snmp-utilsnet-snmp-devel

注,修改配置文件。

[root@cacti~]#vim/etc/snmp/snmpd.confviewsystemviewincluded.1.3.6.1.2.1.1viewsystemviewincluded.1

注,启动snmpd服务。

[root@cacti~]#servicesnmpdstart正在启动snmpd:[确定]

注,测试一下net-snmp。

[root@cacti~]#snmpnetstat-v2c-cpublic-Cna-Cptcp127.0.0.1ActiveInternet(tcp)Connections(includingservers)ProtoLocalAddressRemoteAddress(state)tcp*.22*.*LISTENtcp127.0.0.1.25*.*LISTENtcp127.0.0.1.199*.*LISTENtcp127.0.0.1.6010*.*LISTENtcp192.168.18.201.22192.168.18.19.53322ESTABLISHED

2.安装rrdtool工具

注,安装rrdtool rrdtool-devel。

[root@cacti~]#yuminstall-yrrdtoolrrdtool-devel

注,测试一下。

[root@cacti~]#rrdtoolRRDtool1.3.8Copyright1997-2009byTobiasOetiker tobi@oetiker.ch CompiledAug21201010:57:18Usage:rrdtool[options]commandcommand_optionsValidcommands:create,update,updatev,graph,graphv,dump,restore,last,lastupdate,first,info,fetch,tune,resize,xportRRDtoolisdistributedundertheTermsoftheGNUGeneralPublicLicenseVersion2.(www.gnu.org/copyleft/gpl.html)FormoreinformationreadtheRRDmanpages

3.安装LAMP环境

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

[root@cacti~]#yuminstall-yhttpdphpphp-mysqlphp-snmpphp-xmlphp-gdmysqlmysql-servermysql-develgdgd-devel

注,设置开机自启动并启动服务。

[root@cacti~]#chkconfigsnmpdon[root@cacti~]#chkconfighttpdon[root@cacti~]#chkconfigmysqldon[root@node1~]#chkconfighttpdon[root@node1~]#servicehttpdstart正在启动httpd:[确定][root@node1~]#chkconfigmysqldon[root@node1~]#servicemysqldstart正在启动mysqld:[确定][root@cacti~]#netstat-ntulpActiveInternetconnections(onlyservers)ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programnametcp000.0.0.0:220.0.0.0:*LISTEN1016/sshdtcp00127.0.0.1:250.0.0.0:*LISTEN1093/mastertcp00127.0.0.1:60100.0.0.0:*LISTEN1128/sshdtcp00127.0.0.1:1990.0.0.0:*LISTEN1272/snmpdtcp000.0.0.0:33060.0.0.0:*LISTEN6498/mysqldtcp00:::80:::*LISTEN6298/httpdtcp00:::22:::*LISTEN1016/sshdtcp00::1:25:::*LISTEN1093/mastertcp00::1:6010:::*LISTEN1128/sshdudp000.0.0.0:1610.0.0.0:*1272/snmpd

4.测试LAMP环境

注,提供php页面。

[root@cactihtml]#vimindex.php ?phpphpinfo();? 

注,用浏览器访问测试一下。

5.安装cacti

[root@cacti~]#cd/var/www/html/[root@cactihtml]#rm-rf*[root@cactihtml]#ls[root@cacti~]#tarxfcacti-0.8.8b.tar.gz[root@cacti~]#cdcacti-0.8.8b[root@cacticacti-0.8.8b]#mv*/var/www/html/[root@cacticacti-0.8.8b]#cd/var/www/html/[root@cactihtml]#lsabout.phpdata_templates.phpgraph_templates.phplogscriptsauth_changepassword.phpdocsgraph_view.phplogout.phpscript_server.phpauth_login.phpgprint_presets.phpgraph_xport.phppluginsscript_server.plcacti.sqlgraph_image.phphost.phpplugins.phpsettings.phpcdef.phpgraph.phphost_templates.phppoller_commands.phptemplates_export.phpcligraph_settings.phpimagespoller_export.phptemplates_import.phpcmd.phpgraphs_items.phpincludepoller.phptree.phpcolor.phpgraphs_new.phpindex.phpREADMEuser_admin.phpdata_input.phpgraphs.phpinstallresourceutilities.phpdata_queries.phpgraph_templates_inputs.phplibrradata_sources.phpgraph_templates_items.phpLICENSErra.php

注,创建cacti用户并授权。

[root@cactihtml]#useraddcacti[root@cactihtml]#chown-Rcacti.cacti./*[root@cactihtml]#ll总用量1088-rw-r--r--1cacticacti59458月710:31about.php-rw-r--r--1cacticacti53488月710:31auth_changepassword.php-rw-r--r--1cacticacti142888月710:31auth_login.php-rw-r--r--1cacticacti1783498月710:31cacti.sql-rw-r--r--1cacticacti216588月710:31cdef.phpdrwxr-xr-x2cacticacti40968月710:31cli-rw-r--r--1cacticacti266208月710:31cmd.php-rw-r--r--1cacticacti69748月710:31color.php-rw-r--r--1cacticacti250688月710:31data_input.php-rw-r--r--1cacticacti355058月710:31data_queries.php-rw-r--r--1cacticacti601178月710:31data_sources.php-rw-r--r--1cacticacti329208月710:31data_templates.phpdrwxr-xr-x5cacticacti40968月710:31docs-rw-r--r--1cacticacti61078月710:31gprint_presets.php-rw-r--r--1cacticacti36578月710:31graph_image.php-rw-r--r--1cacticacti134698月710:31graph.php-rw-r--r--1cacticacti92088月710:31graph_settings.php-rw-r--r--1cacticacti174268月710:31graphs_items.php-rw-r--r--1cacticacti401668月710:31graphs_new.php-rw-r--r--1cacticacti605718月710:31graphs.php-rw-r--r--1cacticacti100068月710:31graph_templates_inputs.php-rw-r--r--1cacticacti185428月710:31graph_templates_items.php-rw-r--r--1cacticacti267038月710:31graph_templates.php-rw-r--r--1cacticacti403138月710:31graph_view.php-rw-r--r--1cacticacti60228月710:31graph_xport.php-rw-r--r--1cacticacti600918月710:31host.php-rw-r--r--1cacticacti200318月710:31host_templates.phpdrwxr-xr-x2cacticacti40964月42012imagesdrwxr-xr-x4cacticacti409610月1709:49include-rw-r--r--1cacticacti23138月710:31index.phpdrwxr-xr-x2cacticacti40968月710:31installdrwxr-xr-x3cacticacti40968月710:31lib-rw-r--r--1cacticacti151414月42012LICENSEdrwxr-xr-x2cacticacti40964月42012log-rw-r--r--1cacticacti28388月710:31logout.phpdrwxr-xr-x2cacticacti40968月710:31plugins-rw-r--r--1cacticacti273628月710:31plugins.php-rw-r--r--1cacticacti43108月710:31poller_commands.php-rw-r--r--1cacticacti22438月710:31poller_export.php-rw-r--r--1cacticacti180568月710:31poller.php-rw-r--r--1cacticacti484月42012READMEdrwxr-xr-x5cacticacti40964月42012resourcedrwxr-xr-x2cacticacti409610月1710:51rra-rw-r--r--1cacticacti73948月710:31rra.phpdrwxr-xr-x2cacticacti40968月710:31scripts-rw-r--r--1cacticacti108208月710:31script_server.php-rw-r--r--1cacticacti3534月42012script_server.pl-rw-r--r--1cacticacti57618月710:31settings.php-rw-r--r--1cacticacti63458月710:31templates_export.php-rw-r--r--1cacticacti58358月710:31templates_import.php-rw-r--r--1cacticacti195298月710:31tree.php-rw-r--r--1cacticacti449978月710:31user_admin.php-rw-r--r--1cacticacti656358月710:31utilities.php

注,修改cacti配置文件。

[root@cactihtml]#cdinclude/[root@cactiinclude]#vimconfig.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创建数据库并导入表结构。

[root@cacti~]#mysqladmincreatecacti[root@cacti~]#mysqlcacti /var/www/html/cacti.sql

注,创建cacti数据库管理用户并授权。

[root@cacti~]#mysql-e"GRANTALLONcacti.*TOcactiuser@localhostIDENTIFIEDBY'cactiuser'"[root@cacti~]#mysql-ucactiuser-pcactiuserWelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis10Serverversion:5.1.69SourcedistributionCopyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql showdatabases;+--------------------+|Database|+--------------------+|information_schema||cacti||test|+--------------------+3rowsinset(0.00sec)mysql 

注,下面我们初始化一下cacti。(下面的内容我就不全部注释在上一篇博文中全部讲解过,不清楚的博友可以参考一下这篇博文:http://freeloda.blog.51cto.com/2033581/1308140 。)

注,最后增加crontab让net-snmp每5分钟抓取一次数据。

[root@cactihtml]#echo'*/5****/usr/bin/php/var/www/html/poller.php /dev/null' /var/spool/cron/cacti[root@cactihtml]#crontab-ucacti-l*/5****/usr/bin/php/var/www/html/poller.php /dev/null

注,为了防止这个任务计划不执行,我们最好手动验证一下。

[root@cactihtml]#su-cacti[cacti@cacti~]$/usr/bin/php/var/www/html/poller.phpPHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline165PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline165PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline166PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline166PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline167PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline167PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline168PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline168PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline169PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline169PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline170PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline170PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline171PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_constants.phponline171PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline671PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline671PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline672PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline672PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline673PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline673PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline674PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline674PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline675PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline675PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline676PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline676PHPWarning:strtotime():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline677PHPWarning:date():Itisnotsafetorelyonthesystem'stimezonesettings.Youare*required*tousethedate.timezonesettingorthedate_default_timezone_set()function.Incaseyouusedanyofthosemethodsandyouarestillgettingthiswarning,youmostlikelymisspelledthetimezoneidentifier.Weselected'Asia/Chongqing'for'CST/8.0/noDST'insteadin/web/vhosts/cacti/include/global_arrays.phponline677

注,大家可以看到上面报了一大堆错,是什么错误哟?主要是因为我们php.ini的时区设置的不对,下面我们来修改一下php时区。

[root@cacti~]#vim/etc/php.inidate.timezone=Asia/Shanghai[root@cacti~]#servicehttpdrestart停止httpd:[确定]正在启动httpd:[确定]

注,接下来我们再来测试一下。

[cacti@cacti~]$/usr/bin/php/var/www/html/poller.php--forceOKu:0.00s:0.00r:0.06OKu:0.00s:0.01r:0.08OKu:0.00s:0.01r:0.08OKu:0.00s:0.01r:0.08OKu:0.00s:0.01r:0.11OKu:0.00s:0.01r:0.11OKu:0.00s:0.01r:0.11OKu:0.00s:0.01r:0.1110/17/201311:30:11AM-SYSTEMSTATS:Time:0.2451Method:spineProcesses:3Threads:5Hosts:2HostsPerProcess:1DataSources:11RRDsProcessed:8

6.安装spine多线程采集器

注,解压并编译安装sipne。

[root@cacti~]#tarxfcacti-spine-0.8.8b.tar.gz[root@cacti~]#cdcacti-spine-0.8.8b[root@cacticacti-spine-0.8.8b]#./configure[root@cacticacti-spine-0.8.8b]#make makeinstall

注,提供配置文件并根据需求修改。

[root@cacticacti-spine-0.8.8b]#cd/usr/local/spine/etc/[root@cactietc]#cpspine.conf.distspine.conf[root@cactietc]#vimspine.confDB_HostlocalhostDB_DatabasecactiDB_UsercactiuserDB_PasscactiuserDB_Port3306DB_PreG0

注,测试一下spine。

[root@cactietc]#/usr/local/spine/bin/spineSPINE:Usingspineconfigfile[spine.conf]SPINE:Version0.8.8bstartingSPINE:Time:1.3157s,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文件。

[root@cacti~]#[root@cacti~]#cat/var/www/html/scripts/tcp.php ?php$no_http_headers=true;/*displayNoerrors*/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"]);printcall_user_func_array("TCP",$_SERVER["argv"]);functionTCP($hostname,$host_id,$cmd,$rien,$arg2="",$arg3=""){//print"xxx".$cmd;global$config;$filename=$config["base_path"].'/scripts/ports.inc';$host_method=db_fetch_cell("SELECTavailability_methodFROM`host`whereid='".$host_id."'");if($host_method=="3"){//pingenabled$val_limite=db_fetch_cell("SELECTping_timeoutFROM`host`whereid='".$host_id."'");}if(($host_method=="1")||($host_method=="2")){//snmpenabled$val_limite=db_fetch_cell("SELECTsnmp_timeoutFROM`host`whereid='".$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($linesas$line){$v=explode("#",$line);$socket=@fsockopen(strtolower($hostname),trim($v[0]),$error_number,$error,(float)$val_limite);if($socket){printtrim($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目录下。如下图,

注,下面我们来查看一下。

[root@cacti~]#cat/var/www/html/scripts/ports.inc80#HTTP443#HTTPSSL110#POP995#POPSSL25#SMTP21#FTP53#DNS389#LDAP23#Telnet22#SSH3306#MYSQL143#IMAP993#IMAPSSL514#RSH8003#NAVGW1433#SQLServer10000#Ipsec8090#X-Ray8080#Zope5903#VNC3389#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 测试主机。

2.增加Windows测试主机

注,由于这台主机是线上的生产主机所以对IP做了处理,请大家谅解。(说明:咱们做测试的时候还得在Windows主机上安装SNMP协议,怎么安装我就不具体说明了,大家都应该会的,不会的博友 ,请google一下。)

3.将Windows主机增加到图形树中

4.最终效果图

好了,今天的博客就到这里吧,在下一篇博客中我们主要讲解Cacti的多CPU模板与自定义脚本监控。最后,希望大家有所收获^_^……

不然你大概会一直好奇和不甘吧——

Linux 监控工具之Cacti使用详解(三)推荐

相关文章:

你感兴趣的文章:

标签云: