天天看點

nagios_as5_install監控系統的搭建

nagios_as5_install監控系統的搭建:

一:nagios簡介:

Nagios是一款用于系統和網絡監控的應用程式。它可以在你設定的條件下對主機和服務進行監控,在狀态變差和變好的時候給出告警資訊。 

Nagios最初被設計為在linux系統之上運作,然而它同樣可以在類Unix的系統之上運作。 

Nagios更進一步的特征包括: 

1.監控網絡服務(SMTP、POP3、HTTP、NNTP、PING等); 

2.監控主機資源(處理器負荷、磁盤使用率等);

3.簡單地插件設計使得使用者可以友善地擴充自己服務的檢測法;

4.并行服務檢查機制; 

5.具備定義網絡分層結構的能力,用"parent"主機定義來表達網絡主機間的關系,這種關系可被用來發現和明晰主機當機或不可達狀态; 

6.當服務或主機問題産生與解決時将告警發送給聯系人(通過EMail、短信、使用者定義方式); 

7.具備定義事件句柄功能,它可以在主機或服務的事件發生時擷取更多問題定位;

8.自動的日志復原; 

9.可以支援并實作對主機的備援監控; 

10.可選的WEB界面用于檢視目前的網絡狀态、通知和故障曆史、日志檔案等; 

Nagios所需要的運作條件是機器必須可以運作Linux(或是Unix變種)并且有C語言編譯器。你必須正确地配置TCP/IP協定棧以使大多數的服務檢測可以通過網絡得以進行。

你需要但并非必須正确地配置Nagios裡的CGIs程式,而一旦你要使用CGI程式時,你必須要安裝以下這些軟體...

二:簡單快速安裝nagios

2.1 準備軟體包

在做安裝之前确認要對該機器擁有root權限。

确認你安裝好的linux系統上已經安裝如下軟體包再繼續。

Apache

GCC編譯器

GD庫與開發庫

可以用yum指令來安裝這些軟體包,鍵入指令:

yum –y install httpd gcc glibc glibc-common gd gd-devel

2.2

操作過程

2.2.1

建立nagios賬号

/usr/sbin/useradd nagios && passwd nagios

建立一個使用者組名為nagcmd用于從Web接口執行外部指令。将nagios使用者和apache使用者都加到這個組中。

/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -G nagcmd nagios

/usr/sbin/usermod -G nagcmd apache

2.2.2

下載下傳nagios和插件程式包

cd /usr/local/src

2.2.3

編譯與安裝nagios

tar zxvf nagios-3.0.6.tar.gz

cd nagios-3.0.6

./configure --with-command-group=nagcmd --prefix=/usr/local/nagios

make all

make install

make install-init

make install-config

make install-commandmode

驗證程式是否被正确安裝。切換目錄到安裝路徑(這裡是/usr/local/nagios),

看是否存在 etc、bin、 sbin、 share、 var這五個目錄,如果存在則可以表明程式被正确的安裝到系統了。

後表是五個目錄功能的簡要說明:

bin Nagios執行程式所在目錄,nagios檔案即為主程式

etc Nagios配置檔案位置,初始安裝完後,隻有幾個*.cfg-sample檔案,3與2差別 對象配置檔案都在etc/objects目錄下

sbin Nagios Cgi檔案所在目錄,也就是執行外部指令所需檔案所在的目錄

Share Nagios網頁檔案所在的目錄

Var Nagios日志檔案、spid 等檔案所在的目錄

var/archives Empty directory for the archived logs

var/rw Empty directory for the external command file

2.2.4

編譯并安裝nagios插件 nagios-plugins

tar zxvf nagios-plugins-1.4.13.tar.gz

cd nagios-plugins-1.4.13

./configure --with-nagios-user=nagios --with-nagios-group=nagios

--perfix=/usr/local/nagios

make && make install

驗證:

ls /usr/local/nagios/libexec

會顯示安裝的插件檔案,即所有的插件都安裝在libexec這個目錄下

2.2.5

配置WEB接口

方法一:直接在安裝nagios時 make install-webconf

建立一個nagiosadmin的使用者用于Nagios的WEB接口登入。記下你所設定的登入密碼,一會兒你會用到它。

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

重新開機Apache服務以使設定生效。

service httpd restart

2.2.6

啟動nagios

把Nagios加入到服務清單中以使之在系統啟動時自動啟動

chkconfig --add nagios

chkconfig nagios on

驗證Nagios的樣例配置檔案

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

如果沒有報錯,可以啟動Nagios服務

service nagios start

三:監控linux和windows主機

3.1 遠端linux客戶機的配置:

#useradd nagios

#passwd nagios

#tar -zxvf nagios-plugins-***.tar.gz

#cd nagios-plugins-***

#./configure

#make

#make install

#chown nagios.nagios /usr/local/nagios

#chown -R nagios.nagios /usr/local/nagios/libexec

#tar -zxvf nrpe-2.12.tar.gz

#cd nrpe-2.12

#make all

#make install-plugin

#make install-daemon

#make install-daemon-config

#/usr/local/nagios/libexec/check_nrpe -H localhost

#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

3.2監控機linux服務端的配置:

=================================

由于nrpe外構元件,是以必須在commands.cfg中定義(我這裡的nagios版本是3.0.6和2。x的版本有些不一樣)

[root@localhost etc]# vi /usr/local/nagios/etc/objects/commands.cfg

最下面添加

#check nrpe

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

========================================================

[root@localhost etc]# vi /usr/local/nagios/etc/nagios.cfg

中間添加

cfg_file=/usr/local/nagios/etc/objects/nagios-client-01.cfg

最後面的 nagios-client-01.cfg你們可以自己改,或者Linux1.cfg也可以!

=================================================

建立nagios-client-01.cfg:

[root@dns objects]# vi /usr/local/nagios/etc/objects/nagios-client-01.cfg

define host{

use linux-server

host_name nagios-client-01

alias nagios-client-01

address 172.21.1.108 

define service{

use generic-service

service_description HTTP

check_command check_http

service_description FTP

check_command check_ftp

service_description SSH

check_command check_ssh

service_description SMTP

check_command check_smtp

service_description POP3

check_command check_pop

service_description check-swap

check_command check_nrpe!check_swap

service_description check-load

check_command check_nrpe!check_load

service_description check-disk

check_command check_nrpe!check_hda1

service_description zombie_procs

check_command check_nrpe!check_zombie_procs

service_description check-users

check_command check_nrpe!check_users

service_description total_procs

check_command check_nrpe!check_total_procs

儲存後,退出即可!

我們來運作

檢測下是不是都正确!正确的話,那麼我們重新啟動nagios

那麼在web頁面裡面就會出現!!

同理,windows的也是一樣的道理。

    本文轉自vcdog 51CTO部落格,原文連結:http://blog.51cto.com/255361/837471,如需轉載請自行聯系原作者