2341rtw 发表于 2016-1-22 09:01:25

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

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、安装扩展源
# rpm -ivh http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm
2、安装Apache

# yum -y install httpd httpd-devel
3、安装MySQL
# yum -y install mysql mysql-server
4、安装PHP及相关软件
# yum install php php-mysql php-gd php-pear php-devel php-common php-cli php-mbstring php-mcrypt
5、启动Apache、MySQL

1
2
3
4
5
6
# chkconfig httpd on
# chkconfig mysqld on
# service httpd start
# service mysqld start

# mysqladmin -uroot password dbpasswd ;设置root用户密码




6、安装PHP-SNMP和NET-SNMP
# yum -y install php-snmp net-snmp net-snmp-utils net-snmp-libs
7、安装RRDTool
# yum -y install rrdtool

二、安装Cacti服务
1、下载cacti-0.8.8f.tar.gz
# wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz

2、解压到网站目录/var/www/html/下
# tar zxf cacti-0.8.8f.tar.gz
# mv cacti-0.8.8f /var/www/html/cacti
# chown -R apache.apache /var/www/html/


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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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数据库文件
# mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql

5、修改Cacti相关的MySQL数据库配置文件

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





1
2
3
4
5
6
7
8
/* 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端口

1
2
3
# iptables -A INPUT -p udp --dport 80 -j ACCEPT
# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# service iptables save





7、配置Cacti虚拟主机文件,创建/etc/httpd/conf.d/cacti.conf,允许192.168.1.0的网段访问

1
2
3
4
5
6
7
# 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'
1
2
3
4
# ntpdate time.nist.gov
# hwclock    ;写入BIOS
#添加时间自动同步计划任务
0 11 * * * /usr/sbin/ntpdate time.nist.gov;hwclock -w





1
2
# vim /etc/php.ini
date.timezone = 'Asia/Shanghai'




9、配置cacti轮询php脚本,添加cron计划任务,让它每五分钟执行一次以生成图像显示

1
*/5 * * * */usr/bin/php /var/www/html/cacti/poller.php





1
2
3
4
5
6
7
# /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、重启服务

1
2
3
4
# service httpd restart
# service mysqld restart
# service snmpd restart
# service crond restart





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

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


安装完成

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

# yum -y install libtool net-snmp-devel mysql-devel
3、编译安装Spine

1
2
3
4
5
6
7
8
9
10
# ./configure
# make
# make install
make: 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: Leaving directory `/root/cacti-spine-0.8.8f'





1
2
# ls /usr/local/spine/
binetc




4、配置spine.conf文件,指定cacti数据库、用户和密码
# cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
# vim /etc/spine.conf


5、执行Spine轮询脚本获取监测主机信息

1
2
3
4
# /usr/local/spine/bin/spine
SPINE: Using spine config file
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配置完成



页: [1]
查看完整版本: CentOS6.X上安装Cacti网络监控系统和Spine轮询