Cacti和Nagios整合

        Cacti是一套基于PHP,MySQL,SNMP及RRDTool開發(fā)的網(wǎng)絡流量監(jiān)測圖形分析工具。用來監(jiān)控網(wǎng)絡流量、cpu使用率、內(nèi)存使用率、硬盤使用率等??梢灾庇^的監(jiān)控各種數(shù)據(jù)流量,可以安裝擴展插件,同時支持短信郵件告警等功能。

成都創(chuàng)新互聯(lián)公司:2013年至今為各行業(yè)開拓出企業(yè)自己的“網(wǎng)站建設”服務,為近千家公司企業(yè)提供了專業(yè)的網(wǎng)站設計、網(wǎng)站建設、網(wǎng)頁設計和網(wǎng)站推廣服務, 按需網(wǎng)站制作由設計師親自精心設計,設計的效果完全按照客戶的要求,并適當?shù)奶岢龊侠淼慕ㄗh,擁有的視覺效果,策劃師分析客戶的同行競爭對手,根據(jù)客戶的實際情況給出合理的網(wǎng)站構架,制作客戶同行業(yè)具有領先地位的。

        Nagios是一個監(jiān)視系統(tǒng)運行狀態(tài)和網(wǎng)絡信息的監(jiān)視系統(tǒng)。Nagios能監(jiān)視所指定的本地或遠程主機以及服務,提供異常通知功能,同時還可以安裝各種模塊插件,自定義監(jiān)控腳本等。

        兩者區(qū)別:Cacti偏重于網(wǎng)絡流量,系統(tǒng)負載方面的監(jiān)控。而 Nagios偏重于系統(tǒng)服務方面的監(jiān)控,你可以在被監(jiān)控的機器上寫自己的程序(shell,c 或 perl都可以) 。Nagios則通過這些腳本來對服務進行監(jiān)控。Nagios可以和短信發(fā)送機配合用來監(jiān)控規(guī)模較大的網(wǎng)站。

  • 安裝擴展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環(huán)境

[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 Oetiker <tobi@oetiker.ch>
               Compiled 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,解壓放到網(wǎng)站目錄下

[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/

  • 初始化數(shù)據(jù)庫

[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
  • 創(chuàng)建cacti數(shù)據(jù)庫

[root@www ~]# mysql -uroot -p -e "create database cacti"
  • 授權cacti數(shù)據(jù)庫用戶

[root@www ~]# mysql -uroot -p -e "grant all on cacti.* to 'cacti'@'localhost' identified by 'cactipass';"
[root@www ~]# mysql -uroot -p -e "flush privileges;"
  • 導入數(shù)據(jù)庫文件

[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;
  • 調(diào)整系統(tǒng)時區(qū)及時間

[root@www ~]# yum -y install ntp
[root@www ~]# ntpdate ntpdate time.nist.gov  ##同步時間
[root@www ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  ##替換系統(tǒng)時區(qū)
  • 配置php.ini文件的時區(qū)為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

Cacti和Nagios整合

  • New install

Cacti和Nagios整合

  • Finish

Cacti和Nagios整合

  • 轉到登錄頁面,默認登錄名和密碼都是admin,輸入會提示修改密碼,Save后顯示cacti主頁面

Cacti和Nagios整合

  • 點擊graphs查看生成的圖形數(shù)據(jù)

Cacti和Nagios整合

六、安裝cacti優(yōu)化輪詢器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添加監(jiān)控客戶機

  • 安裝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 <root@localhost> (configure /etc/snmp/snmp.local.conf)
164 syslocation 192.168.1.251  #本機IP
165 syscontact Root root@huangmingming.cn  #接收郵件的郵箱
  • 更改系統(tǒng)時間

[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-->選擇要監(jiān)控的模塊)

Cacti和Nagios整合

  • 將添加的主機加入到Graph Trees中

Cacti和Nagios整合

[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
在最后增加以下內(nèi)容:
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/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
</Directory>

Alias /nagios "/usr/local/nagios/share"
<Directory "/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
</Directory>
[root@www ~]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

  • 網(wǎng)頁登錄

Cacti和Nagios整合Cacti和Nagios整合

  • Nagios4.1.1版本主頁中間顯示不了www.youtube.com頁面,可是為了追求美觀,干脆把它替換掉,找到URL的位置把它替換為全球實時展示******網(wǎng)站,觀賞全球******走向O(∩_∩)O哈哈~

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

[root@www share]# vim /usr/local/nagios/share/main.php
('<iframe width="100%" height="100%" src="http://
www.youtube.com/embed/videoseries?l
ist=PLN-ryIrpC_mCUW1DFwZpxpAk00i60lSkE&iv_load_policy=3&rel=0
" frameborder="0" 
allowfullscreen></iframe>')
替換url:
('<iframe width="100%" height="100%" src="http://
map.norsecorp.com
" frameborder="0" 
allowfullscreen></iframe>')
  • 如圖

Cacti和Nagios整合

本文名稱:Cacti和Nagios整合
文章鏈接:http://bm7419.com/article48/pssdhp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站網(wǎng)站導航面包屑導航、用戶體驗、動態(tài)網(wǎng)站、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設