cacti是什么?
1. cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。
2. Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、端口号、模板信息等变量。
3. snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。
cacti的工作流程可以用下图表示:
cacti的安装:
配置本地yum
[root@cacti ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-Server]
name=Red Hat Enterprise Linux Server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-RedHat-release
[root@cacti ~]# mkdir /mnt/cdrom
[root@cacti ~]# mount /dev/cdrom/mnt/cdrom/
mount: block device /dev/cdrom iswrite-protected, mounting read-only
[root@cacti ~]# yum install httpd php php-mysql php-snmp mysql-serverperl-DBD-MySQL php-pdo net-snmp net-snmp-libs net-snmp-utils net-snmp-develruby –y
[root@cacti ~]# service httpd start
[root@cacti ~]# chkconfig httpd on
[root@cacti ~]# service mysqld start
[root@cacti ~]# chkconfig mysqld on
[root@cacti ~]# mysqladmin -u root -ppassword '123'
[root@cacti ~]# mysql -u root –p
mysql> CREATE DATABASE cacti;
mysql> grant all privileges on cacti.* to cacti@localhostidentified by 'cacti';
mysql> grant all privileges on cacti.* to cacti@127.0.0.1identified by 'cacti';
mysql> grant all privileges on cacti.* tocacti@192.168.2.0 identified by 'cacti';
mysql> flush privileges;
mysql> quit
上传需要用的软件
软件资料下载地址
------------------------------------------分割线------------------------------------------
FTP地址:ftp://ftp1.linuxidc.com
用户名:www.6688.cc
密码:www.linuxidc.com
在 2013年LinuxIDC.com\10月\Cacti及其相关插件的安装
下载方法见 http://www.linuxidc.com/Linux/2013-10/91140.htm
------------------------------------------分割线------------------------------------------
cacti-0.8.7g.tar.gz cacti的主程序
cacti-plugin-0.8.7g-PA-v2.8.tar.gz 插件管理器
feition.tar.bz2 用于飞信报警的程序
monitor-latest.tgz 实现只管监测的插件
sendMsg.zip 发送MSN消息的应用
settings-latest.tgz 增强功能的插件,例如发送电子邮件
thold-latest.tgz 实现达到预值告警的插件
[root@cacti software]# yum localinstallrrdtool* --nogpgcheck –y
更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2013-10/92145p2.htm
推荐阅读:
CentOS 6下Cacti搭建文档 http://www.linuxidc.com/Linux/2013-06/86595.htm
RHEL5.9下Cacti监控部署详解 http://www.linuxidc.com/Linux/2013-06/85427.htm
CentOS 6.3 下Cacti 安装详解 http://www.linuxidc.com/Linux/2013-05/84279.htm
CentOS Linux下快速安装配置Cacti中文版 http://www.linuxidc.com/Linux/2013-03/81627.htm
Cacti 的详细介绍:请点这里 Cacti 的下载地址:请点这里
实现对apache的监控
[root@cacti software]# cd ApacheStats_0.8.2/
[root@cacti ApacheStats_0.8.2]#ll
total 116
-rw-r--r-- 1 root root 102879 Oct 27 18:51 cacti_host_template_webserver_-_apache.xml
-rw-r--r-- 1 root root 4108 Oct 27 18:51 ss_apache_stats.php
[root@cacti ApacheStats_0.8.2]#cp ss_apache_stats.php /var/www/html/cacti/scripts/
[root@cacti ApacheStats_0.8.2]#chown 1000:users /var/www/html/cacti/scripts/ss_apache_stats.php
cacti_host_template_webserver_-_apache.xml 为下面要导入的模版文件
通过控制台导入模版
修改apache的配置文件
[root@cacti ApacheStats_0.8.2]#cd
[root@cacti ~]# vim/etc/httpd/conf/httpd.conf
217 ExtendedStatus On /////打开这一行
903 #<Location /server-status>
904 # SetHandler server-status
905 # Order deny,allow
906 # Deny from all
907 # Allow from .example.com
908 #</Location>
909 <Location /server-status>
910 SetHandler server-status
911 Order deny,allow
912 Deny from all
913 Allow from all
914 </Location>
将apache重启
[root@cacti ~]# service httpd restart
在安装插件之前要先安装插件管理器
[root@cacti cacti]# cd /root/software/
[root@cacti software]# tar -zxvf cacti-plugin-0.8.7g-PA-v2.8.tar.gz
[root@cacti software]# cp -R cacti-plugin-arch/* /var/www/html/cacti/
[root@cacti software]# cd /var/www/html/cacti/
[root@cacti cacti]# mysql -u root -pcacti<pa.sql
[root@cacti cacti]# patch -p1 -N<cacti-plugin-0.8.7g-PA-v2.8.diff
[root@cacti cacti]# vim include/config.php
42 $url_path = "/cacti/"; /////修改这一行的路径
安装插件
[root@cacti cacti]# cd /root/software/
[root@cacti software]# tar -zxvf monitor-latest.tgz
[root@cacti software]# tar -zxvf settings-latest.tgz
[root@cacti software]# tar -zxvf thold-latest.tgz
[root@cacti software]# mv monitor-0.9/ /var/www/html/cacti/plugins/monitor
[root@cacti software]# mv settings-0.6/ /var/www/html/cacti/plugins/settings
[root@cacti software]# mv thold-0.41/ /var/www/html/cacti/plugins/thold
在控制台启用插件
配置支持发送msn消息
[root@cacti software]# unzip sendMsg.zip
[root@cacti software]# mv sendMsg/ var/www/html/
[root@cacti software]# vim /var/www/html/cacti/plugins/thold/thold_functions.php
添加下面这两行
560 exec("echo $subject>>/var/www/html/cacti/plugins/thold/alert.log");
561 exec("sh /var/www/html/cacti/plugins/thold/sendmessage.sh");
编写个sendmessage.sh脚本,在/var/www/html/cacti/plugins/thold/这个目录下(实现自动发送)
[root@cacti software]# vim /var/www/html/cacti/plugins/thold/sendmessage.sh
脚本内容
#!/bin/sh
echo `echo -n"date:"&&date +%Y-%m-%d-%H:%M` >>/var/www/html/sendMsg/msn.txt.1
cat /var/www/html/cacti/plugins/thold/alert.log>>/var/www/html/sendMsg/msn.txt.1
now=`date +%Y-%m-%d-%H:%M`
SA=(test)
msnaddr=(接收信息的帐号)
sendMsg()
{
num=0
while [ $num -lt 1 ];
do
wget ?post-data"sender=发送信息的帐号&password=密码&recipient=
if [ -f /var/www/html/sendMsg/index.php.1]; then
if cat /var/www/html/sendMsg/index.php.1|grep -i successfully >/dev/null 2>&1;then
num=1
elif cat /var/www/html/sendMsg/index.php.1|grep -i "The user appears to be offline" >/dev/null2>&1;then
num=1
echo "The user is offline."
exit 0
elif cat /var/www/html/sendMsg/index.php.1 |grep-i "Something went wrong trying to connect to the server">/dev/null 2>&1;then
num=1
echo "MSN server is online."
exit 0
else
num=0
fi
rm -f /var/www/html/sendMsg/index.php.1
else
num=0
fi
done
}
mv /var/www/html/sendMsg/msn.txt/var/www/html/sendMsg/bak/msn$now.txt -f 1>/dev/null 2>&1
mv /var/www/html/sendMsg/msn.txt.1/var/www/html/sendMsg/msn.txt -f 1>/dev/null 2>&1
rm /var/www/html/cacti/plugins/thold/alert.log -f 1>/dev/null 2>&1
for i in 0
do
if cat /var/www/html/sendMsg/msn.txt ; then
messages=`cat /var/www/html/sendMsg/msn.txt`
sendMsg "
else
continue
fi
done
配置支持飞信报警
[root@cacti software]# tar -jxvf feition.tar.bz2
[root@cacti software]# mkdir -pv /var/www/html/sendsms/linuxso
[root@cacti software]# cp linuxso_20101113/* /lib/
[root@cacti software]# mv linuxso_20101113/* /var/www/html/sendsms/linuxso/
[root@cacti software]# vim /var/www/html/cacti/plugins/thold/thold_functions.php
添加这两行
562 exec("echo $subject>>/var/www/html/cacti/plugins/thold/alert.log");
563 exec("/var/www/html/cacti/plugins/thold/sendsms.sh");
[root@cacti software]# vim /var/www/html/cacti/plugins/thold/sendsms.sh
#!/bin/sh
#send sms by fetion
#Write by pingsun2010@hotmail.com
if [ ! -e"/var/www/html/cacti/plugins/thold/alert.log" ];then
echo "Usage:alert.log does notexist"
exit
fi
if [ -n "`cat/var/www/html/cacti/plugins/thold/alert.log`" ]; then
admin="接收信息的帐号?
echo "sms $admin "`cat /var/www/html/cacti/plugins/thold/alert.log`>>/var/www/html/cacti/plugins/thold/sms.txt
echo "exit" >>/var/www/html/cacti/plugins/thold/sms.txt
else
echo "Usage:no alert"
exit
fi
if [ -n "`cat/var/www/html/cacti/plugins/thold/sms.txt`" ] ;then LD_LIBRARY_PATH=/var/www/html/sendsms/linuxso/var/www/html/sendsms/linuxso/fetion --mobile=发送信息的账户 --pwd=密码 --to=$admin --file-utf8=/var/www/html/cacti/plugins/thold/sms.txt
rm -f /var/www/html/cacti/plugins/thold/sms.txt 1>/dev/null 2>&1
rm -f /var/www/html/cacti/plugins/thold/alert.log 1>/dev/null 2>&1
else
echo "Usgae:no message to send"
exit
fi
[root@cacti thold]# chmod a+x send*
给新建的脚本添加可执行权限
vim /var/www/html/cacti/plugins/thold/alert.log
随便写点儿内容,当飞信程序执行的时候会自动删除里面的内容
可以新建alert.log以及sms.txt,其中在alert.log中添加一个内容。然后手工运行脚本进行测试,需要保证本机能正常接入互联网。
目前cacti的环境已经搭建完成,cacti的使用还需要好好学习……