cacti速成
一、环境(RHEL5)服务器:192.168.152.132(LAMP+rrdtool+cacti)
客户端:192.168.152.128(snmp)
二、安装LAMP
首先做服务器端,Cacti实在LAMP环境基础上的我们要做个LAMP,源码编译太慢的一个mysql就要小半天,所以我们用yum安装
# yum -y install httpd httpd-manual mysql mysql-server php php-mysql php-common php-pdo php-gd
装好后开启服务
#service httpd start
# service mysqld start
#chkconfig httpd on
#chkconfig mysqld on
下满测试下
# vim /var/www/html/index.php //我们看看http和php怎么样
http://blog.运维网.com/attachment/201112/001515691.png
发现有这样的页面说明我们的php就OK了,下面测试下mysql
# cat /var/www/html/index.php
http://blog.运维网.com/attachment/201112/001539100.png
成功!!
目前为止只是个基本条件满足了,真正的才要开始呢。
三、安装Cacti
1)首先要有snmp服务
# yum -y install net-snmp*
#service snmpd start
2)之后就是绘图的工具rrdtool,这个就要编译安装了,rrdtool安装需要 cairo、libxml2、pango库文件支持,所以我们先使用 yum安装这几个库文件
#yum -y install cairo-devel libxml2-devel pango pango-devel
#tar zxvf rrdtool-1.4.4.tar.gz
#cd rrdtool-1.4.4
#./configure --prefix=/usr/local/rrdtool
#make && make install
#ln -s /usr/local/rrdtool/bin/* /usr/local/bin/
# rrdtool //我们输入rrdtool有下面信息rrdtool就安装好了
RRDtool 1.4.4 Copyright 1997-2010 by Tobias Oetiker
Compiled Dec 21 2011 23:36:52
Usage: rrdtool command command_options
Valid commands: create, update, updatev, graph, graphv, dump, restore,
last, lastupdate, first, info, fetch, tune,
resize, xport, flushcached
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
3)Cacti安装
#useradd cacti
#tar -zxvf cacti-0.8.7i.tar.gz -C /var/www/html/
# mysqladmin -u root -p password
Enter password: 123456 //给mysql加上密码123456
mysqladmin: Too few arguments to change password
# mysql -u root -p123456 //输入密码登陆
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
在mysql里我们还有些配置
mysql> create database cacti; //创建 cacti数据库
mysql> insert into mysql.user (host,user,password) values ('localhost','cacti',password('cacti123'));
//建立用户 cacti,密码 cacti123
mysql> flush privileges; //重载MySQL授权表
mysql> grant all on cacti.* to cacti@'localhost' identified by 'cacti123'; //把数据库 cacti授权
于用户 cacti
下面我们导入cacti的数据库
#cd /var/www/html/cacti/
#mysql -ucacti -pcacti123 cacti < cacti.sql
#chown -R cacti:cacti rra/ log/ //这里我们要给权限,要不不出图
# vim /var/www/html/cacti/include/config.php //在修改下配置文件
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti123";
$database_port = "3306";
$database_ssl = false;
好了,我们在浏览器上输入服务器IP
http://blog.运维网.com/attachment/201112/001616925.png
next
http://blog.运维网.com/attachment/201112/001657144.png
finish
http://blog.运维网.com/attachment/201112/001721131.png
初始用户名密码都是admin
http://blog.运维网.com/attachment/201112/001749367.png
这里要我们改下密码
http://blog.运维网.com/attachment/201112/001823348.png
下面开始客户端的配置
# rpm -ivh lm_sensors-2.10.7-4.el5.i386.rpm net-snmp-5.3.2.2-7.el5.i386.rpm
安装snmp服务
配置如下:(这里我省略掉了#行和空行)
# vim snmpd.conf
com2sec notConfigUser default public
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
access notConfigGroup "" any noauth exact mib2 none none
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root(configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
# service snmpd restart
到此就差不多了,我们可以做些检测在服务器上:
snmpwalk -v 2c -c public ServerIP if //用来测试被控对象(serverIP)是否开启了SNMP服务
# snmpwalk -v 2c -c public 192.168.152.128 if
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifIndex.3 = INTEGER: 3
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifDescr.3 = STRING: sit0
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
……
snmpwalk -v 2c ServerIP -c public .1.3.6.1.4.1.2021.10.1.3 //查看被控端是否有CPU负载的数据返回
设置 cacti数据采集轮询时间(这个是一定要加的,要不没图)
#crontab –e ,加入如下内容,让 cacti每五分钟采集一次数据
*/5 * * * * env LANG=C /usr/bin/php /var/www/html/cacti/poller.php
# service crond restart
# chkconfig crond on
OK了下面我们加图:
http://blog.运维网.com/attachment/201112/001853177.png
这里有个问题发现rrd目录下面还是root的
我们改下
# ll /var/www/html/cacti/rra
总计 100
-rw-r--r-- 1 root root 94668 12-22 00:09 192_168_152_128_traffic_in_9.rrd
#chown -R cacti:cacti rra
ll rra
总计 100
-rw-r--r-- 1 cacti cacti 94668 12-22 00:09 192_168_152_128_traffic_in_9.rrd
我们看到已经有128 客户端的数据了
出图好慢滴,不过总算出来了,到此就OK了。
http://blog.运维网.com/attachment/201112/002614804.png
页:
[1]