Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。用来监控网络流量、cpu使用率、内存使用率、硬盘使用率等。可以直观的监控各种数据流量,可以安装扩展插件,同时支持短信邮件告警等功能。
Nagios是一个监视系统运行状态和网络信息的监视系统。Nagios能监视所指定的本地或远程主机以及服务,提供异常通知功能,同时还可以安装各种模块插件,自定义监控脚本等。
两者区别:Cacti偏重于网络流量,系统负载方面的监控。而 Nagios偏重于系统服务方面的监控,你可以在被监控的机器上写自己的程序(shell,c 或 perl都可以) 。Nagios则通过这些脚本来对服务进行监控。Nagios可以和短信发送机配合用来监控规模较大的网站。
安装扩展yum源
<code>[root@www ~]</code><code># rpm -ivh http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm</code>
<code>Retrieving http:</code><code>//mirrors</code><code>.yun-idc.com</code><code>/epel/6/i386/epel-release-6-8</code><code>.noarch.rpm</code>
<code>warning: </code><code>/var/tmp/rpm-tmp</code><code>.1jSHmn: Header V3 RSA</code><code>/SHA256</code> <code>Signature, key ID 0608b895: NOKEY</code>
<code>Preparing... </code><code>########################################### [100%]</code>
<code> </code><code>1:epel-release </code><code>########################################### [100%]</code>
<code>[root@www ~]</code><code># ls /etc/yum.repos.d/epel*</code>
<code>/etc/yum</code><code>.repos.d</code><code>/epel</code><code>.repo </code><code>/etc/yum</code><code>.repos.d</code><code>/epel-testing</code><code>.repo</code>
##########CACTI#########
一、安装LAMP环境
<code>[root@www ~]</code><code># yum -y install httpd php php-mysql mysql mysql-server mysql-devel php-gd libjpeg libjpeg-devel libpng libpng-devel</code>
二、安装net-snmp、php-snmp、net-snmp-utils
<code>[root@www ~]</code><code># yum -y install net-snmp net-snmp-utils net-snmp-libs php-snmp</code>
三、安装rrdtool图形整合工具
<code>[root@www ~]</code><code># yum -y install rrdtool</code>
<code>[root@www ~]</code><code># rrdtool </code>
<code>RRDtool 1.3.8 Copyright 1997-2009 by Tobias Oetiker <[email protected]></code>
<code> </code><code>Compiled Apr 3 2014 13:07:03</code>
<code>Usage: rrdtool [options] </code><code>command</code> <code>command_options</code>
<code>Valid commands: create, update, updatev, graph, graphv, dump, restore,</code>
<code>last, lastupdate, first, info, fetch, tune,</code>
<code>resize, xport</code>
<code>RRDtool is distributed under the Terms of the GNU General</code>
<code>Public License Version 2. (www.gnu.org</code><code>/copyleft/gpl</code><code>.html)</code>
<code>For </code><code>more</code> <code>information </code><code>read</code> <code>the RRD manpages</code>
四、安装cacti主程序
下载cacti-0.8.8f.tar.gz
[root@www ~]# wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz
安装cacti,解压放到网站目录下
[root@www ~]# tar zxf cacti-0.8.8f.tar.gz
[root@www ~]# mv cacti-0.8.8f /var/www/html/cacti/
[root@www ~]# chown -R root. /var/www/html/cacti/
初始化数据库
[root@www ~]# /etc/init.d/mysqld start
<code>[root@www ~]</code><code># mysql_secure_installation </code>
<code>Enter current password </code><code>for</code> <code>root (enter </code><code>for</code> <code>none):</code>
<code>Set root password? [Y</code><code>/n</code><code>] y</code>
<code>Remove anonymous </code><code>users</code><code>? [Y</code><code>/n</code><code>] y</code>
<code>Disallow root login remotely? [Y</code><code>/n</code><code>] y</code>
<code>Remove </code><code>test</code> <code>database and access to it? [Y</code><code>/n</code><code>] y</code>
<code>Reload privilege tables now? [Y</code><code>/n</code><code>] y</code>
创建cacti数据库
<code>[root@www ~]</code><code># mysql -uroot -p -e "create database cacti"</code>
授权cacti数据库用户
<code>[root@www ~]</code><code># mysql -uroot -p -e "grant all on cacti.* to 'cacti'@'localhost' identified by 'cactipass';"</code>
<code>[root@www ~]</code><code># mysql -uroot -p -e "flush privileges;"</code>
导入数据库文件
<code>[root@www ~]</code><code># mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql</code>
修改cacti的配置文件config.php
<code>[root@www ~]</code><code># vim /var/www/html/cacti/include/config.php</code>
<code>$database_type = </code><code>"mysql"</code><code>;</code>
<code>$database_default = </code><code>"cacti"</code><code>;</code>
<code>$database_hostname = </code><code>"localhost"</code><code>;</code>
<code>$database_username = </code><code>"cacti"</code><code>;</code>
<code>$database_password = </code><code>"cactipass"</code><code>;</code>
<code>$database_port = </code><code>"3306"</code><code>;</code>
<code>$database_ssl = </code><code>false</code><code>;</code>
调整系统时区及时间
<code>[root@www ~]</code><code># yum -y install ntp</code>
<code>[root@www ~]</code><code># ntpdate ntpdate time.nist.gov ##同步时间</code>
<code>[root@www ~]</code><code># cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ##替换系统时区</code>
配置php.ini文件的时区为Asia/Shanghai
<code>[root@www ~]</code><code># vim /etc/php.ini </code>
<code>date</code><code>.timezone = </code><code>'Asia/Shanghai'</code>
添加抓图计划任务
<code>[root@www ~]</code><code># /usr/bin/php /var/www/html/cacti/poller.php</code>
<code>[root@www ~]</code><code># crontab -e</code>
<code>*</code><code>/5</code> <code>* * * * </code><code>/usr/bin/php</code> <code>/var/www/html/cacti/poller</code><code>.php</code>
五、Web界面安装和配置cacti
http://192.168.1.21/cacti
<a href="http://192.168.1.21/cacti" target="_blank"></a>
<a href="http://s4.51cto.com/wyfs02/M01/79/90/wKiom1aUq0TRxWOkAAE56zohYII386.jpg" target="_blank"></a>
New install
<a href="http://s5.51cto.com/wyfs02/M00/79/90/wKiom1aUq36imdirAACUNWmLo9o225.jpg" target="_blank"></a>
Finish
<a href="http://s4.51cto.com/wyfs02/M02/79/8E/wKioL1aUrCTjCkGrAAFZ3fjQkTk780.jpg" target="_blank"></a>
转到登录页面,默认登录名和密码都是admin,输入会提示修改密码,Save后显示cacti主页面
<a href="http://s1.51cto.com/wyfs02/M00/79/8E/wKioL1aUrS7xPPI9AAC6TvcNpsA864.jpg" target="_blank"></a>
点击graphs查看生成的图形数据
<a href="http://s1.51cto.com/wyfs02/M01/79/8E/wKioL1aUrx6BxJQYAAEpKw1V8uo713.jpg" target="_blank"></a>
本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1734183