阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Cacti及其相关插件的安装

139次阅读
没有评论

共计 10301 个字符,预计需要花费 26 分钟才能阅读完成。

cacti 是什么?

1. cacti是用 php 语言实现的一个软件,它的主要功能是用 snmp 服务获取数据,然后用 rrdtool 储存和更新数据,当用户需要查看数据的时候用 rrdtool 生成图表呈现给用户。因此,snmprrdtoolcacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。

 

2. Mysql配合 PHP 程序存储一些变量数据并对变量数据进行调用,如:主机名、主机 ipsnmp 团体名、端口号、模板信息等变量。

 

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

 

cacti 的工作流程可以用下图表示:

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 及其相关插件的安装

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 的下载地址:请点这里

安装 cacti 的主程序

[root@cacti software]# tar -zxvf cacti-0.8.7g.tar.gz -C /var/www/html/

[root@cacti software]# cd /var/www/html/

[root@cacti html]# mv cacti-0.8.7g/ cacti

 

[root@cacti html]# service snmpd start

[root@cacti html]# chkconfig snmpd on

[root@cacti html]# vim /etc/snmp/snmpd.conf

添加一行view systemview included .1.3.6.1.2.1.25.1.6 ///// 使能监控 tcp 流量

 

 

编辑计划任务

[root@cacti html]# crontab -e

*/5 * * * * php/var/www/html/cacti/poller.php >/dev/null 2>&1

 

导入数据库

[root@cacti html]# mysql -u root -p cacti</var/www/html/cacti/cacti.sql

输入 mysql 管理员口令

 

编辑 cacti 连接数据库的文件

[root@cacti html]# vim cacti/include/config.php

29 $database_username = “cacti“;

30 $database_password = “cacti“;

 

新建一个用户cacti,口令也为cacti

[root@cacti html]# useradd cacti

[root@cacti html]# passwd cacti

 

[root@cacti html]# cd cacti/

[root@cacti cacti]# chown -R cacti rra log

 

此时就可以通过页面登录 cacti 了,用户和口令都为admin

Cacti 及其相关插件的安装

Cacti 及其相关插件的安装

Cacti 及其相关插件的安装

Cacti 及其相关插件的安装

Cacti 及其相关插件的安装

202143661.jpg

cacti 是什么?

1. cacti是用 php 语言实现的一个软件,它的主要功能是用 snmp 服务获取数据,然后用 rrdtool 储存和更新数据,当用户需要查看数据的时候用 rrdtool 生成图表呈现给用户。因此,snmprrdtoolcacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。

 

2. Mysql配合 PHP 程序存储一些变量数据并对变量数据进行调用,如:主机名、主机 ipsnmp 团体名、端口号、模板信息等变量。

 

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

 

cacti 的工作流程可以用下图表示:

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 及其相关插件的安装

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 为下面要导入的模版文件

 

 

通过控制台导入模版

 

Cacti 及其相关插件的安装

Cacti 及其相关插件的安装

Cacti 及其相关插件的安装

Cacti 及其相关插件的安装

203705255.jpg

修改 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

Cacti 及其相关插件的安装

 

在安装插件之前要先安装插件管理器

[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

 

在控制台启用插件

Cacti 及其相关插件的安装

Cacti 及其相关插件的安装

203354534.jpg

配置支持发送 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=${1}&message=${2}”http://127.0.0.1/sendMsg/index.php -O /var/www/html/sendMsg/index.php.1>/dev/null 2>&1

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 “${msnaddr[$i]}””$messages”

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 的使用还需要好好学习……

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计10301字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中