您的位置:首页 > 运维架构 > Apache

linux通过cacti监控apache通过飞信邮件进行报警

2013-10-30 19:45 555 查看
cactiCacti是通过snmpget来获取数据,使用RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数。它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构、host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,功能非常强大完善。界面友好Cacti架构

Cacti工作原理

一.安装前准备Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具,所有我们需要搭建lamp环境,这里我们采用yum安装(1)本地yum[root@localhost]#mount/dev/cdrom/mnt/cdrom/mount:blockdevice/dev/cdromiswrite-protected,mountingread-only[root@localhost]#vim/etc/yum.repos.d/rhel-debuginfo.repo[rhel-server]name=RedHatEnterpriseLinuxserverbaseurl=file:///mnt/cdrom/Serverenabled=1gpgcheck=1gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release二.lamp搭建[root@localhost~]#yuminstallhttpdphpphp-mysqlphp-snmpmysql-serverper-DBD-MySQLphp-pdonet-snmpnet-snmp-libsnet-snmp-utilsnet-snmp-develrubyruby-devel(1)设置lamp能够开机启动[root@localhost~]#servicehttpdstart[root@localhost~]#chkconfighttpdon[root@localhost~]#servicemysqldstart[root@localhost~]#chkconfigmysqldon(2)为mysql创建账号并授权给cacati[root@localhost~]#mysqladmin-uroot-ppassword'123'[root@localhost~]#mysql-uroot-pmysql>createdatabasecacti;授权给cacati并赋予密码为cactimysql>grantallprivilegesoncacti.*tocacti@localhostidentifiedby'cacti';mysql>grantallprivilegesoncacti.*tocacti@127.0.0.1identifiedby'cacti';mysql>flushprivileges;三.安装rrdtool文件[root@localhost~]#yumlocalinstallrrd*--nogpgcheck/rrdtool-1.4.4-1.el5.wrl.i386/rrdtool-perl-1.4.4-1.el5.wrl.i386/rrdtool-ruby-1.4.4-1.el5.wrl.i386(1)建立调度任务[root@localhostcacti]#crontab-e*/5****php/var/www/html/cacti/poller.php>/dev/null2>&1(2)编辑cacti的控制脚本[root@localhostcacti]#viminclude/config.php26$database_type="mysql";27$database_default="cacti";28$database_hostname="localhost";29$database_username="cacti";30$database_password="cacti";31$database_port="3306";[root@localhostcacti]#servicehttpdrestart(3)增加cacti账号密码[root@localhostcacti]#useraddcacti[root@localhostcacti]#passwdcacti[root@localhostcacti]#chown-Rcactilogrra(4)启动snmp对本主机进行监控[root@localhost~]#servicesnmpdstart[root@localhost~]#chkconfigsnmpdon(5)对本地apache配置[root@localhostcacti]#vim/etc/httpd/conf/httpd.conf查看是否有这样的模块176LoadModulestatus_modulemodules/mod_status.so216#217ExtendedStatusOn902#903<Location/server-status>904SetHandlerserver-status905Orderdeny,allow906Allowfromall907</Location>[root@localhostcacti]#servicehttpdrestart四.进入cactig管理界面(1)通过192.168.2.10/cactil/进入cacti

(2)指明目录,如果是yum安装这些目录,会自动添加上去.

(3)输入账号admin,密码admin

(4)全局配置,版本V2版本,采用snmp1).Create创建NewGraphs添加新图形(2).Management管理GraphManagement图形管理。可以在此删除、复制图像,Cacti会自动创建图像。不过如果我们有特殊的需要,比如将几张图上的数据合并在一张图像上的话也可以在此手工新建图像;GraphTrees图形树。在graphs界面里,图像或devices是树状结构显示的,可以在此设置树的结构;DataSources数据源。记要用来管理rrd文件的,一般无需修改,Cacti会自己创建rrd文件;Devices设备管理。这是我们最经常需要修改的地方,可以在此创建新的设备或修改其名称等信息。(3).CollectionMethods数据收集方法,一般我们无需对这两项进行修改。(非常重要在下面的内容中进行详解)DataQueries数据查询,DataInputMethods数据输入方法(4).Templates模板,这些模板可以导出、导入也可以自己编写,一般无需修改。GraphTemplates图形模板HostTemplates主机模板

(5)对本地主机监控,

(6)创建图形

(7)查看graphs查看本地监控



(8)对windows进行监控需要安装snmp服务

(9)启动该服务,并对该服务添加团体名,设置允许192.168.2.10对其监控

(10)cacti设置创建windows图形树

(11)创建表格,对windows进行监控端口161端口,版本version2

(12)添加windows监控服务

(13)把windows添加到图形树

树里面查看已有数据

查看rrd表,这时候发现增加几个表

(14)监控junpier防火墙

允许192.168.2.10,掩码255.255.255.255,掩码必须是四个255指明单个主机否则无法获得数据

cacti添加设备

创建图形树,由于没有junpier的图形树模板,我们需要对其创建或者网上下载相应的模板,这里我们可以利用现有的设备模板,复制更改,这里一定要把被监控设备的OID设备指明,否则我们将无法获得数据

(15)apache监控,首先我们需要导入apache的模板ss_apache_stats.php需要导入到/var/www/html/cacti目录cacti_host_template_webserver_-_apache.xmlapache模板





(16)增加插件管理器[root@localhost~]#tar-zxvfcacti-plugin-0.8.7g-PA-v2.8.tar.gz[root@localhostcacti-plugin-arch]#cp-r*/var/www/html/cacti/cp:是否覆盖“/var/www/html/cacti/LICENSE”?ycp:是否覆盖“/var/www/html/cacti/README”?Y导入数据库[root@localhostcacti]#mysql-uroot-pcacti<pa.sqlEnterpassword:[root@localhostcacti]#patch-p1-N<cacti-plugin-0.8.7g-PA-v2.8.diff[root@localhostcacti]#viminclude/config.php42$url_path="/cacti/";[root@localhostcacti]#servicehttpdrestart拆解域值[root@localhost~]#tar-zxvfthold-latest.tgz[root@localhost~]#tar-zxvfmonitor-latest.tgz[root@localhost~]#tar-zxvfsettings-latest.tgz[root@localhost~]#mvmonitor-0.9//var/www/html/cacti/plugins/[root@localhost~]#mvthold-0.41//var/www/html/cacti/plugins/[root@localhost~]#mvsettings-0.6//var/www/html/cacti/plugins/[root@localhostplugins]#mvmonitor-0.9/monitor[root@localhostplugins]#mvsettings-0.6/settings[root@localhostplugins]#mvthold-0.41/thold

增加插件





脚本(附件下载)[root@localhost~]#mvsendmessage.sh/var/www/html/cacti/plugins/thold/[root@localhost~]#mvsendsms.sh/var/www/html/cacti/plugins/thold/[root@localhostthold]#chmoda+xsendmessage.sh[root@localhostthold]#chmoda+xsendsms.sh邮件于cacti的结合[root@localhostthold]#vimthold_functions.php559thold_mail($alert_emails,'',$subject,$msg,$file_array);560exec("echo$subject>>/var/www/html/cacti/plugins/thold/alert.log");561exec("sh/var/www/html/cacti/plugins/thold/sendmessage.sh");

对windows进行监控,设置域值

设置域值,这里监控是进程数量





飞信控制[root@localhost~]#tar-jxvffeition.tar.bz2[root@localhost~]#cplinuxso_20101113/lib*/lib/标准路径下[root@localhostthold]#cd/var/www/html/cacti/plugins/thold/[root@localhost~]#mkdir/var/www/html/sendsms[root@localhost~]#mvlinuxso_20101113//var/www/html/sendsms/linuxso[root@localhost~]#[root@localhostthold]#vimthold_functions.php559thold_mail($alert_emails,'',$subject,$msg,$file_array);560exec("echo$subject>>/var/www/html/cacti/plugins/thold/alert.log");561exec("sh/var/www/html/cacti/plugins/thold/sendmessage.sh");562exec("echo$subject>>/var/www/html/cacti/plugins/thold/alert.log");563exec("sh/var/www/html/cacti/plugins/thold/sendsms.sh");

cacti实现飞信报警,邮件报警脚本,以及apache模板查看附件下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息