Nagios安裝真可愛

煮酒品茶:cwtea.blog.51cto.com

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),綏濱企業(yè)網(wǎng)站建設(shè),綏濱品牌網(wǎng)站建設(shè),網(wǎng)站定制,綏濱網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,綏濱網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

簡述:本文講述了nagios安裝的過程以及Nagios整個工作過程。你可以定制一些你需要的。哪怕修改源碼都可以。你會發(fā)現(xiàn)原來以前你不迷糊的地方在這里都有了解釋。nagios會變得這么可愛,生命是那么的精彩。
 
Nagios官方網(wǎng)站:http://www.nagios.org/
Nagios下載地址:http://sourceforge.net/projects/nagios/?source=directory-featured
Nagios-plus下載地址:
http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz/download?use_mirror=jaist
NRPE下載地址:
http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz/download?use_mirror=jaist
SystemOS:CentOS6.3
Nagios 官方文檔 http://nagios.sourceforge.net/docs/nagioscore/3/en/config.html
 
有依賴關(guān)系:
httpd php 
gcc make
#如果沒有安裝以上程序,可以用yum安裝。
 #yum intsall -y httpd php gcc make
#安裝:
 tar zxvf nagios-3.5.0rc2.tar.gz 
cd nagios
#詳見下方./configure: make:將有說明。
 ./configure --prefix=/usr/local/nagios
make all
make install
useradd nagios
#把nagios加入到apache組。
usermod -G nagios apache
make install
make install-init
make install-commandmode
make install-config
make install-webconf
 
#安裝nagios-plugins
#依賴:openssl yum可以安裝。
#yum install -y openssl openssl-devel 
 ./configure --prefix=/usr/local/nagios
make
make install
 
#檢查一下:
[root@nagios nagios-plugins-1.4.16]# ls /usr/local/nagios/libexec/
 
 
./configure:
 Creating sample config files in sample-config/ ...
 
 
*** Configuration summary for nagios 3.5.0rc2 03-09-2013 ***:
 
 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
            Embedded Perl:  no
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
#PID號
                Lock file:  ${prefix}/var/nagios.lock
#檢查結(jié)果目錄
   Check result directory:  ${prefix}/var/spool/checkresults
#服務(wù)配置目錄
           Init directory:  /etc/rc.d/init.d
#apache for nagios目錄
  Apache conf.d directory:  /etc/httpd/conf.d
#mail程序
             Mail program:  /bin/mail
#主機名
                  Host OS:  linux-gnu
 
 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.
 
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
#安裝主程序,CGI文件和Html文件。
  make install-init
     - This installs the init script in /etc/rc.d/init.d
#安裝nagios服務(wù),腳本在/etc/rc.d/init.d/nagios
  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file
#安裝和配置權(quán)限在外部命令目錄
  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       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!
#把樣版配置文件拷到/usr/local/nagios/etc目錄。
  make install-webconf
     - This installs the Apache config file for the Nagios
       web interface
#安裝apache配置nagios選項文件。yum安裝會創(chuàng)建/etc/http/conf.d/nagios.cfg
  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
   #經(jīng)典主題
  
二、安裝完后的配置
#啟動httpd、nagios服務(wù)
#service httpd start
#service nagios start
#訪問http://localhost/nagios會提示輸入帳號密碼,這是我們的make install-webconf生效了。
#打開看看
[root@nagios nagios-plugins-1.4.16]# cat /etc/httpd/conf.d/nagios.conf 
 # SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file.  Customize the paths, etc. as
# needed to fit your system.
 
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
 
<Directory "/usr/local/nagios/sbin">
#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>
 
Alias /nagios "/usr/local/nagios/share"
 
<Directory "/usr/local/nagios/share">
#  SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>
#可以清楚的看到可以定制訪問權(quán)限,以及驗證所在文件:/usr/local/nagios/etc/htpasswd.users
#生成一個
[root@nagios nagios-plugins-1.4.16]# htpasswd -c /usr/local/nagios/etc/htpasswd.users cwtea
#重新進入http://localhost/nagios,輸入剛才的帳號密碼,應(yīng)該進去了。
圖1:
 

Nagios安裝真可愛

#開始配置服務(wù)了。
#我們make install-config會烤貝一些樣例在...prefix/nagios/etc下
#主配置文件nagios.cfg中文說明文檔:轉(zhuǎn)載
1、http://blog.chinaunix.net/uid-374372-id-89822.html
2、http://blog.chinaunix.net/uid-374372-id-89823.html
 
#error
 The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. 
More information about this error may be available in the server error log.
#查看日志,selinux在作怪
 [Fri Mar 15 00:22:46 2013] [error] [client 192.168.100.80] (13)Permission denied: exec of '/usr/local/nagios/sbin/status.cgi' failed, referer: http://192.168.100.84/nagios/side.php
#setenforce 0/1 0為寬容,1為緊張。
#setenforce 0 
#配置cgi.cgi以使我們創(chuàng)建的帳號獲取更高的權(quán)限,而不會提示:
 It appears as though you do not have permission to view information for any of the services you requested...
#由于我們并沒有nagiosadmin此用戶,所以我們直接替換。多個可以用逗號隔開。可先備份cgi.cgi文件
[root@nagios etc]# sed -i 's/nagiosadmin/cwtea/g' cgi.cfg 
[root@nagios etc]# cat cgi.cfg |grep cwtea
 authorized_for_system_information=cwtea
authorized_for_configuration_information=cwtea
authorized_for_system_commands=cwtea
authorized_for_all_services=cwtea
authorized_for_all_hosts=cwtea
authorized_for_all_service_commands=cwtea
authorized_for_all_host_commands=cwtea
#下面就是修改配置文件了添加服務(wù)等。請自行查看nagios中文說明文檔再進行操作。
#我這里創(chuàng)建一個主機組主機 聯(lián)系人組聯(lián)系人共存的配置文件。如果主機夠多可再建個文件。
#具體函義請查看說明文檔。
[root@nagios etc]# vim objects/hc.cfg
 #hostgroup
define hostgroup {
         hostgroup_name  ktm-server
         alias           ktm server
         members         nagios-server
         }
#host
define host {
       host_name                  nagios-server
       alias                      nagios server
       address                    192.168.100.85
       contact_groups             ktm
       check_command              check-host-alive
       max_check_attempts         5
       notification_interval      10
       notification_period        24x7
       notification_options        d,u,r
       }
#contact
define contact {
        contact_name    cwtea
        alias   system administrator
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                          zwhset@163.com
        pager                          15010228888
        }
#contactgroup
define contactgroup {
        contactgroup_name ktm
        alias   system administrator
        members cwtea
}
#再創(chuàng)建服務(wù)模塊
[root@nagios etc]# vim objects/service.cfg
 #service in host
define service {
        host_name        nagios-server
        service_description   check-host-alive
        check_period          24x7
        max_check_attempts    4
        normal_check_interval 3
        retry_check_interval  2
        contact_groups        ktm
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command           check-host-alive
        }
#查看一下templates.cfg  timeperiods.cfg兩個配置文件的內(nèi)容以達到我們配置的目的。
#編輯nagios.cfg文件以加載這幾個文件的目的。并且注銷掉localhost.cfg文件。我們不需要。
[root@nagios objects]# vim ../nagios.cfg 
 cfg_file=/usr/local/nagios/etc/objects/hc.cfg
cfg_file=/usr/local/nagios/etc/objects/service.cfg
#add #
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
 
#驗證一下nagios配置是否正確,直到Total Warnings: 0 Total Errors:   0。當(dāng)然有錯誤排查錯誤,一般都會提示非常清楚。
[root@nagios objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
#滑溜啟動一下nagios
#根據(jù)上面編譯提示我們的PID保存文件。
#[root@nagios objects]# kill -Hup `cat /usr/local/nagios/var/nagios.lock`
#太長了,我們可以取巧一下。也可添加到~/.bashrc文件中,這樣我們就可以knagios滑溜升級,vnagios驗證配置文件。
[root@nagios ~]# alias knagios='kill -Hup `cat /usr/local/nagios/var/nagios.lock`'
[root@nagios ~]# alias vnagios='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'
#再看看Nagios監(jiān)控我們的web界面。
圖2:

Nagios安裝真可愛

 
添加服務(wù)到監(jiān)控報警并郵件可看另一篇文章。
Nagios檢測一些記序:
http://cwtea.blog.51cto.com/4500217/1153384
 
煮酒品茶:我們再來看看一些好玩的東西吧。
[root@nagios var]# pwd
/usr/local/nagios/var
[root@nagios var]# tree
 .
├── archives
├── nagios.lock #PID號保存文件。
├── nagios.log #當(dāng)然是日志啦。
├── objects.cache #當(dāng)你查看這個文件,你就會喜歡上他了。緩存的,看下面解釋。
├── retention.dat #上面緩存一個,這里又保留一個。好兄弟要哥倆啊。
├── rw
│?? └── nagios.cmd #看下面解決。
├── spool
│?? └── checkresults #這個文件夾在工作的時候會經(jīng)常寫冊文件,這當(dāng)然是在采集數(shù)據(jù)存放于此。
└── status.dat #這個就有意思了,網(wǎng)站讀的就是這個文件,service模塊下有個performance_data=rta=0.497000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0,對比網(wǎng)站上的是不是一樣?
 
#objects.cache 解釋:
 # OBJECT CACHE FILE
# This option determines where object definitions are cached when
# Nagios starts/restarts.  The CGIs read object definitions from
# this cache file (rather than looking at the object config files
# directly) in order to prevent inconsistencies that can occur
# when the config files are modified after Nagios starts.
對象緩存文件。這些選項將決定當(dāng)Nagios啟動時或重新啟動時,對象定義將被緩存在什么地方。CGI將從這個對象文件中讀取對象的定義,而不是在之前的對象配置文件路徑中去找。這樣做是為了避免修改Nagios配置文件后引起的不一致問題。換句簡單的話說就是更改配置文件后要重新運新Nagios新的配置參數(shù)才會生效,而當(dāng)前運行的Nagios只參考緩存中的配置參數(shù)而已。
 
object_cache_file=/var/log/nagios/objects.cache
 
#nagios.cmd 解釋:
 # EXTERNAL COMMAND FILE
# This is the file that Nagios checks for external command requests.
# It is also where the command CGI will write commands that are submitted
# by users, so it must be writeable by the user that the web server
# is running as (usually 'nobody').  Permissions should be set at the
# directory level instead of on the file, as the file is deleted every
# time its contents are processed.
這是Nagios用來檢查外部命令請求的文件。這個文件同樣也是用戶操作提交與CGI命令寫入的地方,所以這個文件必須對于相關(guān)服務(wù)可寫,一般是針對Apache的宿主用戶可寫。并且注意,這個文件所在的目錄的權(quán)限必須被Apache可寫,而不單指這文件,因為這個文件在工作當(dāng)中是頻繁被刪除的。(之前我們將Apahe歸入Nagios組的時候就已經(jīng)完成了)
 
command_file=/var/log/nagios/rw/nagios.cmd
 
#status.dat 解釋:
 # STATUS FILE
# This is where the current status of all monitored services and
# hosts is stored.  Its contents are read and processed by the CGIs.
# The contents of the status file are deleted every time Nagios
#  restarts.
狀態(tài)文件。這個文件將保存著目前檢測到的服務(wù)和主機數(shù)據(jù)信息。這個文件當(dāng)中的內(nèi)容是被CGI讀取并處理的,而它也是在每次Nagios重新啟動的時候被刪除清空的。
 
status_file=/var/log/nagios/status.dat
 
[root@nagios bin]# pwd
/usr/local/nagios/bin
[root@nagios bin]# tree
 .
├── nagios  #這個是啟動文件
└── nagiostats #運行一下這個,你會發(fā)現(xiàn)世界是多么的精彩。這個不就是nagios web界面上的信息嗎?他也是采集這個文件。
圖3:
 

Nagios安裝真可愛

#看看權(quán)限,是不是印證了?
[root@nagios bin]# ll nagiostats 
-rwxrwxr--. 1 nagios nagios 44104 Mar 14 21:49 nagiostats
#那么都有些啥目錄呢?都有啥用?
[root@nagios nagios]# ls
bin  etc  include  libexec  sbin  share  var
 #網(wǎng)上找的說明,難得敲字。
bin   Nagios執(zhí)行程序所在目錄,nagios文件即為主程序
etc   Nagios配置文件位置,初始安裝完后,只有幾個*.cfg-sample文件
sbin  Nagios Cgi文件所在目錄,也就是執(zhí)行外部命令所需文件所在的目錄
Share Nagios網(wǎng)頁文件所在的目錄
Var   Nagios日志文件、spid 等文件所在的目錄
#發(fā)現(xiàn)每次打開http://localhost/nagios登入后都是廣告。頭疼。那我們修改一下吧。
#用firefox打開后只顯示那個廣告框架。發(fā)現(xiàn)加載的是main.php。再加載我們想要的service標(biāo)簽。發(fā)現(xiàn)加載的是cgi-bin/status.cgi這個cgi
[root@nagios share]# pwd
/usr/local/nagios/share
#注銷掉或者直接更改都可。
[root@nagios share]# vim index.php
 //$corewindow="main.php"; 
$corewindow="cgi-bin/status.cgi";
#再次打開http://localhost/nagios 直接加載的就是service標(biāo)簽了。見圖4
圖4:
 

Nagios安裝真可愛

那么整個nagios的工作過程你明白了嗎?
煮酒品茶:我們的玩nagios就結(jié)束了。哈哈哈,還蠻有意思的。   

 

當(dāng)前文章:Nagios安裝真可愛
文章轉(zhuǎn)載:http://muchs.cn/article32/gheisc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、服務(wù)器托管、網(wǎng)站策劃、網(wǎng)站內(nèi)鏈營銷型網(wǎng)站建設(shè)、網(wǎng)站設(shè)計公司

廣告

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

綿陽服務(wù)器托管