日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nagios 监控平台搭建

發(fā)布時間:2025/3/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nagios 监控平台搭建 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

nagios搭建配置

一、需要的軟件包

1、nagios-3.2.3.tar.gz ?nagios主監(jiān)控包

tar -zxvf nagios-3.2.3.tar.gz

cd nagios-3.2.3

./configure --prefix=/usr/local/nagios

make all

make install

命令對主程序,cgi及html進行安裝

make install-init

命令在/etc/rc.d/init.d/目錄中安裝啟動腳本

make install-commandmode

命令來安裝和配置外部命令對Nagios主路徑操作的權限。(這里所謂的外部命令主要是指Apache服務通過CGI來對

Nagios的進行的操作。用戶將通過Web以執(zhí)行CGI程序腳本的方式來對Nagios的檢測結果進行讀取和調用。)

make install-config

命令在/usr/local/nagios/etc/下安裝nagios配置文件示例模版

chkconfig --add nagios on 開機啟動nagios

chkconfig --level 35 nagios on

useradd nagios

創(chuàng)建nagios用戶

chown -R ?nagios.nagios /usr/local/nagios

權限設置

nagios-plugins-1.4.15.tar.gz 監(jiān)控插件

2、tar -zxvf nagios-plugins-1.4.15.tar.gz

cd nagios-plugins-1.4.15

./configure --prefix=/usr/local/nagios

make && make install

nagios-cn-3.2.3.tar.bz2 ?漢化包

tar -jxvf nagios-cn-3.2.3.tar.bz2

cd nagios-cn-3.2.3

./configure

make && make install

3、httpd-2.2.14.tar.gz 安裝apache

tar -zxvf httpd-2.2.14.tar.gz

cd httpd-2.2.14

./configure --prefix=/usr/local/apache

make

make install

4、php-5.4.0.tar.gz 安裝php

tar -zxvf php-5.4.0.tar.gz

cd php-5.4.0

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/aache/bin/apxs(apache可以調用php)

make

make install

二、修改apache配置文件

1、修改:

User ?nagios

Group nagios

修改為:

DirectoryIndex index.html index.php

增加:

AddType application/x-httpd-php .php

設置apache授權訪問在配置文件最后添加:

#setting for nagios

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">

AuthType ? Basic

Options ? ?ExecCGI

AllowOverride AuthConfig

Order allow,deny

Allow from all

AuthName "Welcome to user nagios"

AuthUserFile ?/usr/local/apache/conf/htpasswd

Require ?valid-user

</Directory>


Alias /nagios ?"/usr/local/nagios/share"

<Directory ?"/usr/local/nagios/share">

AuthType ? Basic

Options ? ?ExecCGI

AllowOverride AuthConfig

Order allow,deny

Allow from all

AuthName "Welcome to user nagios"

AuthUserFile ?/usr/local/apache/conf/htpasswd

Require ?valid-user

</Directory>


2、創(chuàng)建驗證文件

/usr/local/apache/bin/htasswd -c /usr/local/apache/conf/htpasswd nagiosadmin

注意-c 為創(chuàng)建文件用,nagiosadmin為所創(chuàng)建的用戶,下次使用該命令創(chuàng)建用戶,不能用-c這樣會覆蓋之前的用戶

chown -R nagios.nagios /usr/local/apache

權限設置,不然驗證不通過

啟動nagios:

service nagios start

啟動apache

/usr/local/apache/bin/httpd -k start

瀏覽器訪問 http://ip/nagios/ 要求輸入用戶名密碼,顯示nagios監(jiān)控界面恭喜你基本安裝成功

三、nagios 配置文件分析

1、/usr/local/nagios/nagios/etc/nagios.cfg ?nagios的主配置文件

cfg_file=/usr/local/nagios/etc/objects/commands.cfg ? ? ? 定義nagios命令的配置文件

cfg_file=/usr/local/nagios/etc/objects/contacts.cfg ? ? ? 定義聯(lián)系人、聯(lián)系人組模版的配置文件

cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg ? ?定義時間段的模版配置文件

cfg_file=/usr/local/nagios/etc/objects/templates.cfg ? ? ?定義主機和服務的一個模版配置文件

cfg_file=/usr/local/nagios/etc/objects/windows.cfg ? ? ? ?定義windons主機的模版配置文件

cfg_dir=/usr/local/nagios/etc/nagiosconf在主配置文件中可以通過這條命令指定,nagios配置文件目錄nagiosconf這

個目錄可以按類型嵌套目錄,nagios執(zhí)行中尋找這個目錄中后綴為.cfg的所有文件


2、cgi.cfg 控制CGI訪問的配置文件

use_authentication=1

設定啟用身份驗證。

authorized_for_system_information=nagiosadmin

設定系統(tǒng)信息的授權用戶。

authorized_for_configuration_information=nagiosadmin

設定配置信息的授權用戶。

authorized_for_system_commands=nagiosadmin

設定系統(tǒng)命令的授權用戶。

authorized_for_all_services=nagiosadmin

設定全部監(jiān)測服務的授權用戶。

authorized_for_all_hosts=nagiosadmin

設定全部被監(jiān)測主機的授權用戶。

authorized_for_all_service_commands=nagiosadmin

設定全部監(jiān)測服務命令的授權用戶。

authorized_for_all_host_commands=nagiosadmin

設定全部主機命令的授權用戶。

3、resource.cfg ?資源文件,主要是定義命令所在地,以便其他配置文件引用


3、object目錄,存放很多模版配置文件,被其他配置文件引用

nagios中的配置文件是這樣一個邏輯應用結構:

當一個任務被觸發(fā)要有這樣的工作,任務可以是主機或服務,這個任務什么時候被檢查(需要timeperiods.cfg模版定義),

檢查這個任務的命令是什么(需要commands.cfg模版定義),報警什么時候發(fā)送(由timeperiods.cfg模版定義),聯(lián)系人是

誰(由contact.cfg模版定義)

templates.cfg 文件分析

define contact{

? ? ? ?name ? ? ? ? ? ? ? ? ? ? ? ? ? ?generic-contact ? ? ? name用來定義一個類名,應為這是個difine contact段所以這是個聯(lián)系人類名,可被contact引用引用 ? ?

? ? ? ?service_notification_period ? ? 24x7 ? ? ? ? ? ? ? ? ?服務故障通知時間

? ? ? ?host_notification_period ? ? ? ?24x7 ? ? ? ? ? ? ? ? ?主句故障通知時間

? ? ? ?service_notification_options ? ?w,u,c,r,f,s ? ? ? ? ? 服務報警觸發(fā)參數(shù)

? ? ? ?host_notification_options ? ? ? d,u,r,f,s ? ? ? ? ? ? 主機報警觸發(fā)參數(shù)

? ? ? ?service_notification_commands ? notify-service-by-email ? 服務報警通知方式

? ? ? ?host_notification_commands ? ? ?notify-host-by-email ? ? ?主機報警通知方式

? ? ? ?register ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? ?用來說明它是個類

? ? ? ?}

看這個配置文件“24x7”這是一個時間段名,是在timeeriods.cfg 定義。 ?notify-host-by-email命令是在commadns.cfg定義,涉及到了模版配置文件的引用

define host{

? ? ? ?name ? ? ? ? ? ? ? ? ? ? ? ? ? ?generic-host ? ? ? ? 命名一個主機類 generic-host可被應用

? ? ? ?notifications_enabled ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ?設定啟用主機事件通知

? ? ? ?event_handler_enabled ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ?設定啟用主機事件處理程

flap_detection_enabled ? ? ? ? ?1 ? ? ? ? ? ? ? ? ? ?設定啟用狀態(tài)抖動監(jiān)測

? ? ? ?failure_prediction_enabled ? ? ?1 ? ? ? ? ? ? ? ? ? ?設定啟用故障預測

? ? ? ?process_perf_data ? ? ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ?設定啟用進程性能數(shù)據(jù)記錄

? ? ? ?retain_status_information ? ? ? 1 ? ? ? ? ? ? ? ? ? ?設定啟用狀態(tài)信息保存功能

? ? ? ?retain_nonstatus_information ? ?1 ? ? ? ? ? ? ? ? ? ?設定啟用非狀態(tài)信息保存功能

? ? ? ?notification_period ? ? ? ? ? ? 24x7 ? ? ? ? ? ? ? ? 設定事件通知的工作時間段

? ? ? ?register ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ?

? ? ? ?}

define host{

? ? ? ?name ? ? ? ? ? ? ? ? ? ? ? ? ? ?linux-server ? ? ? ? 定義了一個linux主機類

? ? ? ?use ? ? ? ? ? ? ? ? ? ? ? ? ? ? generic-host ? ? ? ? 通過use引用之前定義過的類

? ? ? ?check_period ? ? ? ? ? ? ? ? ? ?24x7 ? ? ? ? ? ? ? ? 服務的檢查時間

? ? ? ?check_interval ? ? ? ? ? ? ? ? ?5 ? ? ? ? ? ? ? ? ? ?檢查間隔5分

? ? ? ?retry_interval ? ? ? ? ? ? ? ? ?1 ? ? ? ? ? ? ? ? ? ?主機失敗檢查重試時間間隔

? ? ? ?max_check_attempts ? ? ? ? ? ? ?10 ? ? ? ? ? ? ? ? ? 主機失敗最大重檢次數(shù)

? ? ? ?check_command ? ? ? ? ? ? ? ? ? check-host-alive ? ? 檢查命令在commands.cfg中定義

? ? ? ?notification_period ? ? ? ? ? ? workhours ? ? ? ? ? ?發(fā)送報警的時間



? ? ? ?notification_interval ? ? ? ? ? 120 ? ? ? ? ? ? ? ? ?主機未回復重發(fā)報警的時間間隔120分

? ? ? ?notification_options ? ? ? ? ? ?d,u,r ? ? ? ? ? ? ? ?觸發(fā)參數(shù)

? ? ? ?contact_groups ? ? ? ? ? ? ? ? ?admins ? ? ? ? ? ? ? 聯(lián)系人

? ? ? ?register ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ?類

? ? ? ?}

define service{

? ? ? ?name ? ? ? ? ? ? ? ? ? ? ? ? ? ?generic-service ? ? ? ?

? ? ? ?active_checks_enabled ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?passive_checks_enabled ? ? ? ? ?1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?parallelize_check ? ? ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?obsess_over_service ? ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?check_freshness ? ? ? ? ? ? ? ? 0 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?notifications_enabled ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?event_handler_enabled ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?flap_detection_enabled ? ? ? ? ?1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?failure_prediction_enabled ? ? ?1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?process_perf_data ? ? ? ? ? ? ? 1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?retain_status_information ? ? ? 1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?retain_nonstatus_information ? ?1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?is_volatile ? ? ? ? ? ? ? ? ? ? 0 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?check_period ? ? ? ? ? ? ? ? ? ?24x7 ? ? ? ? ? ? ? ? ? ?

? ? ? ?max_check_attempts ? ? ? ? ? ? ?3 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?normal_check_interval ? ? ? ? ? 10 ? ? ? ? ? ? ? ? ? ?

? ? ? ?retry_check_interval ? ? ? ? ? ?2 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?contact_groups ? ? ? ? ? ? ? ? ?admins ? ? ? ? ? ? ? ? ?

? ? ? ?notification_options ? ? ? ? ? ?w,u,c,r ? ? ? ? ? ? ? ?

? ? ? ?notification_interval ? ? ? ? ? 60 ? ? ? ? ? ? ? ? ? ?

? ? ? ?notification_period ? ? ? ? ? ? 24x7 ? ? ? ? ? ? ? ? ? ?

? ? ? ? register ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ?

? ? ? ?}


此為定義一個服務基本類,就是說基本上服務檢查需要指定的內(nèi)容,若有特殊需要可以在此基礎上引用重定義,如下工作,一個監(jiān)測工

作就是一個服務。服務定義段就是要定義Nagios將進行什么樣的監(jiān)測工作的配置段。而且服務當中也能夠定義服務的類,并且類也能繼承類,

運用比較靈活。


define service{

? ? ? ?name ? ? ? ? ? ? ? ? ? ? ? ? ? ?local-service ? ? ? ? ?

? ? ? ?use ? ? ? ? ? ? ? ? ? ? ? ? ? ? generic-service ? ? ? 通過use引用generic-service類 ?

? ? ? ?max_check_attempts ? ? ? ? ? ? ?4 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?normal_check_interval ? ? ? ? ? 5 ? ? ? ? ? ? ? ? ? ?重定義后覆蓋generic-service 中的定義 ? ? ? ? ? ? ? ?

? ? ? ?retry_check_interval ? ? ? ? ? ?1 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?register ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?}

這里的服務并不是指被監(jiān)測主機上運行的服務,而是指Nagios所進行的“各種不同功能的監(jiān)測


contact.cfg文件分析


define contact{

? ? ? ?contact_name ? ? ? ? ? ? ? ? ? ?nagiosadmin ? ? ? ? ? 定義一個聯(lián)系人 ? ? ? ?

? ? ? ?use ? ? ? ? ? ? ? ? ? ? ? ? ? ? generic-contact ? ? ? 引用templates.cfg模版中的generic-contact類 ?

? ? ? ?alias ? ? ? ? ? ? ? ? ? ? ? ? ? Nagios Admin ? ? ? ? ?聯(lián)系人描述

? ? ? ?email ? ? ? ? ? ? ? ? ? ? ? ? ? nagios@localhost ? ? ?聯(lián)系人郵件地址

? ? ? ?}

define contactgroup{

? ? ? ?contactgroup_name ? ? ? admins ? ? ? ? ? ? ? ? ? ? ? ?定義一個聯(lián)系人組

? ? ? ?alias ? ? ? ? ? ? ? ? ? Nagios Administrators ? ? ? ? 描述

? ? ? ?members ? ? ? ? ? ? ? ? nagiosadmin ? ? ? ? ? ? ? ? ? 組成員,組成員必須是define contact{}段定義的,成員之間用逗號隔開


? ? ? }


timeperiods.cfg 文件分析


define timeperiod{

? ? ? ?timeperiod_name 24x7 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?timeperiod_name 定義時間段名,這個時間段名可被引用

? ? ? ?alias ? ? ? ? ? 24 Hours A Day, 7 Days A Week ? ? ? ? 時間段描述

? ? ? ?sunday ? ? ? ? ?00:00-24:00 ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ?monday ? ? ? ? ?00:00-24:00

? ? ? ?tuesday ? ? ? ? 00:00-24:00

? ? ? ?wednesday ? ? ? 00:00-24:00

? ? ? ?thursday ? ? ? ?00:00-24:00

? ? ? ?friday ? ? ? ? ?00:00-24:00

? ? ? ?saturday ? ? ? ?00:00-24:00

? ? ? ?}



# 'workhours' timeperiod definition

define timeperiod{

? ? ? ?timeperiod_name workhours

? ? ? ?alias ? ? ? ? ? Normal Work Hours

? ? ? ?monday ? ? ? ? ?09:00-17:00

? ? ? ?tuesday ? ? ? ? 09:00-17:00

? ? ? ?wednesday ? ? ? 09:00-17:00

? ? ? ?thursday ? ? ? ?09:00-17:00

? ? ? ?friday ? ? ? ? ?09:00-17:00

? ? ? ?}


commamnds.cfg 文件分析

define command{

? ? ? ?command_name ? ?notify-host-by-email

? ? ? ?command_line ? ?/usr/bin/printf "%b" "***** Nagios *****\n\nNotificationType: $NOTIFICATIONTYPE$\nHost:

$HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time:

$LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

? ? ? ?}

define command{

? ? ? ?command_name ? ?check-host-alive

? ? ? ?command_line ? ?$USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5

? ? ? ?}

通過define關鍵字command來表示一個命令定義段,定義內(nèi)用在兩個大括號內(nèi),并且一個屬性必須占一行。如果要定義多個命令的話要寫多個

define command {}段

commnad_name ?來命令一個命令名,在服務的定義當中,只能引用在commands.cfg中定義過的命令名

通過command_line來定義該命令的所使用到的插件程序以及參數(shù)配置格式,也可使用系統(tǒng)程序或自己安裝的程序,

如notify-host-by-email

命令的定義它通過command_line 調用了/usr/bin/printf;、/bin/mial 命令,后面是它們的參數(shù)

如check-host-alive

命令的定義它通過command_line 調用了$USER1$下的check_ping 命令,而$USER1$其實是個目錄在resource.cfg配置文件中定義了nagios的

資源在哪里,


resource.cfg配置文件:

$USER1$=/usr/local/nagios/libexec


localhost.cfg 具體應用實例配置分析

define host{

? ? ? ?use ? ? ? ? ? ? ? ? ? ? linux-server ? ? ? ?引用linux-server類 ? ? ? ? ?



? ? ? ?host_name ? ? ? ? ? ? ? localhost ? ? ? ? ? 被監(jiān)控主機名,報警時會提示,根據(jù)業(yè)務定

? ? ? ?alias ? ? ? ? ? ? ? ? ? localhost ? ? ? ? ? 描述主機應用

? ? ? ?address ? ? ? ? ? ? ? ? 127.0.0.1 ? ? ? ? ? 主機ip

? ? ? ?}

define hostgroup{

? ? ? ?hostgroup_name ?linux-servers

? ? ? ?alias ? ? ? ? ? Linux Servers

? ? ? ?members ? ? ? ? localhost ? ?

? ? ? ?}


define service{

? ? ? ?use ? ? ? ? ? ? ? ? ? ? ? ? ? ? local-service ? ? 引用locak-server類 ? ?

? ? ? ?host_name ? ? ? ? ? ? ? ? ? ? ? localhost ? ? ? ?

? ? ? ?service_description ? ? ? ? ? ? Root Partition

? ? ? ?check_command ? ? ? ? ? ? ? ? ? check_local_disk!20%!10%!/

? ? ? ?}

重點說check_command ? ? ?check_local_disk!20%!10%!/

在命令配置文件中check_local_disk命令的command_line行是這樣

command_line ? $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$

對比之下我們知道check_local_disk 就相當于$USER1$/check_disk -w ?-c ?-p 那么

20%這個參數(shù)就是$ARG1$的實際值

10%這個參數(shù)就是$ARG2$的實際值

/這個參數(shù)就是$ARG3$的實際值

多個參數(shù)之間用!!隔開

至于check_disk 這個命令的用法可以執(zhí)行check_disk --help 來查看,其他命令也一樣,舉例來說:

check_local_disk!20%!10%!/

-p選項指定要監(jiān)控的分區(qū)為/

-w選項觸發(fā)warn報警當/空間小于20%

-c選項觸發(fā)crit報警當/空間小于10%


配置文件終于說完了,不知是否啰嗦了,我覺得啰嗦點沒關系如果大家能更好的理解,說的不對的地方大家指正這里先謝謝了!


四、nrpe包的安裝

1、nagios監(jiān)控主程序可以理解為一個監(jiān)控平臺,Nagios監(jiān)測服務只能是本地系統(tǒng)監(jiān)測以及對遠程主機的連通性監(jiān)測。為了使Nagios

的監(jiān)測服務器能夠遠程對被監(jiān)測主機系統(tǒng)上的信息進行獲取,比如遠程系統(tǒng)上的進程數(shù)、磁盤空間使用狀況、所運行的服務等等

這些必須要登錄遠程主機系統(tǒng)上才能了解的信息的話,就必須要依靠NRPE這個核心擴展插件程序,NRPE作為中間的代理程序,扮

演著一手接受著Nagios監(jiān)測服務器發(fā)來的請求,另一手在遠程主機系統(tǒng)上獲取指定的信息的中間人角色。

如以上提到的實現(xiàn)Nagios對遠程系統(tǒng)的監(jiān)測,那么首先必須要在被監(jiān)測的遠程主機上除了安裝Nagios-plugins插件程序之外還

必須安裝 NRPE核心擴展插件程序,并將NRPE在被監(jiān)測的遠程主機系統(tǒng)上以守護進程的方式運行起來,開放指定的NRPE監(jiān)聽端口

監(jiān)聽著Nagios監(jiān)測服務器發(fā)送過來的所有監(jiān)測請求。另外,在Nagios監(jiān)測服務器上,在必須要安裝Nagios-plugins插件程序和

NRPE核心擴展插件程序。唯一不同的是,Nagios監(jiān)測服務器不需要將NRPE作為守護進程運行著,因為它本身一般不需要被別人

監(jiān)測著而是去監(jiān)測別人,對Nagios監(jiān)測服務器而言,它只需要使用到Nagio-plugins插件程序和NRPE擴展插件程序就足夠了。

在被監(jiān)控主機上安裝Nagios-plugins插件程序

首先要添加用戶useradd nagios 這是必須的

tar -zxvf nagios-plugins-1.4.15.tar.gz

cd nagios-plugins-1.4.15

./configure --prefix=/usr/local/nagios

make && make install

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

安裝nrpe包

tar -zxvf nrpe-2.13.tar.gz

cd nrpe-2.13

./configure

make all

make install-plugin ?安裝nrpe插件程序

make isntall-daemon ?安裝nrpe守護程序

make install-daemon-config ?安裝nrpe守護進程配置文件


2、vi /usr/local/nagios/etc/nrpe.cfg

pid_file=/var/run/nrpe.pid

設定NRPE運行的PID文件,這個默認就設定好了,不用更改。

server_port=5666

這個是NRPE守護進程占用的系統(tǒng)端口。

#server_address=0.0.0.0

server_address=192.168.1.9

設定系統(tǒng)監(jiān)聽NRPE的網(wǎng)絡接口。一般設定具體的IP地址,如果要多個網(wǎng)卡的話就用逗號“,”來分隔多個IP地址。如果要監(jiān)聽系統(tǒng)

全部的網(wǎng)絡接口的話,可以使用“0.0.0.0”這個表示全部網(wǎng)絡接口的特殊地址,但是不可以用通配符“*”。

nrpe_user=nagios

nrpe_group=nagios

設定NRPE的宿主用戶。

allowed_hosts=192.168.1.12

這里是設定允許與本機進行NRPE交互的主機的IP地址,也就是Nagios監(jiān)測服務器的地址,如果要指定多個Nagios服務器的話,那么用逗號“,”來分隔多個IP地址。


command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

以上是NRPE默認就有的擴展插件命令,這是至關重要的地方了。當被監(jiān)測主機運行NRPE守護進程的時候,同時就運行起來了這些在NRPE配置文件中定義的NRPE

擴展命令了。可以看出這些擴展命令都已經(jīng)指定了好了命令名、插件路徑以及選項參數(shù)了。格式如下:


? ? ? ? ?command[NRPE命令名]=插件路徑/插件 選項1 參數(shù)1 選項2 參數(shù)2 ...


注意,如果要指定該被監(jiān)測主機需要被監(jiān)控的服務的話,就必須在這里都配置好NRPE命令并運行在NRPE守護進程里。這里沒有配置的NRPE命令則Nagios監(jiān)測服

務器是無法監(jiān)控到的。


3、了解NRPE的執(zhí)行程序的使用方式

/usr/local/nagios/bin/nrpe -h

-------------------------------------------------------

Usage: nrpe [-n] -c <config_file> <mode>

運行方法:nrpe -c NRPE配置文件路徑 運行模式


Options:

可用選項


? ?-n ? ? ? ? ? = Do not use SSL

? ?不使用SSL方式,一般都使用SSL。


<config_file> = Name of config file to use

? ?指定NRPE配置文件路徑,這個NRPE主配置文件就是nrpe.cfg。


<mode> ? ? ? ? = One of the following two operating modes:

? ?指定NRPE的運行方式,一共有2種可用的NRPE運行方式:


? ?-i ? ? ? ? ? = ? ? Run as a service under inetd or xinetd

? ?以超級守護進程inetd或xinetd方式運行NRPE,要通過這種方式運行的話還要安裝和配置xinetd,一般不用。


? ?-d ? ? ? ? ? = ? ? Run as a standalone daemon

? ?以獨立守護進程方式運行NRPE,一般常用這種運行方式。


4、運行NRPE守護進程

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

-c 指定配置文件

-d 以獨立守護進程方式運行nrpe

檢查是否啟動

ps aux | grep nrpe

netstat -anlp | grep nrpe

5、將NRPE運行添加加入系統(tǒng)啟動腳本中

echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.d/rc.local

到此,被監(jiān)控主機要做的工作已經(jīng)完成了。


五、在監(jiān)控主機上安裝nrpe程序

tar -zxvf nrpe-2.13.tar.gz

cd nrpe-2.13

./configure

make all

安裝NRPE擴展插件程序

make install-plugin

Nagios只要擁有NRPE的擴展插件功能就可以了,所以在Nagios監(jiān)測服務器安裝NRPE工作到這步就可以了。接下來要

做的就是在Nagios監(jiān)測服務器上配置NRPE的擴展插件命令,使得Nagios監(jiān)測服務器能夠定義nrpe命令,從而可以定

義出“遠程系統(tǒng)監(jiān)測服務”。

在監(jiān)控主機上配置NRPE的服務

1.查看新擴展插件check_nrpe的使用方法

/usr/local/nagios/libexec/check_nrpe -h|less

-------------------------------------------------------

Usage: check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>]

使用方式:check_nrpe -H 主機名 -p NRPE端口 -c NRPE命令名


Options:

選項:


<host> ? ? ?= The address of the host running the NRPE daemon

主機,運行著NRPE守護進程的遠程被監(jiān)測主機名,并且該主機名必須在host里定義過。


[port] ? ? ?= The port on which the daemon is running (default=5666)

端口,被監(jiān)測的遠程主機上運行NRPE的端口,默認是5666,如果是默認就不用指定。


[command] ? = The name of the command that the remote daemon should run

命令,這些命令名必須是被監(jiān)測主機上NRPE守護進程運行著的。

-------------------------------------------------------


2.在command.cfg命令定義文件中添加NRPE命令。

vi /usr/local/nagios/etc/commands.cfg

-------------------------------------------------------

# NRPE Command

添加NRPE功能命令。


define command(

? command_name ? nrpe

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

? }

-------------------------------------------------------

這里要說明幾點:

(1)這里定義的命令名就叫作nrpe。

(2)$USER1$/check_nrpe會通過引用resource.cfg獲得/usr/local/nagios/libexec/check_nrpe這個絕對路徑。

(3)-H $HOSTADDRESS$ 用來獲得指定被監(jiān)測主機的IP地址,$HOSTADDRESS$變量會通過定義主機名查找到host段中的IP地址。

(4)-c $ARG1$ 用來指定被監(jiān)測主機上NRPE守護進程運行著的NRPE命令名。


3.添加NRPE監(jiān)控服務

-------------------------------------------------------

#Define Remote Current Users

定義監(jiān)測遠程系統(tǒng)當前登錄用戶數(shù)量服務。

define service{

? ? ? ? use ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?remote-service

? ? ? ? host_name ? ? ? ? ? ? ? ? ? ? ? ?KCentOS5A

? ? ? ? service_description ? ? ? ? ? ? ?Current Users On Remote System

? ? ? ? check_command ? ? ? ? ? ? ? ? ? ?nrpe!check_users

? ? ? ? }


#Define Remote System Loads

定義監(jiān)測遠程系統(tǒng)當前負載服務。

define service{

? ? ? ? use ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?remote-service

? ? ? ? host_name ? ? ? ? ? ? ? ? ? ? ? ?KCentOS5A

? ? ? ? service_description ? ? ? ? ? ? ?Current System Loads

? ? ? ? check_command ? ? ? ? ? ? ? ? ? ?nrpe!check_load

? ? ? ? }


#Define Remote Zombie Processes

定義監(jiān)測遠程系統(tǒng)僵尸進程數(shù)服務。

define service{

? ? ? ? use ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?remote-service

? ? ? ? host_name ? ? ? ? ? ? ? ? ? ? ? ?KCentOS5A

? ? ? ? service_description ? ? ? ? ? ? ?Zombie Processes On Remote System

? ? ? ? check_command ? ? ? ? ? ? ? ? ? ?nrpe!check_zombie_procs

? ? ? ? }


#Define Remote System Total Processes

定義監(jiān)測遠程系統(tǒng)進程總數(shù)服務。

define service{

? ? ? ? use ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?remote-service

? ? ? ? host_name ? ? ? ? ? ? ? ? ? ? ? ?KCentOS5A

? ? ? ? service_description ? ? ? ? ? ? ?Total Processes On Remote System

? ? ? ? check_command ? ? ? ? ? ? ? ? ? ?nrpe!check_total_procs

? ? ? ? }

-------------------------------------------------------

再強調一遍:

(1)這里check_command后面的nrpe是commands.cfg里定義的命令名。

(2)而nrpe命令名后用感嘆號“!”分隔的是NRPE命令名,這些NRPE命令是在遠端被監(jiān)測主機上nrpe.cfg中command后方括號“[]”

中定義的命令名,并且被遠程NRPE守護進程運行著。


3.在修改配置并確認完畢后,重新啟動Nagios主程序。

service nagios restart

Running configuration check...done

Stopping nagios: done.

Starting nagios: done.

這里特別提醒一點: 如果配置文件當中不小心出現(xiàn)偏差的話,那么Nagios程序將啟動失敗,而且通過service nagios restart

這種方式的話,還可能不會出現(xiàn)配置文件出錯的任何提示信息,即使在日志中也不會記錄,就是單單地告訴你不能啟動,這樣

會給排查錯誤帶來巨大的困擾。如果發(fā)生了配置文件錯誤而導致Nagios啟動失敗的話,那么請不要使用service nagios restart/start

這樣的方式啟動。而是使用命令的方式啟動它:/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg 這個

命令來啟動Nagios主程序,這樣的方式下,如果Nagios配置錯誤的話,它還會提示出錯信息,以方便于故障的排查。



六、定制個性化的NRPE遠程監(jiān)控服務:

默認情況下被檢測主機上的NRPE配置文件nrpe.cfg中只給出了5條NRPE命令名,如下

-------------------------------------------------------

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

-------------------------------------------------------

其實在方括號“[]”里面寫的才是真正的NRPE命令名,而其后的部分則是指定了所使用到的插件路徑以及相應的選項和參數(shù),也就

是說,命令名和其使用到的插件以及相應的選項和參數(shù)是在被監(jiān)測端定義的,而Nagios主監(jiān)測服務器上只要把被監(jiān)控端上定義的

NRPE命令名拿過來再加入到服務定義中就可以了。


比如我要增加兩個遠程監(jiān)測服務,分別是:

(1)監(jiān)測遠程主機上的sda1磁盤空間使用狀況。

(2)監(jiān)測遠程主機上的swap交換分區(qū)使用狀況。


1.首先要找到相應的插件,以及使用方法。

根據(jù)要求,找到check_disk和check_swap這兩個插件。

首先看看check_disk的用法。

/usr/local/nagios/libexec/check_disk -h|less

-------------------------------------------------------

Usage: check_disk -w limit -c limit {-p path | -x device}

格式:check_disk -w 低限% -c 低限% -p 磁盤設備文件或則分區(qū)文件的絕對路徑


Options:

選項


-w, --warning=PERCENT%

? ? 設定告警通知百分比數(shù),空間低于該百分比則發(fā)出告警通知。


-c, --critical=PERCENT%

? ? 設定嚴重告警通知百分比數(shù),空間低于該百分比則發(fā)出嚴重告警通知。


-p, --path=PATH, --partition=PARTITION

? ? 指定磁盤設備文件或則分區(qū)文件的絕對路徑。

-------------------------------------------------------


再來看看check_swap的用法。

/usr/local/nagios/libexec/check_swap -h|less

-------------------------------------------------------

Usage:check_swap [-av] -w <percent_free>% -c <percent_free>%

? ? ? ? ?check_swap -w 剩余空間% -c 剩余空間%


? ? ? ? ?check_swap [-av] -w <bytes_free> -c <bytes_free>

? ? ? ? ?check_swap -w 剩余字節(jié)數(shù) -c 剩余字節(jié)數(shù)


Options:

選項


-w, --warning=INTEGER

? ? 設定告警通知剩余字節(jié)數(shù),剩余字節(jié)低于該值則發(fā)出告警通知,只可整數(shù)。


-w, --warning=PERCENT%%

? ? 設定告警通知百分比數(shù),剩余空間低于該百分比則發(fā)出告警通知,雙百分號。


-c, --critical=INTEGER

? ? 設定嚴重告警通知剩余字節(jié)數(shù),剩余字節(jié)低于該值則發(fā)出嚴重告警通知,只可整數(shù)。


-c, --critical=PERCENT%%

? ? 設定嚴重告警通知百分比數(shù),剩余空間低于該百分比則發(fā)出嚴重告警通知,雙百分號。

-------------------------------------------------------


2、在被監(jiān)控主機上編輯nrpe.cfg配置文件:

vi /usr/local/nagios/etc/nrpe.cfg

-------------------------------------------------------

# Added NRPE Commands

下面兩條是自己添加的NRPE命令名。


command[disk_observer]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda

設定監(jiān)測/dev/sda塊設備文件,空間小于20%產(chǎn)生告警,小于10%產(chǎn)生嚴重告警。


command[swap_observer]=/usr/local/nagios/libexec/check_swap -w 45%% -c 25%%

設定監(jiān)測Swap交換分區(qū),占用率大于55%則產(chǎn)生告警,大于75%則產(chǎn)生嚴重告警。

-------------------------------------------------------


3、重新啟動被監(jiān)控主機的NRPE守護進程:

killall nrpe

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


4、檢查被監(jiān)測主機的NRPE守護進程:

ps aux | grep nrpe

nagios ? ?27504 ? 0.0 ? 0.3 ? 4396 ? 868 ? ? ? Ss 03:35 0:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d


5、在Nagios監(jiān)控服務器上首先確認NRPE的命令定義:

vi /usr/local/nagios/etc/commands.cfg

-------------------------------------------------------

define command{

? ? ? ? command_name nrpe

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

? ? ? ? }

-------------------------------------------------------


6.在Nagios監(jiān)控服務器上然后按照NRPE命令定義來添加NRPE遠程監(jiān)控服務:

vi /usr/local/nagios/etc/localhost.cfg

-------------------------------------------------------

#Define Remote System Disk Using

定義監(jiān)測遠程系統(tǒng)磁盤使用狀況。

define service{

? ? ? ? use ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?remote-service

? ? ? ? host_name ? ? ? ? ? ? ? ? ? ? ? ?KCentOS5A

? ? ? ? service_description ? ? ? ? ? ? ?Disk Using Of Remote System

? ? ? ? check_command ? ? ? ? ? ? ? ? ? ?nrpe!disk_observer

? ? ? ? }


#Define Remote System Swap Using

定義監(jiān)測遠程系統(tǒng)交換分區(qū)使用狀況。

define service{

? ? ? ? use ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?remote-service

? ? ? ? host_name ? ? ? ? ? ? ? ? ? ? ? ?KCentOS5A

? ? ? ? service_description ? ? ? ? ? ? ?Swap Using Of Remote System

? ? ? ? check_command ? ? ? ? ? ? ? ? ? ?nrpe!swap_observer

? ? ? ? }

-------------------------------------------------------

7、重新啟動Nagios監(jiān)測服務器的監(jiān)測程序:

service nagios restart

Running configuration check...done

Stopping nagios: .done.

Starting nagios: done.


8、查看Naigos服務運行狀況:

ps aux | grep nagios

nagios ? ? 7367 ? 0.0 ? 0.3 ? 22888 ? ?904 ? ? ? ? ? Ssl ? 21:24 ? ?0:00 /usr/local/nagios/bin/nagios -d

/usr/local/nagios/etc/nagios.cfg

root ? ? ? 7376 ? 0.0 ? 0.2 ? ?3884 ? ?660 pts/2 ? ? R+ ? ?21:25 ? ?0:00 grep nagios




轉載于:https://blog.51cto.com/buguoruci/1354812

總結

以上是生活随笔為你收集整理的nagios 监控平台搭建的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 烈性摔跤| 视频久久 | 国精产品一区一区三区免费视频 | 国产婷婷色一区二区三区在线 | 黄色一级片a | 午夜福利视频合集1000 | 日韩视频一区二区三区四区 | 黄色片免费看 | 韩日少妇 | 韩国美女福利视频 | 欧美激情精品久久久久久蜜臀 | 欧美黑人疯狂性受xxxxx喷水 | 牛牛av国产一区二区 | 人成精品| 欧美性受xxxxxx黑人xyx性爽 | 永久免费网站直接看 | 欧美久久久影院 | 欧美一区二区国产 | 国产成人午夜视频 | 免费黄网站在线 | 国产鲁鲁| 久草播放| 在线观看免费高清 | 国产精品日本一区二区在线播放 | 国产在线视频卡一卡二 | 中文字幕一区二区三区不卡 | 又黄又爽又色视频 | 国产极品美女高潮无套嗷嗷叫酒店 | 波多野吉衣一区 | 久久九九国产精品 | 亚洲va欧美 | 在线观看日韩 | k8yy毛片| 久久视精品 | 岛国av免费 | 开心激情播播 | 杨幂国产精品一区二区 | 国产精品第72页 | 日韩av电影网址 | 国产极品免费 | 国产精品尤物 | 欧美日韩一区二区三区四区五区六区 | 水蜜桃久久 | 亚洲av日韩av永久无码下载 | 99riav国产在线观看 | 久久久精品福利 | 草草影院第一页yycc.com | 第一页在线视频 | 中出视频在线观看 | 91午夜精品| 久久一区精品 | 亚洲欧美在线观看 | 欧美成人专区 | 综合狠狠| 黄片毛片在线 | 成人一级片在线观看 | 免费看一级黄色大全 | 少妇25p| 在线观看亚洲网站 | 日韩一级免费视频 | 日本道中文字幕 | 欧美综合色区 | 黄色大片在线播放 | 亚洲成人激情小说 | 天天操婷婷 | 天天爽夜夜爽夜夜爽精品视频 | 日韩av片免费观看 | 国产日韩欧美视频在线观看 | 色婷婷综合在线 | 久久精品亚洲精品国产欧美 | 久久久久国产精品 | 久久久久亚洲AV成人无码国产 | 成人国产精品免费观看动漫 | 蜜桃av久久久亚洲精品 | 三级全黄的视频 | 四级黄色片 | 成人av动漫在线 | 成人欧美在线 | 国产又粗又猛又爽又黄的视频在线观看动漫 | 综合色导航 | 国产99久一区二区三区a片 | 欧美人体一区二区 | 中文字幕少妇 | 日韩精品极品 | 色欲狠狠躁天天躁无码中文字幕 | 97精品在线观看 | 日韩欧美一区二区三区四区五区 | 国产精品美女自拍视频 | 免费在线看黄的网站 | 潘金莲一级淫片免费放动漫 | 成人免费观看视频 | 国产精品不卡视频 | 亚洲欧洲日韩在线 | 色老板最新地址 | 精品毛片 | 高清欧美精品xxxxx在线看 | 三级国产视频 | av大片免费观看 | 少妇又紧又色又爽又刺激 |