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