Nagios4.3.1監控Centos6.7

上一篇Nagios監控windows中已經寫到Nagios的安裝過程,這裏不再重複。



基於NPRE檢測linux

在linux主機上安裝NRPE,並通過5666端口讓服務端check_nrpe跟NRPE進行通訊

NRPE(Nagios Remote Plugin Executor)是用於在遠端服務器上運行檢測命令的守護進程,他用於讓Nagios監控端基於安裝的方式觸發遠端主機上的檢測命令,並將檢測結果輸出至監控端,而其執行的開銷遠低於基於SSH的檢測方式,而且檢測過程並補需要遠程主機上的系統賬號等信息,其按期性也高於SSH的檢測方式

安裝前準備
調整系統時間
下載nagios-plugins-2.2.1.tar.gz
https://www.nagios.org/downloads/nagios-plugins/
下載nrpe-3.1.0.tar.gz

=============================================================
配置被監控端Nagios Client

1. 安裝nrpe和nagios插件
[root@client ~]# yum install openssl openssl-devel xinetd gcc make

[root@client ~]# useradd nagios
[root@client ~]# tar xvf nagios-plugins-2.2.1.tar.gz
[root@client ~]# cd nagios-plugins-2.2.1
[root@client nagios-plugins-2.2.1]# ./configure && make && make install

[root@client ~]# tar xvf nrpe-2.13.tar.gz
[root@client ~]# cd nrpe-2.13
[root@client nrpe-2.13]# ./configure && make && make install
[root@client nrpe-2.13]# make install-daemon-config
[root@client nrpe-2.13]# make install-xinetd
[root@client nrpe-2.13]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
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
only_from = 127.0.0.1 10.200.1.23    //10.200.1.23 爲nagios監控中心地址    #而且中間必須是空格
}
wKiom1lLX1jBE5GnAABJ23cdj8A115.jpg[root@client nrpe-2.12]# vim /etc/services
nrpe 5666/tcp # NRPE //添加該行
[root@client nrpe-2.13]# service xinetd restart
[root@client nrpe-2.13]# chkconfig xinetd on          #添加開機自啓動
[root@client nrpe-2.13]# chkconfig --list xinetd     #查看2345是否on

[root@client nrpe-2.13]# netstat -tunpl | grep 5666
tcp        0      0 :::5666                     :::*                        LISTEN      2818/xinetd   
wKioL1lLXvLzJXD5AAAZG5claE4175.jpg
2. 配置監控本地私有資源
[root@client nrpe-2.12]# vim /usr/local/nagios/etc/nrpe.cfg
command[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_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/vg01-lv_root
command[check_home]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/vg01-lv_home
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
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 50% -c 40%
[root@client ~]# service xinetd restart

開放5666端口並重啓防火牆
[root@localhost /]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
wKioL1lLhfqwO-IFAABqgtLbHfc701.jpg

[root@localhost /]# service iptables restart

[root@localhost ~]# netstat -tnlp     查看監聽端口5666端口上已經開啓了xinetd服務

wKiom1lLhoTzW4wVAACOqQ4ycy0580.jpg


========================================================
配置監控中心Nagios Server
1. 安裝nrpe插件並測試
[root@master ~# tar xvf nrpe-2.13.tar.gz //僅需要check_nrpe插件
[root@master nrpe-2.13]# ./configure && make all && make install
[root@master ~]# /usr/local/nagios/libexec/check_nrpe -H 10.200.1.24
NRPE v2.13


定義主機和定義服務
[root@linyangjun local]# cd /etc/nagios/
編輯nagiios.cfg
增加cfg_file=/etc/nagios/objects/centos6.cfg  保存後退出
wKiom1lLii3DsYr_AACasnT4rNM249.jpg切換到[root@linyangjun nagios]# cd objects/
[root@linyangjun objects]# vim cnetos6.cfg          #新增centos6.cfg 文件
填入內容:
# Define a host for the local machine

define host{
use linux-server
host_name Centos6                                   #監控端顯示名稱            
alias web-10.200.1.24
address 10.200.1.24                                 #被監控端IP  
}

# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use local-service
host_name Centos6
service_description Root Partition
check_command check_nrpe!check_root
}

# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free
define service{
use local-service
host_name Centos6
service_description Swap Usage
check_command check_nrpe!check_swap
}

# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use local-service
host_name Centos6
service_description Total Processes
check_command check_nrpe!check_total_procs
}

#保存後退出

/usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg   #可驗證語法是否錯誤


測試通過之後重啓nagios服務

#service nagios restart

wKioL1lLkJ6w8JOkAAA4KKzF4rY651.jpg


在/usr/local/nagios/libexec 下,使用cher_nrpe -H 10.200.1.24 測試鏈接,顯示版本號表示鏈接正常

wKioL1lLlV6RuZ7NAAAhXViLuI8144.jpg



重啓完畢打開監控web界面,登錄之後可以看到centos6已經在監控列表中

wKiom1lLkSfRPKqGAAKFP1YOA_I839.jpg-wh_50




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章