您的位置:首页 > 理论基础 > 计算机网络

CentOS6.X上安装Cacti网络监控系统和Spine轮询

2016-01-21 18:00 609 查看
Cacti工具是一套开源的基于Web的网络监控和系统监控的图形解决方案。Cacti通过SNMP服务获取数据,并使用RRDtool绘制图形,提供非常直观的数据和用户管理功能。Cacti需要Web、MySQL和PHP的支持。Cacti一般用于监控网络流量、CPU负载、磁盘空间等。



Cacti官网:http://www.cacti.net/

安装Cacti需要安装的软件包:Apache、MySQL、PHP、RRTool、PHP-SNMP、NET-SNMP

一、安装Cacti需要安装的软件包

1、安装扩展源
[root@sh ~]# rpm -ivh http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm 2、安装Apache

[root@sh ~]# yum -y install httpd httpd-devel
3、安装MySQL
[root@sh ~]# yum -y install mysql mysql-server
4、安装PHP及相关软件
[root@sh ~]# yum install php php-mysql php-gd php-pear php-devel php-common php-cli php-mbstring php-mcrypt
5、启动Apache、MySQL
[root@sh ~]# chkconfig httpd on
[root@sh ~]# chkconfig mysqld on
[root@sh ~]# service httpd start
[root@sh ~]# service mysqld start

[root@sh ~]# mysqladmin -uroot password dbpasswd ;设置root用户密码
6、安装PHP-SNMP和NET-SNMP
[root@sh ~]# yum -y install php-snmp net-snmp net-snmp-utils net-snmp-libs
7、安装RRDTool
[root@sh ~]# yum -y install rrdtool



二、安装Cacti服务
1、下载cacti-0.8.8f.tar.gz
[root@sh ~]# wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz
2、解压到网站目录/var/www/html/下
[root@sh ~]# tar zxf cacti-0.8.8f.tar.gz
[root@sh ~]# mv cacti-0.8.8f /var/www/html/cacti
[root@sh ~]# chown -R apache.apache /var/www/html/

3、创建Cacti数据库、用户和密码

[root@sh ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
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> create database cacti;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON cacti.* TO 'cacti'@'localhost' IDENTIFIED BY 'cactipass';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
mysql> quit
Bye
4、导入Cacti数据库文件
[root@sh ~]# mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql

5、修改Cacti相关的MySQL数据库配置文件
[root@sh ~]# vim /var/www/html/cacti/include/config.php
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cactipass";
$database_port = "3306";
$database_ssl = false;


6、添加防火墙规则允许外部访问80端口
[root@sh ~]# iptables -A INPUT -p udp --dport 80 -j ACCEPT
[root@sh ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
[root@sh ~]# service iptables save


7、配置Cacti虚拟主机文件,创建/etc/httpd/conf.d/cacti.conf,允许192.168.1.0的网段访问
[root@sh ~]# vim /etc/httpd/conf.d/cacti.conf
Alias /cacti    /var/www/html/cacti
<Directory /var/www/html/cacti/>
Order Deny,Allow
Deny from all
Allow from 192.168.1.0/24
</Directory>


8、调整系统时间,并且修改php.ini对应的时区为'Asia/Shanghai'
[root@sh ~]# ntpdate time.nist.gov
[root@sh ~]# hwclock    ;写入BIOS
#添加时间自动同步计划任务
0 11 * * * /usr/sbin/ntpdate time.nist.gov;hwclock -w
[root@sh ~]# vim /etc/php.ini
date.timezone = 'Asia/Shanghai'
9、配置cacti轮询php脚本,添加cron计划任务,让它每五分钟执行一次以生成图像显示
*/5 * * * *  /usr/bin/php /var/www/html/cacti/poller.php
[root@sh ~]# /usr/bin/php /var/www/html/cacti/poller.php
OK u:0.00 s:0.01 r:0.08
OK u:0.00 s:0.01 r:0.10
OK u:0.00 s:0.01 r:0.11
OK u:0.00 s:0.01 r:0.13
OK u:0.00 s:0.01 r:0.19
01/21/2016 03:15:01 PM - SYSTEM STATS: Time:0.3285 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5


10、重启服务
[root@sh ~]# service httpd restart
[root@sh ~]# service mysqld restart
[root@sh ~]# service snmpd restart
[root@sh ~]# service crond restart


11、浏览器登录http://IP/cacti/install/完成安装向导



Cacti默认登录用户和密码都是admin,根据提示修改,进入Cacti的Web界面




安装完成

三、安装Cacti加速轮询器Spine
1、下载spine-0.8.8f,版本对应cacti的版本
[root@sh ~]# wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8f.tar.gz 2、安装Spine依赖的包

[root@sh ~]# yum -y install libtool net-snmp-devel mysql-devel
3、编译安装Spine
[root@sh cacti-spine-0.8.8f]# ./configure
[root@sh cacti-spine-0.8.8f]# make
[root@sh cacti-spine-0.8.8f]# make install
make[1]: Entering directory `/root/cacti-spine-0.8.8f'
/bin/mkdir -p '/usr/local/spine/bin'
/bin/sh ./libtool   --mode=install /usr/bin/install -c spine '/usr/local/spine/bin'
libtool: install: /usr/bin/install -c spine /usr/local/spine/bin/spine
/bin/mkdir -p '/usr/local/spine/etc'
/usr/bin/install -c -m 644 spine.conf.dist '/usr/local/spine/etc'
make[1]: Leaving directory `/root/cacti-spine-0.8.8f'
[root@sh cacti-spine-0.8.8f]# ls /usr/local/spine/
bin  etc
4、配置spine.conf文件,指定cacti数据库、用户和密码
[root@sh ~]# cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
[root@sh ~]# vim /etc/spine.conf




5、执行Spine轮询脚本获取监测主机信息
[root@sh ~]# /usr/local/spine/bin/spine
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8f starting
SPINE: Time: 0.2636 s, Threads: 5, Hosts: 2


6、在Cacti页面选择Spine为默认轮询方式

console--->Settings--->Paths--->Spine Poller File Path--->/usr/local/spine/bin/spine--->save



Poller--->Poller Type--->spine--->save



Cacti配置完成
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  网络 Cacti 监控系统