標籤:nagios nrpe
一、安裝 nagios
yum install -y epel-release
yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe
(其中httpd作為nagios的web端介面)
還可以通過httpd的工具來產生nagios的登入密碼:
htpasswd -c /etc/nagios/passwd nagiosadmin
檢測設定檔是否有問題:
nagios -v /etc/nagios/nagios.cfg
啟動服務:
service httpd start
service nagios start
瀏覽器訪問:
httpd://ip/nagios
二、nagios 監控用戶端
需要在用戶端機器上安裝nagios服務:
yum install -y epel-release
yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe
開啟設定檔/etc/nagios/nrpe.cfg
找到“allowed_hosts=127.0.0.1”改為“allowed_hosts=127.0.0.1,192.168.1.11”後面ip為服務端ip
找到“dont_blame_nrpe=0”改為“dont_blame_nrpe=1”
啟動服務:
service nrpe start
三、nagios 服務端配置
開啟檔案/etc/nagios/nagios.cfg,找到“cfg_dir”,這是定義監控檔案的存放目錄,我們可以定義很多個目錄,以後把新增加的主機資訊檔全部放到這裡。
在我們定義的目錄下,建立子設定檔,添加被監控主機資訊:
cd /etc/nagios/conf.d/
vim 192.168.1.12.cfg
define host{
use linux-server
host_name 192.168.1.12
alias 192.168.1.12
address 192.168.1.12
}
define service{
use generic-service
host_name 192.168.1.12
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.12
service_description check_ssh
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.1.12
service_description check_http
check_command check_http
max_check_attempts 5
normal_check_interval 1
}
##注 意,這 裡的IP是client端的IP,監控的項目有三個ping, ssh, http。其實這三個項目使用的指令碼都為本地指令碼,也就是說,即使遠程主機沒有安裝nagios和nrpe同樣可以監控這些項目。但是如果想監控load,disk,等等就需要通過nrpe服務來搞定了,道理很簡單,load和disk都需要登入到遠程主機上去獲得資訊,而ping,ssh,http都不需要的。這個到遠程主機擷取相關的資訊的過程是由nrpe完成的。如果你的client上沒有啟動nrpe服務那麼我們是無法擷取遠程主機的load和disk等資訊的。下面筆者配置一下使用nrpe來監控遠程主機的相關項目。
在server端編輯/etc/nagios/objects/commands.cfg
在檔案的最後添加一行內容:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
繼續修改子設定檔
cd /etc/nagios/conf.d/
vim 192.168.1.12.cfg #添加如下內容
define service{
use generic-service
host_name 192.168.1.12
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.1.12
service_description check_disk_hda1
check_command check_nrpe!check_hda1
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.1.12
service_description check_disk_hda2
check_command check_nrpe!check_hda2
max_check_attempts 5
normal_check_interval 1
}
##這裡需要解釋一下相關的“check_command”, 先看這個“check_nrpe!check_load” 這裡的check_nrpe就是上面/usr/local/nagios/etc/objects/commands.cfg中剛剛定義的,後面的check_load是在遠程主機上定義的一個命令指令碼。具體在哪裡定義稍後介紹。為什麼中間加個”!”,這個是nagios特有的形式,無需關心。下面需要到遠程主機上去定義上面用到的指令碼了。
服務端重啟服務:
service nagios restart
用戶端重啟服務:
service nrpe restart
四、在nagios用戶端自訂指令碼監控
將監控指令碼寫完之後,拷貝到/usr/lib64/nagios/plugins/目錄下,當然此目錄在設定檔/etc/nrpe.d/check_log2s3.cfg中已經定義。
vim /etc/nrpe.d/check_log2s3.cfg
command[check_log2S3]=sudo /usr/lib64/nagios/plugins/logmonitoring.sh
##當然,這些內容可以直接寫進/etc/nagios/nrpe.cfg中,但是不方便進行管理,因此我們可以在/etc/nrpe.d/目錄中將每個監控指令碼的服務獨立出來。
重啟用戶端服務:
service nrpe restart
到服務端上添加相應的service:
vim 192.168.1.12.cfg
##加入如下內容
define service{
use generic-service
host_name 192.168.1.12
service_description check_logs3
check_command check_nrpe!check_logs3
max_check_attempts 5
normal_check_interval 1
}
重啟服務端服務:
service nagios restart
本文出自 “奇蹟的少年” 部落格,請務必保留此出處http://raffaelexr.blog.51cto.com/8555551/1853676
nagios 配置和使用