nagios 服務端配置
環境要求
nagios 也需要 apache+php 的環境,CentOS7.5 預設的 yum 源裡沒有 nagios 相關的 rpm 包,是以要安裝一個 epel 的擴充源。
安裝 nagios 相關包
設定登入 nagios 背景的使用者和密碼
[[email protected] ~]# htpasswd -c /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
檢查配置檔案是否有問題
[[email protected] ~]# nagios -v /etc/nagios/nagios.cfg
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
浏覽器通路:http://ip/nagios
輸入使用者名nagiosadmin,密碼是手動設定的密碼
此時,nagios 監控的隻有 localhost,還沒有其他用戶端機器,要想添加監控客戶機,還需要在用戶端安裝 nagios 相關的軟體包,并且需要在服務端配置。
nagios 監控用戶端
配置用戶端
安裝 epel 擴充源
安裝 nagios 以及 nagios-plugins
編輯配置檔案
[[email protected] ~]# vim /etc/nagios/nrpe.cfg
找到“allowed_hosts=127.0.0.1”改為“allowed_hosts=127.0.0.1,172.30.15.10”後面的 ip 為服務端 ip
找到“dont_blame_nrpe=0”改為“dont_blame_nrpe=1”
allowed_hosts=127.0.0.1,172.30.15.10
dont_blame_nrpe=1
啟動用戶端
/usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
服務端配置:
用戶端 ip 為 172.30.15.4,下面定義子配置檔案。
[[email protected] ~]# vim /etc/nagios/nagios.cfg
cfg_file=/etc/nagios/objects/172.30.15.10.cfg //添加内容
[[email protected] ~]# cd /etc/nagios/objects/
[[email protected] objects]# vim 172.30.15.4.cfg
define host{
use linux-server
host_name 172.30.15.4
alias 172.30.15.4
address 172.30.15.4
}
define service{
use generic-service
host_name 172.30.15.4
service_description load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name 172.30.15.4
service_description 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 172.30.15.4
service_description FTP
check_command check_ftp!21
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 172.30.15.4
service_description SSH
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 172.30.15.4
service_description HTTP
check_command check_http
max_check_attempts 5
normal_check_interval 1
}
說明:“max_check_attempts 5”表示,當 nagios 檢測到問題時,一共嘗試檢測 5 次都有問題才會告警,如果該數值為 1,那麼檢測到問題就立即告警。“normal_check_interval 1”表示,重新檢測的時間間隔,機關是分鐘,預設是 3 分鐘。“notification_interval 60”表示,在服務出現異常後,故障一直沒有解決,nagios 再次對使用者發出通知的時間,機關是分鐘。如果認為所有的事件隻需要一次通知就夠了,可以把這裡的選項設為 0。
以上服務不依賴用戶端 nrpe 服務,比如我們在自己電腦上可以使用 ping 或者 telnet 探測遠端任何一台機器是否存活、是否開啟某個端口或服務。而當檢測用戶端上的某個具體服務的情況時,就需要借助于 nrpe 了,比如想知道用戶端機器的負載或磁盤使用情況。
編輯完配置檔案後,在服務端重新開機一下 nagios 服務。
然後在浏覽器中通路 nagios→“Current Status”→“Services”,重新整理會多出來一個主機,并且多出來三個服務。
隻不過這三個服務并不是我們想要的,我想要監控負載和磁盤使用率等服務,這時候就要使用 nrpe 服務了。繼續在服務端添加服務。
服務端配置
編輯配置檔案
[[email protected] ~]# vim /etc/nagios/objects/commands.cfg
文檔最後添加
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
編輯配置檔案
[[email protected] ~]# vim /etc/nagios/objects/172.30.15.4.cfg
}
define service{
use generic-service
host_name 172.30.15.4
service_description load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name 172.30.15.4
service_description 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 172.30.15.4
service_description SSH
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 172.30.15.4
service_description check_disk_hda1
check_command check_nrpe!check_hda1
max_check_attempts 5
normal_check_interval 1
}
用戶端操作
(!!!以下用戶端操作)
在遠端主機上編輯 nrpe.cfg 配置檔案
[[email protected] ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
[[email protected] ~]# vim /etc/nagios/nrpe.cfg
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/vda1
用戶端重新開機 nrpe 服務
服務端重新開機 nagios 服務
浏覽器重新整理,又有三個服務出來,稍等一會兒就能看到狀态了。
利用NSClient++監控Window 7主機
修改配置檔案
[[email protected] ~]# vim /etc/nagios/objects/windows.cfg
define host {
use windows-server ; Inherit default values from a template
host_name winserver ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 172.30.15.3 ; IP address of the host
}
編寫配置檔案
echo "cfg_file=/etc/nagios/objects/windows.cfg" >> /etc/nagios/nagios.cfg
下載下傳NSClient++軟體安裝至Windows7主機
連結:https://pan.baidu.com/s/1FNTLX_cvl_wsUmbSYOd32Q
提取碼:1234
安裝完成後修改配置檔案
啟動這個軟體并關閉windows防火牆
測試連接配接(服務端執行)
[[email protected] ~]# /usr/lib64/nagios/plugins/check_nt -H 172.30.15.3 -p 12489 -v UPTIME
System Uptime - 0 day(s) 10 hour(s) 39 minute(s) |uptime=639
重新開機服務端服務
檢視監控頁面