Cacti实时监控
Cacti是一种基于php,mysql,snmp,及rrdtool的网络流量监测图形分析工具。
cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用 rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。 Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。
Cacti是一个完整的网络图形解决方案,旨在利用权力的数据存储和绘图功能。 Cacti provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box.仙人掌提供了一个快速轮询,先进的图形模板,多种数据采集方法,框的功能,用户管理。 All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with hundreds of devices.所有这一切都被包裹在一个直观的,易于使用的界面,使中小型局域网的安装了数百台设备到复杂的网络意识。
系统环境:rhel6.0 x86_64 selinux and iptables off
server:192.168.0.2
软件下载:
yum install httpd mysql-server mysql php rrdtool php-mysql net-snmp php-snmp net-snmp-utils
net-snmp-libs automake libtool net-snmp-devel mysql-devel libart_lgpl-devel libpng-devel
freetype-devel cairo-devel pango-devel
/etc/init.d/snmpd start
####未配置文件之前执行如下命令,无任何输出
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
####红色部分未注释替换注释部分
vim /etc/snmp/snmpd.conf
....
#First,map the community name "public" into a "security name"
# sec.name source community
#com2sec notConfigUser default public
com2sec local localhost public
com2sec mynetwork 192.168.0.0/24 public
#Second,map the security name into a group name:
# groupName securityModel securityName
#group notConfigGroup v1 notConfigUser
#group notConfigGroup v2c notConfigUser
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 network
group MyROGroup v2c network
group MyROGroup usm network#Third,create a view for us to let the group have rights to:
#Make at least snmpwalk -v 1 localhost -c public system fast again.
# name incl/excl subtree mask(optional)
#view systemview included .1.3.6.1.2.1.1
#view systemview included .1.3.6.1.2.1.25.1.1
view all included .1 80#Finally,grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
#access notConfigGroup "" any noauth exact systenview none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
....
#System contact information
#It is also possible to set the sysContact and sysLocation system
#variable throuth the snmpd.conf file:
#syslocation Linux (edit /etc/snmp/snmpd.conf)
#syscontact Root (configure /etc/snmp/snmpd.local.conf)
syslocation Linux(RH3_UP2),Home Linux Router
syscontact yungho@yeah.net....
/etc/init.d/snmpd restart
####配置/etc/snmp/snmpd.conf完成后,执行如下命令,有下面输出:
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.127.0.0.1 = 1
ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.192.168.0.3 = 2
-------------------------------------------------------------------------------------------------------------
tar -zxf cacti-0.8.7g.tar.gz -C /var/www/html
cd /var/www/html
mv cacti-0.8.7g cacti
cd cacti
useradd cacti
chown cacti log/ rra/ -R
#####创建cacti数据库
cd /var/www/html/cacti
/etc/init.d/mysqld start
mysqladmin create cacti #创建cacti库
mysql cacti < cacti.sql #将数据导入创建的cacti数据库中 ####为指定用户访问数据库的用户授权
grant all on cacti.* to cacti@localhost identified by 'cacti'; #cacti用户以cacti密码可以访问cacti库中的所有表
flush privileges; #重载授权
quit;
####测试授权用户是否能够顺利登入数据库
mysql -ucacti -pcacti
####红色字体为修改内容
vim /var/www/html/cacti/include/config.php
....
$database_type='mysql'
$databsae_default='cacti'
$database_hostname='localhost'
$database_username='cacti'
$database_password='cacti'
$database_port="3306"....
####以cacti身份编辑crontab文件
crontab -e
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null
####访问WEB界面的用户名和密码均为admin
URL=
-----------------------------------------------------------------------------------------------------------
tar -zxf cacti-spine-0.8.7.tar.gz
cd cacti-spine-0.8.7g
aclocal
libtoolize --force
autoheader
autoconf
automake
./configure
make
make installcp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
vim /usr/local/spine/etc/spine.conf
....
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306
DB_PreG 0#### 进入页面
设置Settings-Paths-Spine Poller File Path 对应的空格写入路径 /usr/local/spine/bin/spine/ 并保存
进入页面Settings-Poller-Poller Type 对应的下拉列表选 spine 并保存
查看日志tail /var/www/html/cacti/log/cacti.log####注意红色部分的变化
11/16/2011 07:20:02 AM - SYSTEM STATS: Time:1.2592Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5
11/16/2011 07:25:03 AM - SYSTEM STATS: Time:1.2557 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5
11/16/2011 07:30:03 AM - SYSTEM STATS: Time:1.2602 Method:spine Processes:1 Threads:1 Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5
11/16/2011 07:35:02 AM - SYSTEM STATS: Time:1.2624 Method:spine Processes:1 Threads:1 Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5
------------------------------------------------------------------------------------------------------------
cacti插件扩展
tar -zxf cacti-plugin-0.8.7g-PA-v2.8.tar.gz
cd cacti-plugin-arch
cp cacti-plugin-0.8.7g-PA-v2.8.diff /var/www/html/cacti
cd /var/www/html/cacti
patch -p1 -N < cacti-plugin-0.8.7g-PA-v2.8.diff
vim include/config.php
....
$url_path="/cacti/"....
####切换到cacti-plugin-arch目录,导入数据库文件
mysql cacti < pa.sql
####进入页面
设置User Management--admin选中Plugin Management并保存
tar -zxf settings-0.5.tar.gz -C /var/www/html/cacti/plugins/
##进入页面Plugin Management 点击Actions下面的箭头激活
tar -zxf monitor-0.8.2.tar.gz -C /var/www/html/cacti/plugins/
##进入页面Plugin Management 点击Actions下面的箭头激活
##进入页面User Management-admin 选中 View Monitoring 并保存
tar -zxf thold-0..4.3.tar.gz -C /var/www/html/cacti/plugins/
##进入页面Plugin Management 先点击Action下面的蓝色箭头激活,在点击绿色箭头安装
若你在参考过程中发现了任何错误,
或你有什么建议,
欢迎mail到yungho@yeah.net
一起交流学习
阅读(2799) | 评论(0) | 转发(0) |