nagios不檢測任何具體數值指示(如操做系統上的進程個數),它只描述四種被監控對象的狀態:OK,WARNING,CRITICAL和UNKNOWN。因而,咱們只須要對魔種監控對象的WARNING和CRITICAL狀態的閾值進行關注,nagios將閾值傳遞給插件,由插件負責具體對象的監控以及結果分析,其返回四中狀態信息
nagios監控的不一樣對象的不一樣方式
linux/UNIX: SNMP,NRPE,send-nsca
switch: SNMP
print: SNMP
windows: SNMP,NSClient++ :它包含nrpe,nsca的功能
nrpe: 0.0.0.0:5666
須要在nagios以及監控對象上同時安裝nrpe 以及nagios plugins
nsca:
被動模式,由監控對象主動向nagios發送消息
nsclient++: 是一個客戶端,監聽在0.0.0.0:12489
安裝nagios以前的準備
安裝依賴關係:(此處由於須要對mysql進行檢測,因此須要安裝mysql)
# yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server
建立用戶以及組
# groupadd nagcmd
# useradd -G nagcmd nagios
# passwd nagios
將組附加給apache用戶
# usermod -a -G nagcmd apache
編譯安裝nagios
# tar zxf nagios-3.3.1.tar.gz
# cd nagios-3.3.1
# ./configure --with-command-group=nagcmd --enable-event-broker
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# make install-webconf
建立一個登錄nagios web的用戶
# htpasswd -c /usr/local/nagios/etc/htpasswd.user nagiosadmin
以上配置完成後啓動httpd
# service httpd restart
安裝nagios插件(nagios檢測徹底依賴於各類插件)
# tar zxf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
將nagios加入服務並配置爲開機啓動
# chkconfig --add nagios
# chkconfig --level 345 nagios on
檢查配置文件語法是否正確
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
啓動nagios
# service nagios start
關閉selinux或者設置標籤
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin
# chcon -R -t httpd_sys_content_t /usr/local/nagios/share
至此,nagios的安裝完成,能夠經過web進行訪問 http://ip/nagios
基於NRPE監控遠程linux主機
NRPE用於在遠端服務器上運行監測命令的守護進程,它用於讓nagios監控端基於安裝的方式觸發遠端主機上的檢測命令,並將檢測結果輸出至監控端,其執行開銷遠低於ssl,檢測過程不須要遠程主機上的帳號等信息,因此安全性也高於ssh
安裝配置被監控端
添加nagios用戶
# useradd -s /sbin/nologin nagios
NRPE依賴於nagios plugins,須要先安裝
# tar zxf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
安裝NRPE
# tar -zxvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
配置NRPE
# vim /usr/local/nagios/etc/nrpe.conf
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_address=127.0.0.1 ;listener address
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=172.16.10.1 ;nagios server address
command_timeout=60
connection_timeout=300
debug=0
command[cmd_name]=/usr/local/nagios/
啓動NRPE
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
定義一個服務的腳本
vim /etc/rc.d/init.d/nrped
#!/bin/bash
#
# chkconfig: 2345 88 12
# description: NRPE DAEMON
#
. /etc/rc.d/init.d/functions
NRPE=/usr/local/nagios/bin/nrpe
NRPECONF=/usr/local/nagios/etc/nrpe.cfg
case "$1" in
start)
echo -n "Starting NRPE daemon..."
$NRPE -c $NRPECONF -d
echo "done."
;;
stop)
echo -n "Stoping NRPE daemon..."
pkill -u nagios nrpe
echo "done."
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $0 start|stop|restart"
;;
esca
exit 0
服務端配置(nagios監控端)
安裝NRPE
# tar -zxvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
# make all
# make install-plugin
檢測與監控對象間的鏈接是否可用
# cd /usr/local/nagios/libexec/
# ./check_nrpe -H 172.16.100.11
NRPE v2.12php