【Nagios】Linux監(jiān)控軟件安裝與配置(二)-創(chuàng)新互聯(lián)

一、安裝擴展源

成都創(chuàng)新互聯(lián)成立于2013年,先為合水等服務建站,合水等地企業(yè),進行企業(yè)商務咨詢服務。為合水企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。

[root@www ~]# rpm -ivh http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm

二、安裝Nagios相關軟件包

[root@www ~]# yum -y install httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

三、設置nagios后臺登錄用戶名和密碼

[root@www ~]# htpasswd -c /etc/nagios/passwd nagiosadmin  #這里指定用戶名為nagiosadmin,而不是其他
New password: 
Re-type new password: 
Adding password for user nagiosadmin

四、檢查Nagios配置

[root@www ~]# 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

五、啟動Nagios和http服務

[root@www ~]# /etc/init.d/httpd start
Starting httpd:                                            [  OK  ]
[root@www ~]# /etc/init.d/nagios start
Starting nagios: done.

六、瀏覽器訪問

【Nagios】Linux監(jiān)控軟件安裝與配置(二)

【Nagios】Linux監(jiān)控軟件安裝與配置(二)

七、Nagios添加被監(jiān)控客戶端主機

1、安裝Nagios服務

[root@sh ~]# rpm -ivh epel-release-6-8.noarch.rpm
[root@sh ~]# yum -y install nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

2、修改/etc/nagios/nrpe.cfg文件

[root@sh ~]# vim /etc/nagios/nrpe.cfg

 81 allowed_hosts=127.0.0.1,192.168.1.21 #添加nagios服務端IP
 97 dont_blame_nrpe=1   #0改為1

3、啟動nrpe

[root@sh ~]# /etc/init.d/nrpe start
Starting nrpe:                                             [  OK  ]

4、Nagios服務端添加被監(jiān)控客戶端主機

[root@www ~]# cd /etc/nagios/conf.d/
[root@www conf.d]# ls
[root@www conf.d]# vim 192.168.1.251.cfg
define host{
        use                     linux-server
        host_name           192.168.1.251
        alias                       1.251
        address                 192.168.1.251
        }

define service{
        use                     generic-service
        host_name               192.168.1.251
        service_description     check_ping
        check_command           check_ping!100.0,20%!200.0,50%
        max_check_attempts 5
        normal_check_interval 1
}

define service{
        use                     generic-service
        host_name               192.168.1.251
        service_description     check_ssh
        check_command           check_ssh
        max_check_attempts      5  #當nagios檢測到問題時,一共嘗試檢測5次都有問題才會告警,如果該數(shù)值為1,那么檢測到問題立即告警
        normal_check_interval   1  #重新檢測的時間間隔,單位是分鐘,默認是3分鐘
        notification_interval   60 #在服務出現(xiàn)異常后,故障一直沒有解決,nagios再次對使用者發(fā)出通知的時間。如果你認為,所有的事件只需要一次通知就夠了,可以把這里的選項設為0
}

define service{
        use                     generic-service
        host_name               192.168.1.251
        service_description     check_http
        check_command           check_http
        max_check_attempts      5
        normal_check_interval 1
}

5、檢查配置

[root@www conf.d]# nagios -v /etc/nagios/nagios.cfg

6、重啟nagios

[root@www conf.d]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

7、查看效果

【Nagios】Linux監(jiān)控軟件安裝與配置(二)

八、添加nrpe支持的監(jiān)控服務

1、添加nrpe服務

[root@www ~]# vim /etc/nagios/objects/commands.cfg 
################################################################################


# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HO
STNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail
-s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService
: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAd
ditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$
is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

define command{
        command_name    check_nrpe  #自定義check
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }


################################################################################

2、添加nrpe服務腳本

[root@www ~]# vim /etc/nagios/conf.d/192.168.1.251.cfg
......
#check_nrpe
define service{
        use     generic-service
        host_name       192.168.1.251
        service_description     check_load  #監(jiān)控負載
        check_command           check_nrpe!check_load
        max_check_attempts 5
        normal_check_interval 1
}
define service{
        use     generic-service
        host_name       192.168.1.251
        service_description     check_disk_sda1
        check_command           check_nrpe!check_hda1  #check_nrpe為前面自定義的模塊名稱,check_hda1為被監(jiān)控主機/etc/nagios/nrpe.cfg文件里定義的腳本名稱
        max_check_attempts 5
        normal_check_interval 1
}
#define service{    #可以添加多塊磁盤監(jiān)控
#        use     generic-service
#        host_name       192.168.1.251
#        service_description     check_disk_hda2
#        check_command           check_nrpe!check_hda2
#        max_check_attempts 5
#        normal_check_interval 1
#}
[root@www ~]# nagios -v /etc/nagios/nagios.cfg 
.......
Total Warnings: 0
Total Errors:   0
Things look okay - No serious problems were detected during the pre-flight check

3、被監(jiān)控主機通過nrpe.cfg文件定義的腳本命令

[root@sh ~]# vim /etc/nagios/nrpe.cfg
# The following examples use hardcoded command arguments...

command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
#command[check_hda2]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda2
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200

4、重啟服務

[root@www ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@sh ~]# /etc/init.d/nrpe restart
Shutting down nrpe:                                        [  OK  ]
Starting nrpe:                                             [  OK  ]

5、web頁面查看結(jié)果

【Nagios】Linux監(jiān)控軟件安裝與配置(二)

6、查看nagios日志文件

[root@www ~]# ls /var/log/nagios/
archives  nagios.log  objects.cache  retention.dat  spool  status.dat
[root@www ~]# cat /var/log/nagios/nagios.log 
[1449405095] Nagios 3.5.1 starting... (PID=1319)
[1449405095] Local time is Sun Dec 06 20:31:35 CST 2015
[1449405095] LOG VERSION: 2.0
[1449405095] Finished daemonizing... (New PID=1320)
[1449405217] SERVICE ALERT: localhost;HTTP;WARNING;SOFT;1;HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.001 second response time
[1449405277] SERVICE ALERT: localhost;HTTP;WARNING;SOFT;2;HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.001 second response time
[1449405337] SERVICE ALERT: localhost;HTTP;WARNING;SOFT;3;HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.001 second response time
[1449405397] SERVICE ALERT: localhost;HTTP;WARNING;HARD;4;HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.001 second response time
[1449405683] Caught SIGTERM, shutting down...
[1449405683] Successfully shutdown... (PID=1320)
[1449405684] Nagios 3.5.1 starting... (PID=1474)
[1449405684] Local time is Sun Dec 06 20:41:24 CST 2015
[1449405684] LOG VERSION: 2.0
[1449405684] Finished daemonizing... (New PID=1475)
[1449408863] Caught SIGTERM, shutting down...
[1449408863] Successfully shutdown... (PID=1475)
[1449408863] Nagios 3.5.1 starting... (PID=1833)
[1449408863] Local time is Sun Dec 06 21:34:23 CST 2015
[1449408863] LOG VERSION: 2.0
[1449408863] Finished daemonizing... (New PID=1834)
[1449408913] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;SOFT;1;connect to address 192.168.1.251 and port 80: Connection refused
[1449409033] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;SOFT;2;connect to address 192.168.1.251 and port 80: Connection refused
[1449409153] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;SOFT;3;connect to address 192.168.1.251 and port 80: Connection refused
[1449409273] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;SOFT;4;connect to address 192.168.1.251 and port 80: Connection refused
[1449409393] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;HARD;5;connect to address 192.168.1.251 and port 80: Connection refused
[1449409393] SERVICE NOTIFICATION: nagiosadmin;192.168.1.251;check_http;CRITICAL;notify-service-by-email;connect to address 192.168.1.251 and port 80: Connection refused
[1449410874] Caught SIGTERM, shutting down...
[1449410874] Successfully shutdown... (PID=1834)
[1449410874] Nagios 3.5.1 starting... (PID=2330)
[1449410874] Local time is Sun Dec 06 22:07:54 CST 2015
[1449410874] LOG VERSION: 2.0
[1449410874] Finished daemonizing... (New PID=2331)
[1449411134] SERVICE ALERT: 192.168.1.251;check_http;OK;HARD;5;HTTP OK: HTTP/1.1 200 OK - 3910 bytes in 0.001 second response time
[1449411134] SERVICE NOTIFICATION: nagiosadmin;192.168.1.251;check_http;OK;notify-service-by-email;HTTP OK: HTTP/1.1 200 OK - 3910 bytes in 0.001 second response time
[1449411714] Caught SIGTERM, shutting down...
[1449411714] Successfully shutdown... (PID=2331)
[1449411714] Nagios 3.5.1 starting... (PID=2614)
[1449411714] Local time is Sun Dec 06 22:21:54 CST 2015
[1449411714] LOG VERSION: 2.0
[1449411714] Finished daemonizing... (New PID=2615)

九、Nagios配置郵件警告

1、增加define contact和define contactgroup配置

[root@www ~]# vim /etc/nagios/objects/contacts.cfg 

# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin
        }

# add mail addressee
define contact{
        contact_name               admin
        use                             generic-contact
        alias                           administrator
        email              741616710@qq.com
        }

define contact{
        contact_name               ming
        use                             generic-contact
        alias                            HM
        email              root@huangmingming.cn
        }

define contactgroup{
        contactgroup_name          common
        alias                            common
        members                          admin,ming
        }

2、修改define service,增加相應配置

[root@www ~]# vim /etc/nagios/conf.d/192.168.1.251.cfg

    define service{

        use           generic-service

        host_name        192.168.1.251

        service_description   check_http

        check_command      check_http

        max_check_attempts    5

        normal_check_interval  1

        contact_groups     common

        notifications_enabled  1

        notification_period  24x7

        notification_options w,u,c,r

    }

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

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

網(wǎng)站標題:【Nagios】Linux監(jiān)控軟件安裝與配置(二)-創(chuàng)新互聯(lián)
網(wǎng)頁地址:http://muchs.cn/article14/hidde.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供服務器托管、動態(tài)網(wǎng)站、品牌網(wǎng)站制作、全網(wǎng)營銷推廣面包屑導航、域名注冊

廣告

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

h5響應式網(wǎng)站建設