Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。用来监控网络流量、cpu使用率、内存使用率、硬盘使用率等。可以直观的监控各种数据流量,可以安装扩展插件,同时支持短信邮件告警等功能。

Nagios是一个监视系统运行状态和网络信息的监视系统。Nagios能监视所指定的本地或远程主机以及服务,提供异常通知功能,同时还可以安装各种模块插件,自定义监控脚本等。

两者区别:Cacti偏重于网络流量,系统负载方面的监控。而 Nagios偏重于系统服务方面的监控,你可以在被监控的机器上写自己的程序(shell,c 或 perl都可以) 。Nagios则通过这些脚本来对服务进行监控。Nagios可以和短信发送机配合用来监控规模较大的网站。


安装扩展yum源

[root@www~]#rpm-ivhhttp://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpmRetrievinghttp://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpmwarning:/var/tmp/rpm-tmp.1jSHmn:HeaderV3RSA/SHA256Signature,keyID0608b895:NOKEYPreparing...###########################################[100%]1:epel-release###########################################[100%][root@www~]#ls/etc/yum.repos.d/epel*/etc/yum.repos.d/epel.repo/etc/yum.repos.d/epel-testing.repo

##########CACTI#########


一、安装LAMP环境

[root@www~]#yum-yinstallhttpdphpphp-mysqlmysqlmysql-servermysql-develphp-gdlibjpeglibjpeg-devellibpnglibpng-devel


二、安装net-snmp、php-snmp、net-snmp-utils

[root@www~]#yum-yinstallnet-snmpnet-snmp-utilsnet-snmp-libsphp-snmp


三、安装rrdtool图形整合工具

[root@www~]#yum-yinstallrrdtool[root@www~]#rrdtoolRRDtool1.3.8Copyright1997-2009byTobiasOetiker<tobi@oetiker.ch>CompiledApr3201413:07:03Usage:rrdtool[options]commandcommand_optionsValidcommands:create,update,updatev,graph,graphv,dump,restore,last,lastupdate,first,info,fetch,tune,resize,xportRRDtoolisdistributedundertheTermsoftheGNUGeneralPublicLicenseVersion2.(www.gnu.org/copyleft/gpl.html)FormoreinformationreadtheRRDmanpages

四、安装cacti主程序

下载cacti-0.8.8f.tar.gz

[root@www ~]# wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz

安装cacti,解压放到网站目录下

[root@www ~]# tar zxf cacti-0.8.8f.tar.gz

[root@www ~]# mv cacti-0.8.8f /var/www/html/cacti/

[root@www ~]# chown -R root. /var/www/html/cacti/

初始化数据库

[root@www ~]# /etc/init.d/mysqld start

[root@www~]#mysql_secure_installationEntercurrentpasswordforroot(enterfornone):Setrootpassword?[Y/n]yRemoveanonymoususers?[Y/n]yDisallowrootloginremotely?[Y/n]yRemovetestdatabaseandaccesstoit?[Y/n]yReloadprivilegetablesnow?[Y/n]y

创建cacti数据库

[root@www~]#mysql-uroot-p-e"createdatabasecacti"

授权cacti数据库用户

[root@www~]#mysql-uroot-p-e"grantalloncacti.*to'cacti'@'localhost'identifiedby'cactipass';"[root@www~]#mysql-uroot-p-e"flushprivileges;"

导入数据库文件

[root@www~]#mysql-uroot-pcacti</var/www/html/cacti/cacti.sql

修改cacti的配置文件config.php

[root@www~]#vim/var/www/html/cacti/include/config.php$database_type="mysql";$database_default="cacti";$database_hostname="localhost";$database_username="cacti";$database_password="cactipass";$database_port="3306";$database_ssl=false;

调整系统时区及时间

[root@www~]#yum-yinstallntp[root@www~]#ntpdatentpdatetime.nist.gov##同步时间[root@www~]#cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime##替换系统时区

配置php.ini文件的时区为Asia/Shanghai

[root@www~]#vim/etc/php.inidate.timezone='Asia/Shanghai'

添加抓图计划任务

[root@www~]#/usr/bin/php/var/www/html/cacti/poller.php[root@www~]#crontab-e*/5****/usr/bin/php/var/www/html/cacti/poller.php


五、Web界面安装和配置cacti

http://192.168.1.21/cacti

New install

Finish

转到登录页面,默认登录名和密码都是admin,输入会提示修改密码,Save后显示cacti主页面

点击graphs查看生成的图形数据


六、安装cacti优化轮询器spine

下载cacti-spine,版本对应cacti的版本

[root@www ~]# wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8f.tar.gz

[root@www ~]# yum -y install gcc

[root@www ~]# tar zxf cacti-spine-0.8.8f.tar.gz

[root@www ~]# cd cacti-spine-0.8.8f

编译安装cacti-spine

[root@wwwcacti-spine-0.8.8f]#./configure[root@wwwcacti-spine-0.8.8f]#makegcc-DHAVE_CONFIG_H-I.-I./config-I/usr/include/mysql-g-O2-MTsql.o-MD-MP-MF.deps/sql.Tpo-c-osql.osql.cInfileincludedfromsql.c:34:common.h:133:38:error:net-snmp/net-snmp-config.h:Nosuchfileordirectorycommon.h:134:32:error:net-snmp/utilities.h:Nosuchfileordirectorycommon.h:135:40:error:net-snmp/net-snmp-includes.h:Nosuchfileordirectorycommon.h:136:33:error:net-snmp/config_api.h:Nosuchfileordirectorycommon.h:137:30:error:net-snmp/mib_api.h:NosuchfileordirectoryInfileincludedfromspine.h:505,fromsql.c:35:snmp.h:41:error:expected‘;’,‘,’or‘)’before‘*’tokenmake:***[sql.o]Error1

报错提示:需安装net-snmp-devel解决依赖

[root@wwwcacti-spine-0.8.8f]#yum-yinstallnet-snmp-devel[root@wwwcacti-spine-0.8.8f]#yuminstalllibtool

[root@wwwcacti-spine-0.8.8f]#make[root@wwwcacti-spine-0.8.8f]#makeinstallmake[1]:Enteringdirectory`/root/cacti-spine-0.8.8f'/bin/mkdir-p'/usr/local/spine/bin'/bin/sh./libtool--mode=install/usr/bin/install-cspine'/usr/local/spine/bin'libtool:install:/usr/bin/install-cspine/usr/local/spine/bin/spine/bin/mkdir-p'/usr/local/spine/etc'/usr/bin/install-c-m644spine.conf.dist'/usr/local/spine/etc'make[1]:Leavingdirectory`/root/cacti-spine-0.8.8f'Youhavenewmailin/var/spool/mail/root[root@wwwcacti-spine-0.8.8f]#ls/usr/local/spine/binetc

拷贝spine配置文件并修改相应配置

[root@www~]#cp/usr/local/spine/etc/spine.conf.dist/etc/spine.conf[root@www~]#vim/etc/spine.confDB_HostlocalhostDB_DatabasecactiDB_UsercactiDB_PasscactipassDB_Port3306

启动spine

[root@www~]#/usr/local/spine/bin/spineSPINE:Usingspineconfigfile[/etc/spine.conf]SPINE:Version0.8.8fstartingSPINE:Time:0.1549s,Threads:5,Hosts:2

cacti页面下设置spine的路径,完成配置

【console--->Settings--->Paths--->Spine Poller File Path--->/usr/local/spine/bin/spine】


选择spine轮询方式

【Poller--->Poller Type--->spine】


七、Cacti添加监控客户机

安装yum源

[root@sh ~]# rpm -ivh http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm

安装net-snmp

[root@sh ~]# yum -y install net-snmpnet-snmp-develnet-snmp-utils

修改snmpd.conf配置文件

[root@sh~]#vim/etc/snmp/snmpd.conf55viewsystemviewincluded.1.3.6.1.2.1162#syslocationUnknown(edit/etc/snmp/snmpd.conf)163#syscontactRoot<root@localhost>(configure/etc/snmp/snmp.local.conf)164syslocation192.168.1.251#本机IP165syscontactRootroot@huangmingming.cn#接收邮件的邮箱

更改系统时间

[root@sh~]#ntpdatentpdatetime.nist.gov[root@sh~]#cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime

开启snmpd

[root@sh~]#/etc/init.d/snmpdstart


cacti服务端web设置,添加主机(Devices-->Add-->Description-->Hostname-->Host Template-->Number of Collection Threads-->SNMP Version-->Create---*Create Graphs for this Host-->选择要监控的模块)

将添加的主机加入到Graph Trees中

[root@www~]#/usr/local/spine/bin/spineSPINE:Usingspineconfigfile[/etc/spine.conf]SPINE:Version0.8.8fstartingSPINE:Time:0.1185s,Threads:1,Hosts:3


##########NAGIOS#########


一、下载软件包

1、下载nagios核心源码包

wget http://sourceforge.net/projects/nagios/files/latest/download

2、下载nagios插件nagios-plugins

wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

3、下载客户端软件nrpe

wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

http://sourceforge.net/projects/nagios-snmp/files/latest/download


二、添加nagios用户和nagcmd组

把nagios和apache添加到nagcmd组里

[root@www ~]# useradd -s /sbin/nologinnagios

[root@www ~]# groupadd nagcmd

[root@www ~]# usermod -G nagcmd nagios

[root@www ~]# usermod -G nagcmd apache

[root@www ~]# id apache

uid=48(apache) gid=48(apache) groups=48(apache),502(nagcmd)

[root@www ~]# id nagios

uid=501(nagios) gid=501(nagios) groups=501(nagios),502(nagcmd)


[root@www ~]# mkdir /usr/local/nagios

[root@www ~]# chown -R nagios.nagios /usr/local/nagios



三、安装nagios-4.1.1.tar.gz

[root@www ~]# tar zxf nagios-4.1.1.tar.gz

[root@www ~]# cd nagios-4.1.1

编译

[root@wwwnagios-4.1.1]#./configure--prefix=/usr/local/nagios--sysconfdir=/etc/nagios--with-command-group=nagcmd......GeneralOptions:-------------------------Nagiosexecutable:nagiosNagiosuser/group:nagios,nagiosCommanduser/group:nagios,nagcmdEventBroker:yesInstall${prefix}:/usr/local/nagiosInstall${includedir}:/usr/local/nagios/include/nagiosLockfile:${prefix}/var/nagios.lockCheckresultdirectory:${prefix}/var/spool/checkresultsInitdirectory:/etc/rc.d/init.dApacheconf.ddirectory:/etc/httpd/conf.dMailprogram:/bin/mailHostOS:linux-gnuIOBrokerMethod:epollWebInterfaceOptions:------------------------HTMLURL:http://localhost/nagios/CGIURL:http://localhost/nagios/cgi-bin/Traceroute(usedbyWAP):



Review the options above for accuracy. If they look okay,

type 'make all' to compile the main program and CGIs.


安装

[root@www nagios-4.1.1]# make all


*** Compile finished ***


If the main program and CGIs compiled without any errors, you

can continue with installing Nagios as follows (type 'make'

without any arguments for a list of all possible options):


make install

- This installs the main program, CGIs, and HTML files


make install-init

- This installs the init script in /etc/rc.d/init.d


make install-commandmode

- This installs and configures permissions on the

directory for holding the external command file


make install-config

- This installs *SAMPLE* config files in /etc/nagios

You'll have to modify these sample files before you can

use Nagios. Read the HTML documentation for more info

on doing this. Pay particular attention to the docs on

object configuration files, as they determine what/how

things get monitored!


make install-webconf

- This installs the Apache config file for the Nagios

web interface


make install-exfoliation

- This installs the Exfoliation theme for the Nagios

web interface


make install-classicui

- This installs the classic theme for the Nagios

web interface



*** Support Notes *******************************************


[root@www nagios-4.1.1]# make install

[root@www nagios-4.1.1]# make install-init

[root@www nagios-4.1.1]# make install-commandmode

[root@www nagios-4.1.1]# make install-config


[root@www nagios-4.1.1]# ls /usr/local/nagios/

bin libexec sbin share var

[root@www nagios-4.1.1]# ls /etc/nagios/

cgi.cfg nagios.cfg objects resource.cfg


[root@wwwnagios-4.1.1]#/usr/local/nagios/bin/nagios-v/etc/nagios/nagios.cfgNagiosCore4.1.1Copyright(c)2009-presentNagiosCoreDevelopmentTeamandCommunityContributorsCopyright(c)1999-2009EthanGalstadLastModified:08-19-2015License:GPLWebsite:https://www.nagios.orgReadingconfigurationdata...Readmainconfigfileokay...Readobjectconfigfilesokay...Runningpre-flightcheckonconfigurationdata...Checkingobjects...Checked8services.Checked1hosts.Checked1hostgroups.Checked0servicegroups.Checked1contacts.Checked1contactgroups.Checked24commands.Checked5timeperiods.Checked0hostescalations.Checked0serviceescalations.Checkingforcircularpaths...Checked1hostsChecked0servicedependenciesChecked0hostdependenciesChecked5timeperiodsCheckingglobaleventhandlers...Checkingobsessivecompulsiveprocessorcommands...Checkingmiscsettings...TotalWarnings:0TotalErrors:0Thingslookokay-Noseriousproblemsweredetectedduringthepre-flightcheck


[root@www ~]# chkconfig --add nagios

[root@www ~]# chkconfig nagios on



四、安装插件nagios-plugins-2.1.1.tar.gz

编译安装

[root@www ~]# tar zxf nagios-plugins-2.1.1.tar.gz

[root@www ~]# cd nagios-plugins-2.1.1

[root@www nagios-plugins-2.1.1]# ./configure --prefix=/usr/local/nagios

[root@www nagios-plugins-2.1.1]# make && make install

[root@www nagios-plugins-2.1.1]# ls /usr/local/nagios/

bin include libexec sbin share var


五、安装nrpe-2.15.tar.gz

[root@www ~]# tar zxf nrpe-2.15.tar.gz

[root@www ~]# cd nrpe-2.15

[root@www nrpe-2.15]# ./configure

[root@www nrpe-2.15]# make all

[root@www nrpe-2.15]# cd src/

[root@www src]# make install

[root@www src]# make install-pligin


六、Apache配置

设置nagios验证用户和密码

[root@www~]#htpasswd-c/etc/nagios/passwdnagiosadminNewpassword:Re-typenewpassword:Addingpasswordforusernagiosadmin

http.conf配置

[root@www~]#vim/etc/httpd/conf/httpd.conf242Userapache243Groupapache402DirectoryIndexindex.htmlindex.html.varindex.php781AddTypeapplication/x-httpd-php.php.phtml在最后增加以下内容:#settingfornagiosScriptAlias/nagios/cgi-bin"/usr/local/nagios/sbin"<Directory"/usr/local/nagios/sbin">AuthTypeBasicOptionsExecCGIAllowOverrideNoneOrderallow,denyAllowfromallAuthName"NagiosAccess"AuthUserFile/etc/nagios/passwdRequirevalid-user</Directory>Alias/nagios"/usr/local/nagios/share"<Directory"/usr/local/nagios/share">AuthTypeBasicOptionsNoneAllowOverrideNoneOrderallow,denyAllowfromallAuthName"NagiosAccess"AuthUserFile/etc/nagios/passwdRequirevalid-user</Directory>

[root@www~]#/etc/init.d/httpdrestartStoppinghttpd:[OK]Startinghttpd:[OK]


网页登录


Nagios4.1.1版本主页中间显示不了www.youtube.com页面,可是为了追求美观,干脆把它替换掉,找到URL的位置把它替换为全球实时展示******网站,观赏全球******走向O(∩_∩)O哈哈~

[root@www share]# grep 'www.youtube.com' main.php

[root@wwwshare]#vim/usr/local/nagios/share/main.php('<iframewidth="100%"height="100%"src="//www.youtube.com/embed/videoseries?list=PLN-ryIrpC_mCUW1DFwZpxpAk00i60lSkE&iv_load_policy=3&rel=0"frameborder="0"allowfullscreen></iframe>')替换url:('<iframewidth="100%"height="100%"src="//map.norsecorp.com"frameborder="0"allowfullscreen></iframe>')

如图