Centos下cacti的安装

介绍

Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。Cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形。它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构、host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,功能非常强大完善。界面友好。软件 Cacti 的发展是基于让 RRDTool 使用者更方便使用该软件,除了基本的 Snmp 流量跟系统资讯监控外,Cacti 也可外挂 Scripts 及加上 Templates 来作出各式各样的监控图。

snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成,snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义

准备工作

http://www.cacti.net/download_cacti.php
http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
http://www.cacti.net/downloads/spine/cacti-spine-0.8.8b.tar.gz

安装rrdtool

getconf LONG_BIT
rpm -ivh http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
rpm -ivh http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

yum install rrdtool -y

 安装配置snmp

yum install net-snmp net-snmp-libs net-snmp-utils -y
chkconfig snmpd on

 snmp配置文件 /etc/snmp/snmpd.conf   

com2sec notConfigUser 101.199.100.150  sEtNcu3O9R7Dl29c
com2sec notConfigUser 220.181.150.98  sEtNcu3O9R7Dl29c
com2sec notConfigUser 180.153.229.230  sEtNcu3O9R7Dl29c
com2sec notConfigUser 220.181.150.125  sEtNcu3O9R7Dl29c
com2sec notConfigUser 103.28.11.237  sEtNcu3O9R7Dl29c
com2sec notConfigUser 103.28.10.244  sEtNcu3O9R7Dl29c
com2sec notConfigUser 103.28.10.245   sEtNcu3O9R7Dl29c
com2sec notConfigUser  127.0.0.1 sEtNcu3O9R7Dl29c 
com2sec notConfigUser 60.195.252.107  sEtNcu3O9R7Dl29c 
com2sec notConfigUser 60.195.252.110  sEtNcu3O9R7Dl29c 

group   notConfigGroup v2c           notConfigUser
access  notConfigGroup ""      any       noauth    exact  all  none  none 
view all    included  .1         80  
proc mountd
proc ntalkd 4
proc sendmail 10 1
disk / 10000
load 12 14 14

加入防火墙

/sbin/iptables -I INPUT -p udp -m udp -s 101.199.100.150  --dport 161 -jACCEPT
/sbin/iptables -I INPUT -p udp -m udp -s 220.181.150.98  --dport 161 -jACCEPT
/sbin/iptables -I INPUT -p udp -m udp -s 180.153.229.230  --dport 161 -jACCEPT
/sbin/iptables -I INPUT -p udp -m udp -s 220.181.150.125  --dport 161 -jACCEPT
/sbin/iptables -I INPUT -p udp -m udp -s 103.28.11.237  --dport 161 -jACCEPT
/sbin/iptables -I INPUT -p udp -m udp -s 103.28.10.244  --dport 161 -jACCEPT
/sbin/iptables -I INPUT -p udp -m udp -s 103.28.10.245   --dport 161 -jACCEPT

删除

iptables -D  INPUT  1

查看防火墙

iptables -L -n  --line-number  

 结果

Chain INPUT (policy DROP)
num  target     prot opt source               destination         
1    ACCEPT     udp  --  60.195.252.110       0.0.0.0/0           udp dpt:161 
2    ACCEPT     udp  --  60.195.252.107       0.0.0.0/0           udp dpt:161 
3    ACCEPT     udp  --  103.28.10.245        0.0.0.0/0           udp dpt:161 
4    ACCEPT     udp  --  103.28.10.244        0.0.0.0/0           udp dpt:161 
5    ACCEPT     udp  --  103.28.11.237        0.0.0.0/0           udp dpt:161 
6    ACCEPT     udp  --  220.181.150.125      0.0.0.0/0           udp dpt:161 
7    ACCEPT     udp  --  180.153.229.230      0.0.0.0/0           udp dpt:161 
8    ACCEPT     udp  --  220.181.150.98       0.0.0.0/0           udp dpt:161 
9    ACCEPT     udp  --  101.199.100.150      0.0.0.0/0           udp dpt:161 

 启动并测试

service snmpd start
snmpwalk -v 1 -c public localhost .1.3.6.1.2.1.1.1.0
snmpwalk -c public -v 2c 127.0.0.1 system 

 输出类一下信息则表明安装成功

SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.32-504.16.2.el6.i686 #1 SMP Wed Apr 22 04:04:03 UTC 2015 i686
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.32-504.16.2.el6.i686 #1 SMP Wed Apr 22 04:04:03 UTC 2015 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (874261) 2:25:42.61
SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain
SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (25) 0:00:00.25
SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDMIBObjects.3.1.1
SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance

配置nginx

location ~ ^/(status|ping)$
{   
    include fastcgi_params;
    fastcgi_pass unix:php_fpm_sock;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    allow 114.160.24.142;
    deny all;
}   

 location /ngx_status {
        stub_status on; 
        access_log  off;
        allow 60.195.252.106;
        allow 60.195.252.107;
        allow 60.195.252.110;
        allow 124.160.24.242;
        deny all;
}   

安装spine

net-snmp-devel
mysql
mysql-devel
openssl-devel

安装

yum -y install net-snmp-devel
cd /usr/local/src/
wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8b.tar.gz
tar -zxf  cacti-spine-0.8.8b.tar.gz
cd cacti-spine-0.8.8b
./configure
make && make install
vim /usr/local/spine/etc/spine.conf
//修改数据库连接信息

 测试

/usr/local/spine/bin/spine
ldd /usr/local/spine/bin/spine

 出现一下信息则表示成功

SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8a starting
SPINE: Time: 0.1190 s, Threads: 5, Hosts: 2 

 

linux-gate.so.1 =>  (0x00896000)
        libnetsnmp.so.20 => /usr/lib/libnetsnmp.so.20 (0x0094e000)
        libmysqlclient.so.18 => /usr/lib/libmysqlclient.so.18 (0x0037f000)
        libcrypto.so.10 => /usr/lib/libcrypto.so.10 (0x046a7000)
        libz.so.1 => /lib/libz.so.1 (0x001ac000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x001c0000)
        libm.so.6 => /lib/libm.so.6 (0x001db000)
        libc.so.6 => /lib/libc.so.6 (0x006b3000)
        libssl.so.10 => /usr/lib/libssl.so.10 (0x03bb1000)
        libdl.so.2 => /lib/libdl.so.2 (0x00205000)
        librt.so.1 => /lib/librt.so.1 (0x0020a000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x037f4000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00259000)
        /lib/ld-linux.so.2 (0x0035f000)
        libgssapi_krb5.so.2 => /lib/libgssapi_krb5.so.2 (0x039c2000)
        libkrb5.so.3 => /lib/libkrb5.so.3 (0x038e3000)
        libcom_err.so.2 => /lib/libcom_err.so.2 (0x00df4000)
        libk5crypto.so.3 => /lib/libk5crypto.so.3 (0x002fc000)
        libresolv.so.2 => /lib/libresolv.so.2 (0x00213000)
        libkrb5support.so.0 => /lib/libkrb5support.so.0 (0x002ee000)
        libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x0032f000)
        libselinux.so.1 => /lib/libselinux.so.1 (0x0022d000)

 安装cacti

cd /usr/loca/src
wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
tar xzf cacti-0.8.8b.tar.gz
mv cacti-0.8.8b /data/www/cacti
cd !$
mysql -urott -p  -e 'create database cacti'
mysql -uroot -p cacti < cacti.sql

 授权

GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';

 修改配置文件 include/config.php

 加入cron

echo "*/5 * * * * cactiuser php /data/www/cacti/poller.php > /dev/null 2>&1">>/etc/crontab

 访问后台

出现以上则说明成功

过5分钟过,不出意外的话则可以看到监控的图片了

posted @ 2015-08-20 01:08  踏雪无痕SS  阅读(490)  评论(0编辑  收藏  举报