Cacti和Nagios整合-創(chuàng)新互聯(lián)

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

10年積累的網(wǎng)站制作、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站策劃后付款的網(wǎng)站建設(shè)流程,更有休寧縣免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

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

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

  • 安裝擴(kuò)展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"
  • 授權(quán)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;"
  • 導(dǎo)入數(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)時(shí)區(qū)及時(shí)間

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

[root@www ~]# vim /etc/php.ini 
date.timezone = 'Asia/Shanghai'
  • 添加抓圖計(jì)劃任務(wù)

[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整合

  • 轉(zhuǎn)到登錄頁面,默認(rèn)登錄名和密碼都是admin,輸入會(huì)提示修改密碼,Save后顯示cacti主頁面

Cacti和Nagios整合

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

Cacti和Nagios整合

六、安裝cacti優(yōu)化輪詢器spine

  • 下載cacti-spine,版本對(duì)應(yīng)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
  • 報(bào)錯(cuò)提示:需安裝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配置文件并修改相應(yīng)配置

[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
  • 啟動(dòng)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頁面下設(shè)置spine的路徑,完成配置

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

  • 選擇spine輪詢方式

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

七、Cacti添加監(jiān)控客戶機(jī)

  • 安裝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  #本機(jī)IP
165 syscontact Root root@huangmingming.cn  #接收郵件的郵箱
  • 更改系統(tǒng)時(shí)間

[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服務(wù)端web設(shè)置,添加主機(jī)(Devices-->Add-->Description-->Hostname-->Host Template-->Number of Collection Threads-->SNMP Version-->Create---*Create Graphs for this Host-->選擇要監(jiān)控的模塊)

Cacti和Nagios整合

  • 將添加的主機(jī)加入到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配置

  • 設(shè)置nagios驗(yàn)證用戶和密碼

[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的位置把它替換為全球?qū)崟r(shí)展示******網(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整合

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

當(dāng)前文章:Cacti和Nagios整合-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://www.bm7419.com/article2/dgcsic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、微信公眾號(hào)定制網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、營銷型網(wǎng)站建設(shè)、小程序開發(fā)

廣告

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

網(wǎng)站托管運(yùn)營