nagios的安裝及配置方法

這篇文章主要介紹“nagios的安裝及配置方法”,在日常操作中,相信很多人在nagios的安裝及配置方法問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”nagios的安裝及配置方法”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

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

一、服務(wù)端安裝(主要監(jiān)控磁盤(pán)或系統(tǒng)負(fù)載,可以自定義腳本,不能查看歷史數(shù)據(jù))

1、配置好擴(kuò)展源并安裝

yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

2、設(shè)置登錄nagios后臺(tái)的用戶和密碼:

htpasswd -c /etc/nagios/passwd nagiosadmin

3、編輯配置文件

vim /etc/nagios/nagios.cfg

nagios -v /etc/nagios/nagios.cfg #檢測(cè)配置文件

4、啟動(dòng)服務(wù)

啟動(dòng)服務(wù):service httpd start; service nagios start

5、瀏覽器訪問(wèn): http://10.10.13.239/nagios

nagios管理員賬號(hào):nagiosadmin密碼:abc.123

二、客戶端安裝

1、配置好擴(kuò)展源后安裝

yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe 

2、編輯配置文件

vim /etc/nagios/nrpe.cfg  找到“allowed_hosts=127.0.0.1” 改為 “allowed_hosts=127.0.0.1,10.10.13.239” 后面的ip為服務(wù)端ip; 找到” dont_blame_nrpe=0” 改為  “dont_blame_nrpe=1” 
啟動(dòng)客戶端 /etc/init.d/nrpe start

3、服務(wù)端添加配置文件

cd /etc/nagios/conf.d/

vim 10.10.13.247.cfg

define host{

        use                     linux-server

        host_name                 10.10.13.247

        alias                       13.247

        address                  10.10.13.247

        }

define service{

        use                     generic-service

        host_name                 10.10.13.247

        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                 10.10.13.247

        service_description          check_ssh

        check_command              check_ssh

        max_check_attempts           5    #當(dāng)nagios檢測(cè)到問(wèn)題時(shí),一共嘗試檢測(cè)5次都有問(wèn)題才會(huì)告警,如果該數(shù)值為1,那么檢測(cè)到問(wèn)題立即告警

        normal_check_interval         1    #重新檢測(cè)的時(shí)間間隔,單位是分鐘,默認(rèn)是3分鐘

        notification_interval         60    #在服務(wù)出現(xiàn)異常后,故障一直沒(méi)有解決,nagios再次對(duì)使用者發(fā)出通知的時(shí)間。單位是分鐘。如果你認(rèn)為,>所有的事件只需要一次通知就夠了,可以把這里的選項(xiàng)設(shè)為0。

}

define service{

        use                     generic-service

        host_name                 10.10.13.247

        service_description          check_http

        check_command              check_http

        max_check_attempts           5

        normal_check_interval         1

}

#配置完檢測(cè)是否有錯(cuò)

nagios -v /etc/nagios/nagios.cfg

4、客戶端上重啟一下nrpe服務(wù): service nrpe restart
服務(wù)端也重啟一下nagios服務(wù): service nagios restart

5、 刷新地址http://10.10.13.239/nagios看host和services已經(jīng)添加了相關(guān)項(xiàng)目

三、監(jiān)控客戶端的本地資源(需要借助于nrpe服務(wù))

1、服務(wù)端vim /etc/nagios/objects/commands.cfg
增加:define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
2、繼續(xù)編輯 vim /etc/nagios/conf.d/10.10.13.247.cfg 
增加如下內(nèi)容:define service{
        use     generic-service
        host_name       10.10.13.247
        service_description     check_load
        check_command           check_nrpe!check_load #可以在客戶端/etc/nagios/nrpe.cfg里面找到check_load腳本路徑
        max_check_attempts 5
        normal_check_interval 1
}


define service{
        use     generic-service
        host_name       10.10.13.247
        service_description     check_disk_sda1
        check_command           check_nrpe!check_hda1#可以在客戶端/etc/nagios/nrpe.cfg里面找到check_hda1腳本路徑
        max_check_attempts 5
        normal_check_interval 1
}

3、修改客戶端的nrpe配置文件

vim /etc/nagios/nrpe.cfg 

修改command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1

改為command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1

4、重啟服務(wù)端的nagios和nrpe服務(wù)重啟客戶端的nrpe服務(wù)

[root@server ~]# /etc/init.d/nagios restart

[root@server ~]# /etc/init.d/nrpe restart

[root@client ~]# /etc/init.d/nrpe restart

5、刷新地址http://10.10.13.239/nagios看services已經(jīng)添加了一負(fù)載和硬盤(pán)使用量的監(jiān)控

四、添加郵件告警功能

1、編輯配置文件

vim /etc/nagios/objects/contacts.cfg

添加

define contact{                                          #定義成員123
        contact_name               123
        use                             generic-contact
        alias                           river
        email             313841662@qq.com
        }


define contact{
        contact_name               456               #定義成員456
        use                             generic-contact
        alias                            aaa
        email             313841662@qq.com
        }


define contactgroup{                                 #定義組,組成員為123,456
        contactgroup_name           common
        alias                                  common
        members                          123,456
        }

2、然后在要需要告警的服務(wù)里面加上contactgroup

vim /etc/nagios/conf.d/10.10.13.247.cfg

define service{
        use     generic-service
        host_name       10.10.13.247
        service_description     check_load
        check_command           check_nrpe!check_load
        max_check_attempts 5
        normal_check_interval 1
        contact_groups        common
        notifications_enabled  1                 ;是否開(kāi)啟提醒功能。1為開(kāi)啟,0為禁用。一般,這個(gè)選項(xiàng)會(huì)在主配置文件(nagios.cfg)中定義,效果相同。
        notification_period   24x7              ;發(fā)送提醒的時(shí)間段。非常重要的主機(jī)(服務(wù))我定義為7×24,一般的主機(jī)(服務(wù))就定義為上班時(shí)間。如果不在定義的時(shí)間段內(nèi),無(wú)論什么問(wèn)題發(fā)生,都不會(huì)發(fā)送提醒。(時(shí)間格式為24x7不是24*7,如果寫(xiě)成后者就會(huì)報(bào)錯(cuò))        
        notification_options w,u,c,r            ;這個(gè)是service的狀態(tài)。w為waning, u為unknown, c為critical, r為recover(恢復(fù)了),f為flapping,n為不發(fā)送提醒。類(lèi)似的還有一個(gè)  host對(duì)應(yīng)的狀態(tài):d,u,r   d = 狀態(tài)為DOWN, u = 狀態(tài)為UNREACHABLE , r = 狀態(tài)恢復(fù)為OK,需要加入到host的定義配置里。(這一選項(xiàng)后面不能跟冒號(hào)跟冒號(hào)就會(huì)報(bào)錯(cuò),必須為空格)
}

#具體告警格式可以百度nagios 郵件告警

五、利用sendmail發(fā)送告警郵件

1.軟件檢測(cè)及安裝

#rpm -q sendmail

若不存在則安裝

#yum -y install sendmail

2.停止sendmail服務(wù)

這里不需要sendmail作為郵件服務(wù)端來(lái)運(yùn)行,所以關(guān)閉sendmail服務(wù)。

#service sendmail stop

3.配置sendmail服務(wù)

配置發(fā)送郵件的郵箱認(rèn)證信息

vi /etc/mail.rc 

添加如下內(nèi)容:

set from=chenconghe@benco.com.cn

set smtp=mail.benco.com.cn

set smtp-auth-user=chenconghe

set smtp-auth-password=20160427150456

set smtp-auth=login

4.測(cè)試發(fā)送郵件功能

格式:echo "郵件內(nèi)容" | mail -s "郵件標(biāo)題" 目標(biāo)郵件地址

echo "hello word" | mail -s "mail title" 313841662@qq.com

5.配置nagios郵件發(fā)送命令

修改nagios命令配置文件

#vim /etc/nagios/objects/commands.cfg

#notify-host-by-email命令的定義 

define command{

        #命令名稱(chēng),即定義了一個(gè)主機(jī)異常時(shí)發(fā)送郵件的命令。

        command_name    notify-host-by-email

        #命令具體的執(zhí)行方式。

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\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命令的定義 

define command{

        #命令名稱(chēng),即定義了一個(gè)服務(wù)異常時(shí)發(fā)送郵件的命令

        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\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

       }

6、接著修改nagios中定義的主機(jī)和服務(wù)的報(bào)警機(jī)制,實(shí)現(xiàn)nagios利用郵件自動(dòng)報(bào)警。 

vim /etc/nagios/conf.d/10.10.13.238.cfg

define service{

        use     generic-service

        host_name       10.10.13.247

        service_description     notify-service-by-email

        check_command           notify-service-by-email

        max_check_attempts 5

        normal_check_interval 1

        notification_period 24x7

        contact_groups common

        notifications_enabled  1

        notification_options w,u,c,r

}

define service{

        use     generic-service

        host_name       10.10.13.247

        service_description     notify-host-by-email

        check_command           notify-host-by-email

        max_check_attempts 5

        normal_check_interval 1

        contact_groups common

        notifications_enabled  1

        notification_period 24x7

        notification_options w,u,c,r

}

#當(dāng)重啟服務(wù)時(shí)出現(xiàn)以下錯(cuò)誤:

Warning: Duplicate definition found for command 'notify-host-by-email' (config file '/etc/nagios/objects/commands.cfg', starting on line 244)

Error: Could not add object property in file '/etc/nagios/objects/commands.cfg' on line 245.

有可能是因?yàn)閺?fù)制粘貼的時(shí)候復(fù)制了兩次,注意檢查配置文件

7、測(cè)試

將10.10.13.247關(guān)掉,QQ郵箱收到一封報(bào)警信,測(cè)試成功。

#當(dāng)重啟客戶端的時(shí)候有可能在Nagios的監(jiān)控頁(yè)面上有關(guān)需要nrpe輔助的項(xiàng)目會(huì)顯示出錯(cuò),需要重新檢查客戶端nrpe配置文件allowed_hosts和dont_blame_nrpe是否需要修改。突然斷電等可能導(dǎo)致配置信息丟失需要重新檢查


測(cè)試自動(dòng)發(fā)送郵件參考此文章:http://4709096.blog.51cto.com/4699096/1703980

參考: 
調(diào)用短信接口   http://www.aminglinux.com/bbs/thread-7380-1-1.html
整合微信  http://www.aminglinux.com/bbs/thread-7917-1-1.html

到此,關(guān)于“nagios的安裝及配置方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

新聞名稱(chēng):nagios的安裝及配置方法
當(dāng)前鏈接:http://muchs.cn/article14/pieoge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)網(wǎng)站內(nèi)鏈、網(wǎng)站設(shè)計(jì)、定制網(wǎng)站、軟件開(kāi)發(fā)

廣告

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

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司