nagios安裝使用指南
話不多說,下面開始,nagios具體的介紹,可以搜一下,這篇文章為作者在實際操作中整理出來,寫出來的都是負責人的內容~如果不想線上看,可以下載文件,請點選文件下載
環境準備
此文件共用2臺伺服器的配置,作業系統均為centOS6.7,安裝使用者都為nagios使用者,所有的安裝都必須基於nagios,當權限不足時,採用sudo的方式,具體資訊如下:
IP地址 | 角色 | 安裝使用者 |
---|---|---|
192.168.1.10 | Nagios服務端 | nagios |
192.168.1.11 | 被監控主機 | nagios |
nagios服務端安裝步驟
編譯安裝nagios軟體
安裝需要192.168.1.10伺服器預裝cc,glibc,glibc-common,gd,gd-devel,xinetd,openssl-devel等,執行命令:
[nagios@localhost ~]$ rpm -qa | grep **
#依次檢查是否安裝以上軟體,如果沒有安裝則執行命令:
[nagios@localhost ~]$ sudo yum install -y **
依賴部分處理好之後,下面進行nagios的編譯安裝,nagios的下載地址為:nagios官網下載 ,下載好之後,進入防止安裝包的目錄,解壓壓縮包:
[nagios@localhost ~]$ tar zxvf nagios-3.5.0.tar.gz
進入解壓後的目錄: cd /home/nagios/nagios依次執行:
./configure --prefix=/usr/local/nagios
make all
sudo make install
sudo make install-init
make install-commandmode
make install-config
sudo chkconfig --add nagios
sudo chkconfig --level 35 nagios on
最後執行
sudo chkconfig --list nagios
顯示如下結果:
下面來驗證nagios是否被安裝:
切換到目錄/usr/local/nagios/下,檢視目錄結構如下:
如果以上目錄都存在,說明程式已經被安裝到伺服器中,各個目錄的作用為:
目錄 | 作用 |
---|---|
bin | 可執行程式所在目錄 |
etc | 配置檔案所在目錄 |
libexec | 外部外掛所存放的目錄 |
sbin | Nagios CGI檔案所在目錄,也就是執行外部命令所需檔案所在的目錄 |
share | 網頁檔案存放目錄 |
var | 日誌,lock檔案目錄 |
安裝nagios外掛
nagios外掛下載地址為:官網下載解壓安裝包:
tar zxvf nagios-plugins-2.0.1.tar.gz
進入解壓目錄:
[nagios@localhost ~]$ cd nagios-plugins-2.0.1
[nagios@localhost nagios-plugins-2.0.1]$ pwd
/home/nagios/nagios-plugins-2.0.1 #解壓路徑
分別執行命令:
./configure --prefix=/usr/local/nagios
make
sudo make install
安裝apache和php
安裝apache
nagios提供了web頁面,可以觀看被監控的資源狀態,所以需安裝apache與php來支援此項功能,那麼首,檢視作業系統是否自帶了apache,如果有就刪除掉:
[nagios@localhost nagios-plugins-2.0.1]$ rpm -qa | grep httpd
httpd-tools-2.2.15-45.el6.centos.x86_64
httpd-2.2.15-45.el6.centos.x86_64
#刪除自帶的apache
[nagios@localhost nagios-plugins-2.0.1]$ sudo rpm -e --nodeps httpd
下載apache安裝包 官網下載 解壓下載的安裝包並安裝:
#建立資料夾,存到執行指令碼配置檔案等
sudo mkdir /usr/local/apache2
#解壓安裝包
tar zxvf httpd-2.2.23.tar.gz
#進入安裝路徑
cd httpd-2.2.23
#配置值向目錄,通第一條命令的目錄
./configure --prefix=/usr/local/apache2
#編譯
make
#安裝
sudo make install
安裝php
php安裝包下載地址:官網下載,下載後執行以下命令:
#解壓安裝包
tar zxvf php-5.4.10.tar.gz
#建立資料夾,存到執行指令碼配置檔案等
sudo mkdir /usr/local/php
#進入解壓之後的目錄
cd php-5.4.10
#配置指向目錄
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
執行最後一條語句時,出現如下錯誤:
說明沒有安裝libxml2和libxml2-devel,安裝即可:
#已經存在libxml2,說明只安裝libxml2-devel即可
[nagios@localhost php-5.4.10]$ rpm -qa libxml2
libxml2-2.7.6-20.el6.x86_64
#安裝libxml2-devel
sudo yum install -y libxml2-devel
執行成功,接續執行:
#編譯
make
#安裝
make install
最後將安裝目錄下的php.ini-production檔案,拷貝至/usr/local/php/lib/下並命名為php.ini
sudo cp php.ini-production /usr/local/php/lib/php.ini
配置apache
編輯apache的配置檔案httpd.conf
sudo vim /usr/local/apache2/conf/httpd.conf
找到:
User daemon
Group daemon
修改為:
Group nagios
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
修改為:
<IfModule dir_module>
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
</IfModule>
為了增加使用者的訪問許可權,在此檔案中增加以下配置:
#setting for magion
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
建立apache目錄驗證檔案
在上面的配置中,指定了許可權驗證檔案/usr/local/nagios/etc/htpasswd,下面來建立這個檔案,最後的nagios是使用者名稱,輸入命令後,需要手工輸入密碼:
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios
最後啟動apache服務:
sudo /usr/local/apache2/bin/apachectl start
配置nagios server
預設情況下,nagios沒有做任何配置,那麼下面介紹一些主要配置檔案和如何配置服務,配置檔案主要在目錄: /usr/local/nagios/etc/
nagios的配置檔案,是相互聯絡的,搞清楚具體的配置,就可以弄清楚他們之間的依賴:
- templates.cfg
nagios主要用於監控主機資源以及服務,在nagios配置中稱為物件,為了不必重複定義一些監控物件,nagios引入了一個模板配置檔案,將一些共性的屬性定義成模板,以便於多次引用,這就是templates.cfg的作用,具體的含義如下:
#一般的通用配置,下面具體的某種型別配置中,可以引用次配置
define contact{
name generic-contact ; 別名
service_notification_period 24x7 當服務出現異常時,傳送通知的時間段,這個時間段"24x7"在timeperiods.cfg檔案中定義
host_notification_period 24x7 ;當主機出現異常時,傳送通知的時間段,這個時間段"24x7"在timeperiods.cfg檔案中定義
service_notification_options w,u,c,r,f,s ; 什麼級別的通知(針對主機),會被髮送出去(w:warn|u:unknow|c:criticle緊急狀態|r:recover恢復狀態|d:宕機),f,s含義還沒查到
host_notification_options d,u,r,f,s ;什麼級別的警告(針對服務)會被通知出去
service_notification_commands notify-service-by-email ; 服務故障時,傳送通知的方式,可以是郵件和簡訊,這裡傳送的方式是郵件; 其中“notify-service-by-email”在commands.cfg檔案中定義
host_notification_commands notify-host-by-email ; 主機故障時,傳送通知的方式,可以是郵件和簡訊,這裡傳送的方式是郵件; 其中“notify-host-by-email”在commands.cfg檔案中定義
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
define host{
name generic-host ; 主機名稱,這裡的主機名,並不是直接對應到真正機器的主機名 ; 乃是對應到在主機配置檔案裡所設定的主機名
notifications_enabled 1 ; Host notifications are enabled 主機啟動通知,1已啟用,0為啟用
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data 其值可以為0或1,其作用為是否啟用Nagios的資料輸出功能;如果將此項賦值為1,那麼Nagios就會將收集的資料寫入某個檔案中,以備提取
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_period 24x7 ; Send host notifications at any time 指定“傳送通知”的時間段,也就是可以在什麼時候傳送通知給使用者
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
# 功能同上,只不過這個是針對linux伺服器的特殊配置
define host{
name linux-server ; The name of this host template
use generic-host ; This template inherits other values from the generic-host template use表示引用,也就是將主機generic-host的所有屬性引用到linux-server中來; 在nagios配置中,很多情況下會用到引用
check_period 24x7 ; By default, Linux hosts are checked round the clock 這裡的check_period告訴nagios檢查主機的時間段
check_interval 5 ; Actively check the host every 5 minutes 對主機的檢查間隔時間,單位/分鐘
retry_interval 1 ; Schedule host check retries at 1 minute intervals cho 重試間隔,單位/分鐘
max_check_attempts 10 ; Check each Linux host 10 times (max) 最大重試此書
check_command check-host-alive ; Default command to check Linux hosts 指定檢查主機狀態的命令,其中“check-host-alive”在commands.cfg檔案中定義
notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day 主機故障時,傳送通知的時間範圍,其中“workhours”在timeperiods.cfg中進行了定義
; Note that the notification_period variable is being overridden from
; the value that is inherited from the generic-host template!
notification_interval 0 ; Resend notifications every 2 hours 在主機出現異常後,故障一直沒有解決,nagios再次對使用者發出通知的時間,0代表值通知1次
notification_options d,u,r ; Only send notifications for specific host states 定義主機在什麼狀態下可以傳送通知給使用者
contact_groups admins ; Notifications get sent to the admins by default 指定聯絡人組,這個“admins”在contacts.cfg檔案中定義
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
# Generic service definition template - This is NOT a real service, just a template!定義服務的通用配置,下面的可以利用use來引用
define service{
name generic-service ; The 'name' of this service template 為這個服務取一個名字
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
is_volatile 0 ; The service is not volatile
check_period 24x7 ; The service can be checked at any time of the day 告訴nagios檢查服務的時間段
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
normal_check_interval 10 ; Check the service every 10 minutes under normal conditions
retry_check_interval 2 ; Re-check the service every two minutes until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the 'admins' group 指定聯絡人組
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
#定義一個監控本機的service
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!
}
#其餘的配置,如印表機,windowServer,交換機的監控這裡暫時不介紹
- resource.cfg
這個配置檔案只有一行:
$USER1$=/usr/local/nagios/libexec
指定了nagios可執行外掛的路徑,這個根據自己的實際路徑來決定.將來配置外掛或者自定義外掛,會大量用到這個變數
commands.cfg
這個檔案是定義一些命令的時候,需要修改的檔案,目前不需要修改預設的配置檔案,後面章節中會有新增自定義服務,那裡會詳細介紹如何修改hosts.cfg檔案
這個檔案需要手動建立,在/usr/local/nagios/etc/objects目錄下建立,內容如下:
define host{
use linux-server ;引用主機linux-server的屬性資訊,linux-server主機在templates.cfg檔案中進行了定義。
host_name nagios1 ;主機名
alias nagios1 ;主機別名
address 192.168.1.11 ;被監控的主機地址,這個地址可以是ip,也可以是域名。
}
#定義一個主機組
define hostgroup{
hostgroup_name bsmart-servers ;主機組名稱,可以隨意指定。
alias bsmart servers ;主機組別名
members nagios1 ;主機組成員,其中“Nagios-Linux”就是上面定義的主機。
}
- localhost.cfg
這個配置檔案是監控nagios server本身的
# 為本機定義一個host,取名為localhost
define host{
use linux-server ; 引用模板配置檔案裡的內容
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}
#定義主機組,成員只有localhost
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members localhost ; Comma separated list of hosts that belong to this group
}
#配置檔案的其他內容都為利用預設的外掛,配置的一些服務,也就是localhost需要監控的一些專案
- services.cfg
這個檔案也需要手工建立, 在/usr/local/nagios/etc/objects下建立,主要內容為:
define service{
use local-service ;引用local-service服務的屬性值,local-service在templates.cfg檔案中進行了定義。
host_name nagios1 ;指定要監控哪個主機上的服務,“Nagios-Server”在hosts.cfg檔案中進行了定義。
service_description check-host-alive ;對監控服務內容的描述,以供維護人員參考。
check_command check-host-alive ;指定檢查的命令。
}
define service{
use local-service
host_name nagios1
service_description Current Load
check_command check_nrpe!check_load
}
define service{
use local-service
host_name nagios1
service_description Check Disk sda1
check_command check_nrpe!check_sda1
}
define service{
use local-service
host_name nagios1
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use local-service
host_name nagios1
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use local-service
host_name nagios1
service_description Check Zombie Procs
check_command check_nrpe!check_zombie_procs
}
- contacts.cfg
主要配置一些聯絡人,聯絡人組:
#聯絡人
define contact{
contact_name gzd ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)引用generic-contact的屬性資訊,其中“generic-contact”在templates.cfg檔案中進行定義
alias gzd ; Full name of user
email [email protected]163.com ;
}
#聯絡人組,成員只有gzd
define contactgroup{
contactgroup_name admins
alias admins
members gzd
}
- timeperiods.cfg
時間的定義檔案:
#24*7也就是每天
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
}
#美國的節假日,用不到,可以直接刪除
define timeperiod{
name us-holidays
timeperiod_name us-holidays
alias U.S. Holidays
january 1 00:00-00:00 ; New Years
monday -1 may 00:00-00:00 ; Memorial Day (last Monday in May)
july 4 00:00-00:00 ; Independence Day
monday 1 september 00:00-00:00 ; Labor Day (first Monday in September)
thursday 4 november 00:00-00:00 ; Thanksgiving (4th Thursday in November)
december 25 00:00-00:00 ; Christmas
}
- cgi.cfg
此檔案用來控制相關cgi指令碼,如果想在nagios的web監控介面執行cgi指令碼,例如重啟nagios程序,關閉nagios通知,停止nagios主機檢測等,就需要配置cgi.cfg檔案了,由於nagios的web監控介面驗證使用者為nagios,所以只需在cgi.cfg檔案中需要修改的配置資訊如下:
default_user_name=nagios
authorized_for_system_information=nagiosadmin, nagios
authorized_for_configuration_information=nagiosadmin, nagios
authorized_for_system_commands= nagios
authorized_for_all_services=nagiosadmin, nagios
authorized_for_all_hosts=nagiosadmin, nagios
authorized_for_all_service_commands=nagiosadmin, nagios
authorized_for_all_host_commands=nagiosadmin, nagios
- nagios.cfg
-
nagios的核心配置檔案,所有的配置,需要在此定義,才可以生效.
log_file=/usr/local/nagios/var/nagios.log # 定義nagios日誌檔案的路徑
cfg_file=/usr/local/nagios/etc/objects/commands.cfg # “cfg_file”變數用來引用物件配置檔案,如果有更多的物件配置檔案,在這裡依次新增即可。
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
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/localhost.cfg # 本機配置檔案
cfg_file=/usr/local/nagios/etc/objects/windows.cfg # windows 主機配置檔案(不用可以刪掉)
object_cache_file=/usr/local/nagios/var/objects.cache # 該變數用於指定一個“所有物件配置檔案”的副本檔案,或者叫物件緩衝檔案
precached_object_file=/usr/local/nagios/var/objects.precache
resource_file=/usr/local/nagios/etc/resource.cfg # 該變數用於指定nagios資原始檔的路徑,可以在nagios.cfg中定義多個資原始檔。
status_file=/usr/local/nagios/var/status.dat # 該變數用於定義一個狀態檔案,此檔案用於儲存nagios的當前狀態、註釋和宕機資訊等。
status_update_interval=10 # 該變數用於定義狀態檔案(即status.dat)的更新時間間隔,單位是秒,最小更新間隔是1秒。
nagios_user=nagios # 該變數指定了Nagios程序使用哪個使用者執行。
nagios_group=nagios # 該變數用於指定Nagios使用哪個使用者組執行。
check_external_commands=1 # 該變數用於設定是否允許nagios在web監控介面執行cgi命令;
# 也就是是否允許nagios在web介面下執行重啟nagios、停止主機/服務檢查等操作;
# “1”為執行,“0”為不允許。
command_check_interval=10s # 該變數用於設定nagios對外部命令檢測的時間間隔,如果指定了一個數字加一個"s"(如10s);
# 那麼外部檢測命令的間隔是這個數值以秒為單位的時間間隔;
# 如果沒有用"s",那麼外部檢測命令的間隔是以這個數值的“時間單位”的時間間隔。
interval_length=60 # 該變數指定了nagios的時間單位,預設值是60秒,也就是1分鐘 # 即在nagios配置中所有的時間單位都是分鐘。
最後驗證配置檔案是正確:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果出現以下內容,則驗證成功:
nagios的啟動,停止操作
啟動主要有三種方式:
#指定配置檔案啟動
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
#初始化指令碼啟動
/etc/init.d/nagios start
#利用服務啟動
service nagios start
重啟:
#初始化指令碼重啟
/etc/init.d/nagios reload
或者
/etc/init.d/nagios restart
#利用服務啟動
service nagios restart
#可以通過web監控頁的 "Process Info" -> "Restart the Nagios process"來重啟nagios
停止
#初始化指令碼重啟
/etc/init.d/nagios stop
#利用服務啟動
service nagios stop
#可以通過web監控頁的 "Process Info" -> "Shutdown the Nagios process"來停止nagios
啟動nagios後,登入web頁面,點選左側選單”hosts”,可以看到我們在上面定義的主機”localhost”:
點選左側選單的”service”,可以看到監控的服務狀態,如果為PENDING,說明服務等待執行中,稍等一會或者調小執行間隔可縮短等待時間,可以看到,服務的監控狀態均綠色,”OK”狀態,表示正常:
至此,nagios Serveer的配置已經完成!
nagios客戶端配置
安裝nagios外掛和NRPE
被監控主機上需要安裝NRPE和安裝nagios-plugins-2.0.1.tar.gz
這個外掛和nagios server上的外掛為同一,安裝方法也一樣:
# mkdir /usr/local/nagios
# tar zxvf nagios-plugins-2.0.1.tar.gz
# cd nagios-plugins-2.0.1
# configure --prefix=/usr/local/nagios
# make && make install
安裝NPRE:
下載請點選:下載地址!
安裝需SSL庫,執行:sudo yum install -y openssl-devel安裝,安裝後,一次執行以下命令:
#解壓安裝包
tar zxvf nrpe-2.8.1.tar.gz
#進入解壓目錄
cd nrpe-2.8.1
#配置安裝
./configure
#編譯
make all
#安裝check_nrpe外掛
make install-plugin
#安裝daemon
make install-daemon
#安裝配置檔案
make install-daemon-config
#安裝xinetd
make install-xinetd
安裝好了之後,可以看到多了這個檔案:/etc/xinetd.d/nrpe,編輯這個檔案:
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
#在這裡增加nagios server的ip,空格分割
only_from = 127.0.0.1 192.168.1.10
}
編輯etc/services 檔案,增加nrpe服務,增加內容:
nrpe 5666/tcp # nrpe
重啟xinted服務:
service xinetd restart
輸入命令netstat -na | grep :5666,出現:
則為啟動正常!
配置監控主機nrpe服務
安裝NRPE:
一次執行命令:
tar zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
以上內容結束,重啟nagios服務!
被監控主機的配置
修改/usr/local/nagios/etc/nrpe.cfg配置檔案:
ommand[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_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
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
如上圖,我們在被監控的主機上定義的命令,需要在此配置檔案給出!
最後請重啟nagios
PNP4Nagios
PNP4Nagios 是一個用於顯示nagios效能圖表的外掛,基於RRDTool日誌分析,並以 Kohana(一個 PHP 開發框架)呈現在 Web 端,可以以 Action Url 的形式整合到 Nagios 中,此處的安裝主機均在nagios server機器上安裝
Nagios對服務或主機監控的是一個瞬時狀態,有時候系統管理員如果需要了解主機在一段時間內的效能以及服務的響應狀態,並且形成圖表時,就需要通過檢視日誌資料來分析,但是這種方式不但繁瑣,而且抽象,可以利用PNP來解決這個問題
安裝PNP
PNP是一個小巧的開源軟體包,它基於PHP和PERL,PNP可以利用rrdtool工具將Nagios採集的資料繪製成相關的圖表,然後顯示主機或者服務在一段時間內的執行狀況
安裝rrdtool
rrdtool是一個生成圖表的工具,下載地址為: 下載地址
以此執行以下命令:
#進入壓縮包所在目錄
cd /home/nagios/
建立配置目錄
sudo mkdir /usr/local/rrdtool
解壓壓縮包,注意這裡用tar xvf命令解壓
tar xvf rrdtool-1.4.8.tar.gz
進入解壓包目錄
cd rrdtool-1.4.8
#配置目錄
./configure --prefix=/usr/local/rrdtool
提示需要安裝依賴:perl和fix庫檔案:
yum -y install pango*
yum -y install perl*
繼續執行
make
make install
安裝pnp4nagios
tar -xvzf pnp4nagios-0.6.21.tar.gz
cd pnp4nagios-0.6.21
./configure --with-nagios-user=nagios --with-nagios-group-nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool
make all
sudo make install
sudo make install-webconf
make install-config
make install-init
配置PNP
建立配置檔案misccommands.cfg, nagios.cfg, rra.cfg, check_all_local_disks.cfg, check_nrpe.cfg, check_nwstat.cfg等
執行命令:
cp misccommands.cfg-sample misccommands.cfg
cp nagios.cfg-sample nagios.cfg
cp rra.cfg-sample rra.cfg
進入pages目錄,建立配置檔案web_traffic.cfg
cp web_traffic.cfg-sample web_traffic.cfg
cd ../check_commands
cp check_all_local_disks.cfg-sample check_all_local_disks.cfg
cp check_nrpe.cfg-sample check_nrpe.cfg
cp check_nwstat.cfg-sample check_nwstat.cfg
最後,重啟NPCD服務:
sudo /etc/init.d/npcd restart
修改nagios server配置檔案
修改nagios.cfg檔案:
sudo vim /usr/local/nagios/etc/nagios.cfg
process_performance_data=0
#修改為
rocess_performance_data=1
#開啟註釋
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
修改/usr/local/nagios/etc/objects/commonds.cfg:
增加下面內容:
#ss-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
# 'process-service-perfdata' command definition
define command{
command_name process-service-
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
修改 /usr/local/nagios/etc/objects/templates.cfg:
新增:
define host {
name hosts-pnp
register 0
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$
}
define service {
name services-pnp
register 0
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
}
修改vim /usr/local/nagios/etc/objects/services.cfg:
所有服務引用services-pnp服務,例如:
define service{
use local-service,services-pnp
host_name nagios1
service_description Current Load
check_command check_nrpe!check_load
}
最後,重啟nagios server
配置pnp4nagios虛擬目錄
執行命令: vi /usr/local/apache2/conf/httpd.conf,在文件末尾新增:
Alias /pnp4nagios "/usr/local/pnp4nagios/share"
<Directory "/usr/local/pnp4nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require