1. Nagios安裝 - 服務端
安裝擴展YUM源(2個都可以,但是epel-release只有6.7版本纔可以,6.7以前版本不支持)
[root@localhost ~]# yum install -y epel-release
[root@localhost ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo
安裝nagios服務以及相關支持服務:
[root@localhost ~]# yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe
創建用戶和密碼
[root@localhost ~]# htpasswd -c /etc/nagios/passwd nagiosadmin
檢測配置文件
[root@localhost ~]# nagios -v /etc/nagios/nagios.cfg
上圖表示 配置正確 沒有問題
啓動服務:
檢測一下:
瀏覽器訪問: http://ip/nagios
如果沒有得到上面的結果,請檢查selinux和iptables,輸入上面建立的用戶名和密碼
可以看到我安裝的版本是3.5.1。
2. Nagios安裝 - 客戶端
安裝擴展YUM源(2個都可以,但是epel-release只有6.7版本纔可以,6.7以前版本不支持)
[root@localhost ~]# yum install -y epel-release
[root@localhost ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo
安裝nagios客戶端服務
[root@localhost ~]# yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe
編輯配置文件
[root@localhost ~]# vim /etc/nagios/nrpe.cfg
找到“allowed_hosts=127.0.0.1” 改爲 “allowed_hosts=192.168.1.201”
allowed_hosts=192.168.1.201 定義服務器主機
找到” dont_blame_nrpe=0” 改爲 “dont_blame_nrpe=1”
dont_blame_nrpe=1
啓動服務
[root@localhost ~]# /etc/init.d/nrpe start
3. 監控中心(192.168.1.201)添加被監控主機(192.168.1.202)
編輯被監控主機配置文件
[root@localhost ~]# cd /etc/nagios/conf.d/
[root@localhost conf.d]# vim 192.168.1.202.cfg
define host{
use linux-server
host_name 192.168.1.202
alias 1.202
address 192.168.1.202
}
define service{
use generic-service
host_name 192.168.1.202
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.202
service_description check_ssh
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
notification_interval 60
define service{
use generic-service
host_name 192.168.1.202
service_description check_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。
檢測配置文件:
[root@localhost conf.d]# nagios -v /etc/nagios/nagios.cfg
重啓服務:
去web查看一下監控情況
4--監控客戶端硬盤,內存情況
#由於需要nagios調用的監控命令都需要在command.cfg模塊中定義 而前面的check_nrpe在默認的command.cfg中時沒有的
這裏需要在command.cfg中將其加入進去 現在去服務器端編輯/objects/commands.cfg
[root@nagios conf.d]# vim /etc/nagios/objects/commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
定義check_nrpe編輯文件添加下面內容:
在服務器端配置被監控端的配置文件:
[root@localhost conf.d]# cd /etc/nagios/conf.d/
[root@localhost conf.d]# vim 192.168.1.202.cfg
define service{
use generic-service
host_name 192.168.1.88
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.88
service_description check_disk_hda1
check_command check_nrpe!check_hda1
max_check_attempts 5
normal_check_interval 1
}
客戶端查看check_load,check_hda1服務
[root@localhost ~]# df -h
[root@localhost ~]# vi /etc/nagios/nrpe.cfg
查看一下已經監控到了 ok