您好,登錄后才能下訂單哦!
拓?fù)鋱D:
一安裝Nagios
1、安裝前準(zhǔn)備
a、創(chuàng)建Nagios用戶和用戶組,創(chuàng)建nagios主目錄
[root@Server /]# useradd -s /sbin/nologin nagios
[root@Server /]# passwd nagios
[root@Server /]# mkdir /usr/local/nagios
[root@Server /]# chown nagios.nagios /usr/local/nagios/
b、開啟sendmail或者Postfix服務(wù)
chkconfig sendmail on
service sendmail start
或者
chkconfig postfix on
service postfix start
2、編譯安裝Nagios
[root@Server Nagios主程序]# tar -zxvf nagios-3.2.3.tar.gz
[root@Server Nagios主程序]# cd nagios-3.2.3
[root@Server nagios-3.2.3]# ./configure --prefix=/usr/local/nagios/ 指定Nagios的安裝目錄
[root@Server nagios-3.2.3]#make all
[root@Server nagios-3.2.3]#make install 安裝Nagios主程序CGI和HTML文件
[root@Server nagios-3.2.3]#make install-init 在/etc/rc.d/init.d目錄下創(chuàng)建Nagios啟動腳本
[root@Server nagios-3.2.3]#make install-commandmode 命令來配置目錄權(quán)限
[root@Server nagios-3.2.3]#make install-config 安裝Nagios示例配置文件,這里的安裝路徑是/usr/local/nagios/etc
a、設(shè)置開機(jī)啟動
[root@Server nagios-3.2.3]# chkconfig --add nagios
[root@Server nagios-3.2.3]# chkconfig --level 35 nagios on
[root@Server nagios-3.2.3]# chkconfig | grep nagios
nagios 0:關(guān)閉 1:關(guān)閉 2:關(guān)閉 3:啟用 4:啟用 5:啟用 6:關(guān)閉
[root@Server nagios-3.2.3]#
b、Nagios各個目錄名稱及用途說明
[root@Server nagios-3.2.3]# ls /usr/local/nagios/
bin etc libexec sbin share var
[root@Server nagios]# ls var
archives rw spool
[root@Server nagios]#
目錄名稱 用途
bin Nagios可執(zhí)行程序所在目錄
etc Nagios配置文件所在目錄
sbin NagiosCGI文件所在目錄,也就是執(zhí)行外部命令所需文件所在目錄
share Nagios網(wǎng)頁文件所在的目錄
libexec Nagios外部插件所在目錄
var Nagios日志文件、lock等文件所在的目錄
var/archives Nagios日志自動歸檔目錄
var/rw 用來存放外部命令文件的目錄
3、安裝Nagios插件
[root@Server Nagios插件]# tar -zxvf nagios-plugins-1.4.14.tar.gz
[root@Server Nagios插件]# cd nagios-plugins-1.4.14
[root@Server nagios-plugins-1.4.14]# ./configure
[root@Server nagios-plugins-1.4.14]# make all
[root@Server nagios-plugins-1.4.14]# make install
4、安裝Nagios漢化插件
[root@Server Nagios漢化插件]# tar -jxvf nagios-cn-3.2.3.tar.bz2
[root@Server Nagios漢化插件]# cd nagios-cn-3.2.3
[root@Server nagios-cn-3.2.3]# ./configure
[root@Server nagios-cn-3.2.3]# make all
[root@Server nagios-cn-3.2.3]# make install
5、安裝Apache和PHP
[root@Server Apache]# tar -jxvf httpd-2.2.13.tar.bz2
[root@Server Apache]# cd httpd-2.2.13
[root@Server httpd-2.2.13]# ./configure --prefix=/usr/local/apache2
[root@Server httpd-2.2.13]# make
[root@Server httpd-2.2.13]# make install
[root@Server PHP]# tar -jxvf php-5.5.15.tar.bz2
[root@Server php-5.5.15]# cd php-5.5.15
[root@Server php-5.5.15]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
[root@Server php-5.5.15]# make
[root@Server php-5.5.15]# make test
[root@Server php-5.5.15]# make install
a、配置Apache文件
vim /usr/local/apache2/conf/httpd.conf
242 User apache
243 Group apache
改成
66 User nagios
67 Group nagios
167 DirectoryIndex index.html
改成
167 DirectoryIndex index.html index.php
167 AddType application/x-httpd-php .php
添加
412 #setting for nagios
413 ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
414 <Directory "/usr/local/nagios/sbin">
415 Authtype Basic
416 Options ExecCGI
417 AllowOverride None
418 Order allow,deny
419 Allow from all
420 AuthName "Nagios Access"
421 AuthUserFile /usr/local/nagios/etc/htpasswd
422 Require valid-user
423 </Directory>
424
425 Alias /nagios "/usr/local/nagios/share"
426 <Directory "/usr/local/nagios/share">
427 AuthType Basic
428 Options None
429 AllowOverride None
430 Order allow,deny
431 Allow from all
432 AuthName "nagios Access"
433 AuthUserFile /usr/local/nagios/etc/htpasswd
434 Require valid-user
435 </Directory>
b、創(chuàng)建Apache目錄驗證文件
[root@Server /]# /usr/local/apache2/bin/htpasswd -cm /usr/local/nagios/etc/htpasswd xiaodong
New password:
Re-type new password:
Adding password for user xiaodong
[root@Server /]#
c、啟動Apache服務(wù)
[root@Server conf]# /usr/local/apache2/bin/apachectl start
httpd: apr_sockaddr_info_get() failed for Server.shbztech.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@Server conf]#
(FQDN的問題,修改文件“/etc/httpd/conf/httpd.conf”即可解決)
98 ServerName server.shbztech.com:80
http:172.16.1.99/nagios 通過身份驗證“xiaodong/xiaodong”可以看到Nagios的主頁
6、配置Nagios
默認(rèn)的配置文件在“/usr/local/nagios/etc”目錄下,
文件名或目錄名 用途
cgi.cfg 控制CGI訪問的配置文件
nagios.cfg Nagios主配置文件
resource.cfg 變量定義文件,又稱為資源文件,在此文件中定義變量,以便由其它配置文件引用。
objects objects是一個目錄,在此目錄下有很多配置文件模板,用于定義Nagios對象
objects/commands.cfg 命令定義配置文件,其中定義的命令可以被其它配置文件引用
objects/contacts.cfg 定義聯(lián)系人和聯(lián)系人組的配置文件
objects/localhost.cfg 定義監(jiān)控本地主機(jī)的配置文件
objects/printer.cfg 定義監(jiān)控打印機(jī)的一個配置文件模板,默認(rèn)沒有啟用此文件
objects/switch.cfg 監(jiān)控路由器的一個配置文件模板,默認(rèn)沒有啟用此文件
objects/templates.cfg 定義主機(jī)和服務(wù)的一個模板配置文件,可以在其它配置文件中引用
objects/timeperiods.cfg 定義Nagios監(jiān)控時間段的配置文件
objects/windows.cfg 監(jiān)控windows主機(jī)的一個配置文件模板,默認(rèn)沒有啟用此文件
a、配置文件之間的關(guān)系
Nagios的配置過程設(shè)計的幾個定義有:主機(jī)、主機(jī)組、服務(wù)、服務(wù)組、聯(lián)系人、聯(lián)系人組、監(jiān)控時間和監(jiān)控命令等。
第一:定義監(jiān)控那些主機(jī)、主機(jī)組、服務(wù)和服務(wù)組。
第二:定義這個監(jiān)控通過什么命令實現(xiàn)。
第三:定義監(jiān)控的時間段。
第四:定義主機(jī)和服務(wù)出現(xiàn)問題時要通知的聯(lián)系人和聯(lián)系人組。
b、templates.cfg文件
define contact{ ;聯(lián)系人
name generic-contact ;聯(lián)系人名稱
service_notification_period 24x7 ;當(dāng)服務(wù)出現(xiàn)異常,發(fā)送通知的時間段(timeperiods.cfg文件中定義)
host_notification_period 24x7 ;當(dāng)主機(jī)出現(xiàn)異常時,發(fā)送通知的時間段
service_notification_options w,u,c,r,f,s ;定義服務(wù)“通知可以被發(fā)送的情況”,w即warn,表示警告狀態(tài);u即unknown,表示不明狀態(tài);c即criticle,表示緊急狀態(tài);r即recover,表示恢復(fù)狀態(tài)。
host_notification_options d,u,r,f,s ;定義主機(jī)在什么狀態(tài)下需要發(fā)送通知給使用者,d即down,表示宕機(jī)狀態(tài);u即unreachable,表示不可到達(dá)狀態(tài);r即recovery,表示重新恢復(fù)狀態(tài)
service_notification_commands notify-service-by-email ;服務(wù)故障發(fā)送通知的方式,“commands.cfg文件中定義”
host_notification_commands notify-host-by-email ;主機(jī)故障發(fā)送通知的方式,“commands.cfg文件中定義”
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
define host{
name generic-host ;主機(jī)名稱(自定義)
notifications_enabled 1 ;
event_handler_enabled 1 ;
flap_detection_enabled 1 ;
failure_prediction_enabled 1 ;其值可以為0或1,起作用為是啟用Nagios的數(shù)據(jù)輸出功能。
process_perf_data 1 ;Nagios收集數(shù)據(jù)寫入某個文件中,以備提取
retain_status_information 1 ;
retain_nonstatus_information 1 ;
notification_period 24x7 ;
register 0 ;
}
define host{
name linux-server ;主機(jī)名稱(自定義)
use generic-host ;use表示引用,將generic-host的屬性應(yīng)用到linux-server中
check_period 24x7 ;Nagios檢查主機(jī)的時間段
check_interval 5 ;Nagios對主機(jī)檢查時間間隔
retry_interval 1 ;重試檢查時間間隔,單位是分鐘
max_check_attempts 10 ;Nagios對主機(jī)的最大檢查次數(shù),當(dāng)Nagios檢查到主機(jī)宕機(jī)時,會重復(fù)檢查該主機(jī)的次數(shù)
check_command check-host-alive ;指定檢查主機(jī)狀態(tài)的命令
notification_period workhours ;主機(jī)故障時,發(fā)送通知的時間范圍,其中“workhours”在timeperiods.cfg中進(jìn)行定義
notification_interval 120 ;當(dāng)主機(jī)出現(xiàn)異常后,故障一直沒有解決,Nagios再次對使用者發(fā)送通知的時間。單位是分鐘。如果覺得所有的事件發(fā)送一次通知就夠了,可以吧這個選項設(shè)為0
notification_options d,u,r ;定義主機(jī)在什么狀態(tài)下發(fā)送通知給使用者
contact_groups admins ;指定聯(lián)系人組?!癮dmins”在contacts.cfg文件中定義
register 0 ;
}
define service{
name generic-service ;定義一個服務(wù)名稱
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 ;Nagios對服務(wù)的最大檢查次數(shù)
normal_check_interval 10 ;服務(wù)檢查時間間隔,單位:分鐘
retry_check_interval 2 ;重試檢查事件間隔,單位:分鐘
contact_groups admins ;指定聯(lián)系人組
notification_options w,u,c,r ;
notification_interval 60 ;服務(wù)出現(xiàn)故障后,故障一直沒解決,Nagios在此向使用者發(fā)送通知的時間,單位:分鐘
notification_period 24x7 ;
register 0 ;
}
define service{
name local-service ; The name of this service template
use generic-service ; Inherit default values from the generic-service definition
max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state
normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
c、resource.cfg文件(只有一行)
$USER1$=/usr/local/nagios/libexec 指定安裝Nagios插件的路徑
d、commangs.cfg文件
此文件默認(rèn)情況下是存在的,無需任何修改即可使用。
e、hosts.cfg
此文件默認(rèn)情況下不存在,需要手動創(chuàng)建。主要用來指定被監(jiān)控的主機(jī)地址
define host {
use linux-server ;引用主機(jī)linux-server的屬性
host_name www.shbztech.com ;主機(jī)名
alias xiaodong-web ;主機(jī)別名
address 172.16.1.100 ;主機(jī)IP
}
define host {
use linux-server
host_name ftp.shbztech.com
alias xiaodong-ftp
address 172.16.1.101
}
define hostgroup { ;定義一個主機(jī)組
hostgroup_name linux-server ;主機(jī)組名稱,可以隨意指定
alias Linux Server ;主機(jī)組別名
members www.shbztech.com,ftp.shbztech.com ;主機(jī)組成員
}
f、services.cfg文件
此文件默認(rèn)情況下不存在,需要手動創(chuàng)建。主要用來定義監(jiān)控的服務(wù)和主機(jī)資源。
例如:監(jiān)控HTTP服務(wù)、FTP服務(wù)、主機(jī)磁盤空間、主機(jī)系統(tǒng)負(fù)載等。
################################## xiaodong Web #####################################
define service{
use local-service
host_name www.shbztech.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name www.shbztech.com
service_description SSH
check_command check_ssh
}
define service{
use local-service
host_name www.shbztech.com
service_description http
check_command check_http
}
################################## xiaodong FTP #####################################
define service{
use local-service
host_name ftp.shbztech.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name ftp.shbztech.com
service_description SSH
check_command check_ssh
}
define service{
use local-service
host_name ftp.shbztech.com
service_description ftp
check_command check_tcp!21
}
在Nagios中,插件命令和參數(shù)組合格式為:命令!參數(shù)!參數(shù)。如果有更多參數(shù),以此通過嘆號分割即可
例如:
check_ping!100.0,20%!500.0,60%
此命令組合從左到右依次為:命令!告警時延,丟包率!嚴(yán)重告警時延,丟包率。
check_http!0.0020!0.0050!10
此命令組合從左到右依次為:命令!告警時延!嚴(yán)重告警時延!連接超時時間
check_tcp!23!0.0020!0.0050!10
此命令組合從左到右依次為:命令!端口!告警時延!嚴(yán)重告警時延!連接超時時間
check_ssh!22!10
此命令組合從左到右依次為:命令!端口!連接超時時間
check_smtp!0.0020!0.0050!10
此命令組合從左到右依次為:命令!告警時延!嚴(yán)重告警時延!連接超時時間
另外,在監(jiān)控服務(wù)器端口時,很多命令都可以使用check_tcp來代替,
例如:
check_ssh=check_tcp!22
check_imap=check_tcp!143
check_ftp=check_tcp!21
g、contacts.cfg文件
contacts.cfg是一個定義聯(lián)系人和聯(lián)系人組的配置文件。
define contact{
contact_name xiaodong ;聯(lián)系人名稱
use generic-contact ;引用generic-contact的屬性信息
alias Nagios Admin ;聯(lián)系人別名
email lixiaodong620@163.com ;聯(lián)系人常用郵箱地址
}
define contactgroup{
contactgroup_name admins ;聯(lián)系人組
alias Nagios Administrators ;聯(lián)系人組描述
members xiaodong ;聯(lián)系人組成員
}
h、timeperiods.cfg文件
此文件只用于定義監(jiān)控的時間段
define timeperiod{
timeperiod_name 24x7
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
}
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
}
i、cgi.cfg文件
此文件用來控制相關(guān)CGI腳本,如果想在Nagios的Web監(jiān)控界面執(zhí)行CGI腳本,例如重啟Nagios進(jìn)程、關(guān)閉Nagios通知
停止Nagios主機(jī)檢測等,這時就需要配置cgi.cfg文件了
由于Nagios的Web監(jiān)控界面驗證用戶為xiaodong,因此只需在cgi.cfg文件中添加此用戶的執(zhí)行權(quán)限。
107 default_user_name=xiaodong
119 authorized_for_system_information=nagiosadmin,xiaodong
131 authorized_for_configuration_information=nagiosadmin,xiaodong
144 authorized_for_system_commands=nagiosadmin,xiaodong
157 authorized_for_all_services=nagiosadmin,xiaodong
158 authorized_for_all_hosts=nagiosadmin,xiaodong
j、nagios.cfg文件
Nagios的核心配置文件,所有對象配置文件必須在這個文件中進(jìn)行定義才能發(fā)揮其作用
“l(fā)og_file”變量用來定義Nagios日志文件的路徑
19 log_file=/usr/local/nagios/var/nagios.log
“cfg_file”變量用來引用對象配置文件
30 cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
31 cfg_file=/usr/local/nagios/etc/objects/services.cfg
32 cfg_file=/usr/local/nagios/etc/objects/commands.cfg
33 cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
34 cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
35 cfg_file=/usr/local/nagios/etc/objects/templates.cfg
“object_cache_file”變量用于指定一個“所有對象配置文件”的副本文件,又稱為對象緩沖文件,這個設(shè)定可以加快CGI的配置緩沖,并且在編輯對象配置文件時,可以讓正在進(jìn)行的Nagios不影響CGI的顯示輸出
69 object_cache_file=/usr/local/nagios/var/objects.cache
“resource_file”變量用于指定Nagios資源文件的路徑
98 resource_file=/usr/local/nagios/etc/resource.cfg
“status_file”變量用于定義一個狀態(tài)文件
108 status_file=/usr/local/nagios/var/status.dat
“status_update_interval”變量用于定義狀態(tài)文件的更新時間間隔,單位是秒,最先更新間隔是1秒
117 status_update_interval=10
“nagios”進(jìn)程由那個用戶和組運行
125 nagios_user=nagios
133 nagios_group=nagios
“check_external_commands”變量用于設(shè)置是否允許Nagios在Web監(jiān)控界面上運行CGI命令,也就是是否允許Nagios在Web界面下執(zhí)行重啟Nagios、停止主機(jī)/服務(wù)檢查等操作,“1”為運行,“0”為不允許運行
145 check_external_commands=1
“command_check_interval”變量用于設(shè)置Nagios對外部命令檢測的時間間隔,如果指定了一個數(shù)字加一個“s”(如10s),那么外部檢測命令的間隔是這個數(shù)值以秒為單位的時間間隔。如果沒有“s”,那么外部檢測的命令的間隔是以這個數(shù)值為“時間單位”的時間間隔
163 command_check_interval=2
“interval_length”變量指定了Nagios的時間單位,默認(rèn)是60秒,也就是1分鐘,即在Nagios配置中所有的“時間單位”都是分鐘
720 interval_length=60
7、Nagios的運行和維護(hù)
a、驗證nagios配置文件的正確性
[root@Server etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 3.2.3
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 10-03-2010
License: GPL
Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/hosts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/services.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'...
Read object config files okay...
Running pre-flight check on configuration data...
Checking services...
Checked 14 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 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@Server etc]#
b、啟動與停止Nagios
啟動Nagios
1>通過初始化腳本啟動Nagios
/etc/init.d/nagios start
或者
service nagios start
2>手工方式啟動Nagios
通過Nagios命令的“-d”參數(shù)來啟動Nagios守護(hù)進(jìn)程
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
關(guān)閉Nagios
1>通過初始化腳本關(guān)閉Nagios服務(wù)
/etc/init.c/nagios stop
或者
service nagios stop
2>通過kill方式關(guān)閉Nagios
kill <nagios_pid>
重啟Nagios
1>通過初始化腳本來重啟Nagios
/etc/init.d/nagios reload
/etc/init.d/nagios restart
或者
service nagios restart
2>通過Web監(jiān)控頁重啟Nagios
3>手工方式平滑重啟
kill -HUP <nagios_pid>
8、Nagios性能分析圖表的實現(xiàn)
a、安裝rrdtool
[root@Server RRDtool]# tar -zxvf rrdtool-1.4.5.tar.gz
[root@Server RRDtool]# cd rrdtool-1.4.5
[root@Server rrdtool-1.4.5]# ./configure --prefix=/usr/local/rrdtool
[root@Server rrdtool-1.4.5]# make
[root@Server rrdtool-1.4.5]# make install
[root@Server rrdtool-1.4.5]#
configure: error: Please fix the library issues listed above and try again.
解決方案:
第一:
tar -zxvf cgilib-0.5.tar.gz
cd cgilib-0.5
make
cp libcgi.a /usr/local/lib
cp cgi.h /usr/include/
不能解決看下面
第二:
yum -y install libart_lgpl-devel
不能解決看下面
第三:
yum -y install pango-devel* cairo-devel* libxml2-devel
解決?。?/p>
b、安裝pnp
[root@Server PNP]# tar -zxvf pnp-0.4.13.tar.gz
[root@Server PNP]# cd pnp-0.4.13
[root@Server pnp-0.4.13]# ./configure --with-nagios-user=nagios --with-nagios-group-nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata
[root@Server pnp-0.4.13]# make all
[root@Server pnp-0.4.13]# make install
[root@Server pnp-0.4.13]# make install-config
[root@Server pnp-0.4.13]# make install-init
c、配置pnp
創(chuàng)建默認(rèn)配置文件
[root@Server /]# cd /usr/local/nagios/etc/pnp/
[root@Server pnp]# cp process_perfdata.cfg-sample process_perfdata.cfg
[root@Server pnp]# cp npcd.cfg-sample npcd.cfg
[root@Server pnp]# cp rra.cfg-sample rra.cfg
[root@Server pnp]# chown -R nagios.nagios /usr/local/nagios/etc/pnp/
修改process_perfdata.cfg文件
[root@Server pnp]# vim process_perfdata.cfg
44 LOG_LEVEL = 0
改成
44 LOG_LEVEL = 2
d、修改Nagios配置文件
1>增加小太陽圖標(biāo)
修改templates.cfg文件
define host {
name hosts-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$
process_perf_data 1
}
define service {
name services-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data 1
}
2>修改nagios.cfg文件
833 process_performance_data=0
改成
833 process_performance_data=1 ###開啟數(shù)據(jù)輸出功能
去掉注釋
845 host_perfdata_command=process-host-perfdata
846 service_perfdata_command=process-service-perfdata
3>修改commands.cfg文件
228 define command{
229 command_name process-host-perfdata
230 command_line /usr/local/nagios/libexec/process_perfdata.pl
231 }
235 define command{
236 command_name process-service-perfdata
237 command_line /usr/local/nagios/libexec/process_perfdata.pl
238 }
4>修改hosts.cfg文件和services.cfg文件
hosts.cfg
define host {
use linux-server,hosts-pnp ;“添加hosts-pnp”
host_name www.shbztech.com
alias xiaodong-web
address 172.16.1.100
}
services.cfg
define service{
use local-service,services-pnp
host_name www.shbztech.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
檢測Nagios配置正確性
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart
打開小太陽出現(xiàn)故障
故障一:PHP zlib Support not found
解決方案:需要重新編譯安裝PHP。
[root@Server php-5.5.15]# cd php-5.5.15
[root@Server php-5.5.15]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-apxs2=/usr/local/apache2/bin/apxs
[root@Server php-5.5.15]# make
[root@Server php-5.5.15]# make test
[root@Server php-5.5.15]# make install
故障二: /usr/local/nagios/share/pnp/include/function.inc.php on line 557
解決方案:vim /usr/local/nagios/share/pnp/include/function.inc.php
556 date_default_timezone_set('UTC'); 添加一行
故障三: /usr/local/nagios/share/pnp/include/function.inc.php on line 1027
1027 $pdf =& new PDF('P', 'mm', 'A4');
改成
1027 $pdf = new PDF('P', 'mm', 'A4');
1503 if($level == 2 && $type == "complete" && eregi("^NAGIOS_",$tag)){
改成
1503 if($level == 2 && $type == "complete" && preg_match("/^NAGIOS_/",$tag)){
再重新重啟nagios,應(yīng)該就能看到圖表了
9、利用插件擴(kuò)展Nagios的監(jiān)控功能 - 利用NRPE外部構(gòu)件監(jiān)控遠(yuǎn)程主機(jī)
配置Nagios客戶端(遠(yuǎn)程主機(jī))
a、安裝Nagios插件
[root@www nagios]# useradd -s /sbin/nologin nagios
[root@www nagios]# passwd nagios
[root@www nagios]# tar -zxvf nagios-plugins-1.4.14.tar.gz
[root@www nagios]# cd nagios-plugins-1.4.14
[root@www nagios-plugins-1.4.14]# ./configure
[root@www nagios-plugins-1.4.14]# make install
[root@www nagios-plugins-1.4.14]# chown nagios.nagios /usr/local/nagios/
[root@www nagios-plugins-1.4.14]# chown nagios.nagios /usr/local/nagios/libexec/
b、安裝NRPE插件
[root@www nagios]# tar -zxvf nrpe-2.14.tar.gz
[root@www nagios]# cd nrpe-2.14
故障:checking for SSL headers... configure: error: Cannot find ssl headers
解決方案:
yum -y install openssl-devel
[root@www nrpe-2.14]# make all
[root@www nrpe-2.14]# make install-plugin
[root@www nrpe-2.14]# make install-daemon
[root@www nrpe-2.14]# make install-daemon-config
c、配置NRPE
/usr/local/nagios/etc/nrpe.cfg
81 allowed_hosts=127.0.0.1
改成
81 allowed_hosts=127.0.0.1,172.16.1.99 ;nagios監(jiān)控服務(wù)器IP
d、啟動NRPE守護(hù)進(jìn)程
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
vim /etc/rc.local 加入開機(jī)啟動腳本
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@www /]# netstat -antl | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
關(guān)閉NRPE進(jìn)程
ps -aux | grep nagios
kill pid
e、測試NRPE功能
在客戶端本機(jī)上測試
[root@www /]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.14 --看到“NRPE v2.14”就說明成功了
在服務(wù)器上安裝NRPE和配置Nagios服務(wù)
a、安裝NRPE插件
[root@NagiosServer NRPE]# tar -zxvf nrpe-2.14.tar.gz
[root@NagiosServer NRPE]# cd nrpe-2.14
[root@NagiosServer NRPE]# ./configure
故障:checking for SSL headers... configure: error: Cannot find ssl headers
解決方案:
yum -y install openssl-devel
[root@NagiosServer NRPE]# make all
[root@NagiosServer nrpe-2.14]# make install-plugin ;通過make install-plugin 命令默認(rèn)將check_nrpe插件安裝到/usr/local/nagios/libexec目錄下
b、測試插件與客戶端是否能正常通信
[root@NagiosServer /]# /usr/local/nagios/libexec/check_nrpe -H 172.16.1.100
NRPE v2.14 --看到“NRPE v2.14”就說明成功了
[root@NagiosServer /]# /usr/local/nagios/libexec/check_nrpe -H 172.16.1.101
NRPE v2.14
c、定義一個check_nrpe監(jiān)控命令
vim /usr/local/nagios/etc/objects/commands.cfg
添加如下命令
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
d、添加遠(yuǎn)程主機(jī)監(jiān)控
vim /usr/local/nagios/etc/objects/services.cfg
################################# xiaodong www #####################################
define service{
use local-service,services-pnp
host_name www.shbztech.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,services-pnp
host_name www.shbztech.com
service_description SSH
check_command check_ssh
}
define service{
use local-service,services-pnp
host_name www.shbztech.com
service_description http
check_command check_http
}
define service{
use local-service,services-pnp
host_name www.shbztech.com
service_description users
check_command check_nrpe!check_users
}
define service{
use local-service,services-pnp
host_name www.shbztech.com
service_description load
check_command check_nrpe!check_load
}
################################# xiaodong ftp #####################################
define service{
use local-service,services-pnp
host_name ftp.shbztech.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,services-pnp
host_name ftp.shbztech.com
service_description SSH
check_command check_ssh
}
define service{
use local-service,services-pnp
host_name ftp.shbztech.com
service_description ftp
check_command check_tcp!21
}
define service{
use local-service,services-pnp
host_name ftp.shbztech.com
service_description users
check_command check_nrpe!check_users
}
define service{
use local-service,services-pnp
host_name ftp.shbztech.com
service_description load
check_command check_nrpe!check_load
}
增加的配置是對www.shbztech.com和ftp.shbztech.com主機(jī)的當(dāng)前用戶數(shù)、系統(tǒng)負(fù)載、磁盤空間利用率、swap內(nèi)存使用4個方面進(jìn)行監(jiān)控
監(jiān)控遠(yuǎn)程主機(jī)的命令方式:check_nrpe!遠(yuǎn)程主機(jī)下定義的監(jiān)控變量 而check_users、check_load等變量已經(jīng)在Nagios客戶端nrpe.cfg文件中進(jìn)行了定義。
e、測試和啟動Nagios服務(wù)
[root@NagiosServer /]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@NagiosServer /]# service nagios restart
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。