Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。用来监控网络流量、cpu使用率、内存使用率、硬盘使用率等。可以直观的监控各种数据流量,可以安装扩展插件,同时支持短信邮件告警等功能。
成都创新互联公司:2013年至今为各行业开拓出企业自己的“网站建设”服务,为近千家公司企业提供了专业的网站设计、网站建设、网页设计和网站推广服务, 按需网站制作由设计师亲自精心设计,设计的效果完全按照客户的要求,并适当的提出合理的建议,拥有的视觉效果,策划师分析客户的同行竞争对手,根据客户的实际情况给出合理的网站构架,制作客户同行业具有领先地位的。
Nagios是一个监视系统运行状态和网络信息的监视系统。Nagios能监视所指定的本地或远程主机以及服务,提供异常通知功能,同时还可以安装各种模块插件,自定义监控脚本等。
两者区别:Cacti偏重于网络流量,系统负载方面的监控。而 Nagios偏重于系统服务方面的监控,你可以在被监控的机器上写自己的程序(shell,c 或 perl都可以) 。Nagios则通过这些脚本来对服务进行监控。Nagios可以和短信发送机配合用来监控规模较大的网站。
安装扩展yum源
[root@www ~]# rpm -ivh http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm Retrieving http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm warning: /var/tmp/rpm-tmp.1jSHmn: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [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 -y install httpd php php-mysql mysql mysql-server mysql-devel php-gd libjpeg libjpeg-devel libpng libpng-devel
二、安装net-snmp、php-snmp、net-snmp-utils
[root@www ~]# yum -y install net-snmp net-snmp-utils net-snmp-libs php-snmp
三、安装rrdtool图形整合工具
[root@www ~]# yum -y install rrdtool [root@www ~]# rrdtool RRDtool 1.3.8 Copyright 1997-2009 by Tobias OetikerCompiled Apr 3 2014 13:07:03 Usage: rrdtool [options] command command_options Valid commands: create, update, updatev, graph, graphv, dump, restore, last, lastupdate, first, info, fetch, tune, resize, xport RRDtool is distributed under the Terms of the GNU General Public License Version 2. (www.gnu.org/copyleft/gpl.html) For more information read the RRD manpages
四、安装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_installation Enter current password for root (enter for none): Set root password? [Y/n] y Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y
创建cacti数据库
[root@www ~]# mysql -uroot -p -e "create database cacti"
授权cacti数据库用户
[root@www ~]# mysql -uroot -p -e "grant all on cacti.* to 'cacti'@'localhost' identified by 'cactipass';" [root@www ~]# mysql -uroot -p -e "flush privileges;"
导入数据库文件
[root@www ~]# mysql -uroot -p cacti < /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 -y install ntp [root@www ~]# ntpdate ntpdate time.nist.gov ##同步时间 [root@www ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ##替换系统时区
配置php.ini文件的时区为Asia/Shanghai
[root@www ~]# vim /etc/php.ini date.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@www cacti-spine-0.8.8f]# ./configure [root@www cacti-spine-0.8.8f]# make gcc -DHAVE_CONFIG_H -I. -I./config -I/usr/include/mysql -g -O2 -MT sql.o -MD -MP -MF .deps/sql.Tpo -c -o sql.o sql.c In file included from sql.c:34: common.h:133:38: error: net-snmp/net-snmp-config.h: No such file or directory common.h:134:32: error: net-snmp/utilities.h: No such file or directory common.h:135:40: error: net-snmp/net-snmp-includes.h: No such file or directory common.h:136:33: error: net-snmp/config_api.h: No such file or directory common.h:137:30: error: net-snmp/mib_api.h: No such file or directory In file included from spine.h:505, from sql.c:35: snmp.h:41: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token make: *** [sql.o] Error 1
报错提示:需安装net-snmp-devel解决依赖
[root@www cacti-spine-0.8.8f]# yum -y install net-snmp-devel [root@www cacti-spine-0.8.8f]# yum install libtool
[root@www cacti-spine-0.8.8f]# make [root@www cacti-spine-0.8.8f]# make install make[1]: Entering directory `/root/cacti-spine-0.8.8f' /bin/mkdir -p '/usr/local/spine/bin' /bin/sh ./libtool --mode=install /usr/bin/install -c spine '/usr/local/spine/bin' libtool: install: /usr/bin/install -c spine /usr/local/spine/bin/spine /bin/mkdir -p '/usr/local/spine/etc' /usr/bin/install -c -m 644 spine.conf.dist '/usr/local/spine/etc' make[1]: Leaving directory `/root/cacti-spine-0.8.8f' You have new mail in /var/spool/mail/root [root@www cacti-spine-0.8.8f]# ls /usr/local/spine/ bin etc
拷贝spine配置文件并修改相应配置
[root@www ~]# cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf [root@www ~]# vim /etc/spine.conf DB_Host localhost DB_Database cacti DB_User cacti DB_Pass cactipass DB_Port 3306
启动spine
[root@www ~]# /usr/local/spine/bin/spine SPINE: Using spine config file [/etc/spine.conf] SPINE: Version 0.8.8f starting SPINE: Time: 0.1549 s, 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-snmp net-snmp-devel net-snmp-utils
修改snmpd.conf配置文件
[root@sh ~]# vim /etc/snmp/snmpd.conf 55 view systemview included .1.3.6.1.2.1 162 #syslocation Unknown (edit /etc/snmp/snmpd.conf) 163 #syscontact Root(configure /etc/snmp/snmp.local.conf) 164 syslocation 192.168.1.251 #本机IP 165 syscontact Root root@huangmingming.cn #接收邮件的邮箱
更改系统时间
[root@sh ~]# ntpdate ntpdate time.nist.gov [root@sh ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
开启snmpd
[root@sh ~]# /etc/init.d/snmpd start
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/spine SPINE: Using spine config file [/etc/spine.conf] SPINE: Version 0.8.8f starting SPINE: Time: 0.1185 s, 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/nologin nagios
[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@www nagios-4.1.1]# ./configure --prefix=/usr/local/nagios --sysconfdir=/etc/nagios --with-command-group=nagcmd ...... General Options: ------------------------- Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagcmd Event Broker: yes Install ${prefix}: /usr/local/nagios Install ${includedir}: /usr/local/nagios/include/nagios Lock file: ${prefix}/var/nagios.lock Check result directory: ${prefix}/var/spool/checkresults Init directory: /etc/rc.d/init.d Apache conf.d directory: /etc/httpd/conf.d Mail program: /bin/mail Host OS: linux-gnu IOBroker Method: epoll Web Interface Options: ------------------------ HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP):
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@www nagios-4.1.1]# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg Nagios Core 4.1.1 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 08-19-2015 License: GPL Website: https://www.nagios.org Reading configuration data... Read main config file okay... Read object config files okay... Running pre-flight check on configuration data... Checking objects... Checked 8 services. Checked 1 hosts. Checked 1 host groups. Checked 0 service groups. Checked 1 contacts. Checked 1 contact groups. Checked 24 commands. Checked 5 time periods. Checked 0 host escalations. Checked 0 service escalations. Checking for circular paths... Checked 1 hosts Checked 0 service dependencies Checked 0 host dependencies Checked 5 timeperiods Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check
[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/passwd nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin
http.conf配置
[root@www ~]# vim /etc/httpd/conf/httpd.conf 242 User apache 243 Group apache 402 DirectoryIndex index.html index.html.var index.php 781 AddType application/x-httpd-php .php .phtml 在最后增加以下内容: #setting for nagios ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"AuthType Basic Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthUserFile /etc/nagios/passwd Require valid-user Alias /nagios "/usr/local/nagios/share"AuthType Basic Options None AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthUserFile /etc/nagios/passwd Require valid-user
[root@www ~]# /etc/init.d/httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
网页登录
Nagios4.1.1版本主页中间显示不了www.youtube.com页面,可是为了追求美观,干脆把它替换掉,找到URL的位置把它替换为全球实时展示******网站,观赏全球******走向O(∩_∩)O哈哈~
[root@www share]# grep 'www.youtube.com' main.php
[root@www share]# vim /usr/local/nagios/share/main.php ('') 替换url: ('')
如图
当前标题:Cacti和Nagios整合
网页链接:http://lswzjz.com/article/pssdhp.html