一、准备工作
环境:Centos 5.2 x86_32
所需软件:net-snmp、net-snmp-libs、net-snmp-utils、rrdtool、php-snmp、cacti-0.8.7d-cn-utf8.zip
注:此次cacti的安装和配置主要是配合nagios做监控,在配置好nagios的基础上做的cacti监控,nagios和cacti安装在同一部机器上,所以在配置nagios时mysql、apache以及一些相关插件已经安装了。
二、安装及配置
(1)安装snmp以及相关插件
yum install php-snmp net-snmp net-snmp-libs net-snmp-utils
(2)rrdtool的安装
# 在主监控机上安装rrdtool,rrdtool依赖的包过多,所以选择增加源,然后用yum安装
# 编辑CentOS-Base.repo文件,使其yum支持安装rrdtool插件
vi /etc/yum.repos.d/CentOS-Base.repo
# 在文件末尾增加以下部分
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1
# 以yum安装rrdtool
yum install rrdtool
(3)配置snmp
vi /etc/snmp/snmpd.conf
# 将下边这行
com2secnotConfigUser default public
# 改为
com2secnotConfigUser 127.0.0.1 public
# 将下边这行中的systemview
access notConfigGroup "" any noauth exact systemview none none
# 改为all
access notConfigGroup "" any noauth exact all none none
# 将下边这行的注释“#”号去掉
#view all included .1 80
# 重启snmpd服务
service snmpd restart
(4)安装cacti
# 把解压后的包移动到你apache相应的web目录
tar xvf cacti-0.8.7e.tar.gz
mv cacti-0.8.7e /usr/local/apache2/htdocs/cacti
(5)在数据库中建库、授权、导入数据库结构
# 注意导入cacti.sql时该文件的路径
mysql -u root -p
# 输入root的密码:
mysql> create database cacti;
mysql> grant all privileges on cacti.* to cacti@localhost identified by 'cactiuser' with grant option;
mysql> grant all privileges on cacti.* to cacti@127.0.0.1 identified by 'cactiuser' with grant option;
mysql> use cacti;
mysql> source /usr/local/apache2/htdocs/cacti/cacti.sql;
mysql> exit
# 配置cacti以连接数据库
useradd cactiuser
passwd cactiuser (pwd:cactipw)
chown –R cactiuser rra/ log/
vi include/config.php
$database_type = ''mysql'';
$database_default = ''cacti''; //需要连接的cacti数据库
$database_hostname = ''localhost''; //要连接的数据库所在服务器的主机名
$database_username = ''cactiuser''; //之前授权过登录cacti数据库的用户名
$database_password = ''cactipw''; //之前授权过登录cacti数据库的用户的密码
(6)浏览器下配置cacti
# 用浏览器打开 http://172.0.0.54/cacti ,会显示 cacti的安装指南,设置好就不会再出现了。
# 点击 “Next”
# 选择“New Install”,点击“Next”
# 指定 rrdtool、 php、 snmp 工具的 Binary 文件路径,确保所有的路径都是显示“ FOUND”,没有 “NOT FOUND”的,点击Finish 完成安装。
# Cacti 默认的用户名与密码是 admin,输入用户名与密码,点击 login
# 为了安全的原因,第一次登录成功后,cacti 会强制要求你更改一个新的 password ,输入新密码并确认密码,点击 save ,进入cacti 控制台界面:
# 点击 graphs ,查看cacti 监控本机的图表:
(7)增加入一个计划任务,使得 cacti 每五分钟生成一个监控图表。
crontab -e
#加入如下内容。注意poller.php的路径
*/5 * * * * /usr/local/php5/bin/php /usr/local/apache2/htdocs/cacti/poller.php > /dev/null 2>&1
# 确保 /usr/local/apache2/htdocs/cacti/rra/目录存在
# 如果暂时未看到图表,可以手工执行,生成图表
/usr/local/php5/bin/php /usr/local/apache2/htdocs/cacti/poller.php > /dev/null 2>&1
三、使用 Cacti 监控 Linux 主机
# 在被监控的linux主机上安装net-snmp
yum install net-snmp
# 配置snmp
vi /etc/snmp/snmpd.conf
# 更改以下部分
# 将下边这行中的default
com2secnotConfigUser default public
# 改为cacti服务器的IP地址
com2secnotConfigUser 172.0.0.54 public
# 将下边这行中的systemview
access notConfigGroup "" any noauth exact systemview none none
# 改为all
access notConfigGroup "" any noauth exact all none none
# 将下边这行的注释“#”号去掉
#view all included .1 80
# 重启snmp服务
service snmpd restart
四、使用cacti监控windows主机
监控windows主机,需要在windows主机上安装snmp服务,并配置snmp的安全选项,添加一个团体,权限为只读,团体名称为cacti浏览器页面上的snmp组的名称一样,只需要在cacti页面上添加监控设备就可以了。
监控磁盘io的话,需要在windows主机上安装informant-std服务,并且下载监控磁盘io的模板,下载后会得到10个文件,我们只需要两个文件,cacti_data_query_w32_-_disk_statistics.xml和snmp_informant_disk.xml,将
snmp_informant_disk.xml拷贝到cacti主机的/usr/local/cacti/resource/snmp_queries目录下,将cacti_data_query_w32_-_disk_statistics.xml添加到cacti管理页面的模板里,在监控设备上添加相应的监控选项就可以了。