Linux系統搭建Nagios監控平臺


1、首先在Nagios監控的服務器部署php

# 安裝Nagios軟件及其依賴的軟件
[root@nagios ~]# yum install -y httpd php gcc glibc glibc-common net-snmp nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe gd gd-devel openssl openssl-devel
# 定義Nagios登錄的帳號與密碼
[root@nagios ~]# htpasswd -c /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
# 對配置文件進行檢測
[root@nagios ~]# nagios -v /etc/nagios/nagios.cfg

Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/etc/nagios/objects/commands.cfg'...
Processing object config file '/etc/nagios/objects/contacts.cfg'...
Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
Processing object config file '/etc/nagios/objects/templates.cfg'...
Processing object config file '/etc/nagios/objects/localhost.cfg'...
Processing object config directory '/etc/nagios/conf.d'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
        Checked 8 services.
Checking hosts...
        Checked 1 hosts.
Checking host groups...
        Checked 1 host groups.
Checking service groups...
        Checked 0 service groups.
Checking contacts...
        Checked 1 contacts.
Checking contact groups...
        Checked 1 contact groups.
Checking service escalations...
        Checked 0 service escalations.
Checking service dependencies...
        Checked 0 service dependencies.
Checking host escalations...
        Checked 0 host escalations.
Checking host dependencies...
        Checked 0 host dependencies.
Checking commands...
        Checked 24 commands.
Checking time periods...
        Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
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@nagios ~]# service httpd start
正在啓動 httpd:                                           [肯定]
[root@nagios ~]# service nagios start
Starting nagios: done.

經過瀏覽器進行訪問,輸入以前設定帳號與密碼,進行登錄linux

wKiom1V9IzHzlxilAAJgh6QFWEU914.jpg


登錄成功後,咱們能夠分別查看主機,以及所監控的服務
ios

wKiom1V9I32R4QAwAATFkOodFEs728.jpg


監控的主機,默認的只有監控服務器主機一臺web

wKiom1V9I9OCi2xHAARbzcu1i-A149.jpg


監控的服務vim

wKioL1V9JcfiSHP7AAYOxGN0dRU799.jpg




2、監控服務器的基本架構以及搭建起來,接下來咱們開始配置被監控主機,看一下如何添加主機windows

# 在客戶端安裝必要的軟件
[root@web1 ~]# yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe openssl openssl-devel
[root@web1 ~]# vim /etc/nagios/nrpe.cfg
................................
# 這裏須要添加容許訪問的主機地址
allowed_hosts=127.0.0.1,192.168.1.132
.................................
# 啓動服務
[root@web1 ~]# service nrpe start
Starting nrpe:                                             [肯定]

# nagios的主機是以配置文件進行劃分主機的,因此咱們只要建立對應主機的配置文件
[root@nagios ~]# cd /etc/nagios/objects/
# 這個目錄下有不少的配置文件,功能各不相同,咱們會以本機默認配置爲模板,定義主機配置文件
[root@nagios objects]# ls
commands.cfg  contacts.cfg  localhost.cfg  printer.cfg  switch.cfg  templates.cfg  timeperiods.cfg  windows.cfg
[root@nagios ~]# vim /etc/nagios/conf.d/web1.cfg
# 基本監測服務配置形態
efine host{
        use                     linux-server
        host_name               web1
        alias                   web1.com
        address                 192.168.1.130
        }

define service{
        use                             generic-service
        host_name                       web1
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        max_check_attempts 5
        normal_check_interval 1
        notification_interval           60
        }
        
define service{
        use                             generic-service
        host_name                       web1
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
       
define service{
        use                             generic-service
        host_name                       web1
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           1
        contact_groups                  admins
        notification_period   24x7
        notification_options            w,u,c,r
        }
# 對配置文件的正確性進行檢查        
[root@nagios ~]# nagios -v /etc/nagios/nagios.cfg

Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/etc/nagios/objects/commands.cfg'...
Processing object config file '/etc/nagios/objects/contacts.cfg'...
Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
Processing object config file '/etc/nagios/objects/templates.cfg'...
Processing object config file '/etc/nagios/objects/localhost.cfg'...
Processing object config file '/etc/nagios/objects/windows.cfg'...
Processing object config directory '/etc/nagios/conf.d'...
Processing object config file '/etc/nagios/conf.d/web1.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
        Checked 25 services.
Checking hosts...
        Checked 3 hosts.
Checking host groups...
        Checked 2 host groups.
Checking service groups...
        Checked 0 service groups.
Checking contacts...
        Checked 1 contacts.
Checking contact groups...
        Checked 1 contact groups.
Checking service escalations...
        Checked 0 service escalations.
Checking service dependencies...
        Checked 0 service dependencies.
Checking host escalations...
        Checked 0 host escalations.
Checking host dependencies...
        Checked 0 host dependencies.
Checking commands...
        Checked 25 commands.
Checking time periods...
        Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
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@nagios ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

         到主機選項中查看,增長了一個web1的主機瀏覽器

wKioL1V9kuyhcW_IAALzpH9QWp8950.jpg


圖:一
bash


wKiom1V-ObHzJIaVAAbXm2hU42A660.jpg

圖:二服務器

基本形態已經完成
架構

功能增長:

一、監控負載與硬盤狀態

# 在監控服務器上修改配置
[root@nagios ~]# vim /etc/nagios/objects/commands.cfg
..............................
# 在配置中增長如下內容
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
..............................


[root@nagios ~]# vim /etc/nagios/conf.d/web1.cfg
# 增長監控系統負載和硬盤的狀態
....................................
define service{
        use     generic-service
        host_name                       web1
        service_description             check_load
        check_command                   check_nrpe!check_load
        max_check_attempts 5
        normal_check_interval 1
        }


define service{
        use                             generic-service
        host_name                       web1
        service_description             check_disk_hda1
        check_command                   check_nrpe!check_hda1
        max_check_attempts 5
        normal_check_interval 1
        }
[root@nagios ~]# nagios -v /etc/nagios/nagios.cfg
..........................................
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
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@nagios ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.


修改被監控主機的配置

[root@web ~]# vim /etc/nagios/nrpe.cfg
..........................................
# 後面的/dev/hda1修改成/dev/sda1
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
.........................................
[root@web ~]# /etc/init.d/nrpe restart
Shutting down nrpe:                                        [肯定]
Starting nrpe:                                             [肯定]


再次查看瀏覽器,剛纔配置的兩個監控項目,能夠了


wKiom1V-YSCByLKRAAZTfzdK98g236.jpg


二、配置告警

# 修改監控服務器配置
[root@nagios ~]# vim /etc/nagios/objects/contacts.cfg

define contact{
        contact_name                    nagiosadmin            
        use                             generic-contact        
        alias                           Nagios Admin        
        email                           nagios@localhost   <== 這裏修改成郵件地址   
        }
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin
        }


# 修改要監控的服務        
[root@nagios ~]# vim /etc/nagios/conf.d/web1.cfg
.................................................

# 設置來監控HTTP服務
define service{
        use                             generic-service
        host_name                       web1
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           1
        contact_groups                  admins
        notification_period   24x7
        notification_options            w,u,c,r
        }
..................................................

[root@nagios ~]# nagios -v /etc/nagios/nagios.cfg

Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL

...........................................................

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
[root@nagios ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

# 安裝發送郵件的服務並啓動
[root@nagios ~]# yum install -y sendmail
[root@nagios ~]# /etc/init.d/sendmail start
正在啓動 sendmail:                                        [肯定]
啓動 sm-client:                                           [肯定]


咱們在客戶機上中止http服務,來進行測試告警郵件

[root@web ~]# /etc/init.d/httpd stop
中止 httpd:                                               [肯定]
相關文章
相關標籤/搜索