溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Nagios監(jiān)控工具

發(fā)布時間:2020-06-18 15:47:06 來源:網(wǎng)絡(luò) 閱讀:659 作者:冷暖己知 欄目:移動開發(fā)

Nagios監(jiān)控工具

不會顯示具體的值,僅顯示主機(jī)或服務(wù)的狀態(tài)

強(qiáng)大的報警功能

高度插件化


Nagios監(jiān)控主機(jī)/服務(wù)顯示的4種狀態(tài)

OK

WARNING

CRITICAL

UNKNOWN

Nagios對象:

主機(jī),主機(jī)組

服務(wù)/資源,服務(wù)組

聯(lián)系人,聯(lián)系人組

時間段

命令(模板--->應(yīng)用到某個被監(jiān)控對象,以實現(xiàn)監(jiān)控)


Nagios實現(xiàn)監(jiān)控的方式:

check_by_ssh

check_by_nrpe:專用于監(jiān)控Linux或Unix主機(jī)

check_by_nsclient++:用于監(jiān)控Windows主機(jī)

check_by_snmp

check_by_nsca:實現(xiàn)被動方式的nagios,由被監(jiān)控對象主動向nagios發(fā)送狀態(tài)信息

check_by_xyz:自定義監(jiān)控方式/腳本

安裝nagios


1、安裝依賴的軟件

# yum install -y httpd php php-mysql mysql-devel mysql 


2、創(chuàng)建nagios運(yùn)行需要的用戶和組

# groupadd nagcmd

# useradd -G nagcmd nagios


將運(yùn)行apache進(jìn)程的用戶加入到nagcmd組中

# usermod -a -G nagcmd apache

3、安裝nagios

# tar zxf nagios-3.3.1.tar.gz 

# cd nagios

# ./configure --with-command-group=nagcmd --enable-event-broker --sysconfdir=/etc/nagios

# make all

# make install

# make install-init

# make install-commandmode

# make install-config

#  make install-webconf

創(chuàng)建一個登錄nagios web頁面的用戶,這個用戶賬號在以后通過web登錄nagios時使用

# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin

New password: 

Re-type new password: 

Adding password for user nagiosadmin



啟動httpd服務(wù)

# service httpd start



4、安裝nagios-plugins插件


# tar zxf nagios-plugins-1.5.tar.gz 

# cd nagios-plugins-1.5

# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

# make && make install


5、啟動nagios服務(wù)

# chkconfig --add nagios

# service nagios start 

6、訪問nagios

http://10.1.1.2/nagios

配置nagios

nagios配置文件保存在/etc/nagios目錄下

nagios插件目錄

/usr/local/nagios/libexec

nagios監(jiān)控windows主機(jī)

SNMP

NSClient++

nagios通過check_nt插件與windows NSClient++通信

NSClient++可提供check_nt,check_nrpe及NSCA的能力

NSClient++監(jiān)聽在12489/tcp端口與check_nt插件通信

配置check_nt與NSClient++監(jiān)控windows主機(jī)


1、定義命令command

# vim /etc/nagios/objects/commands.cfg 


define command{

        command_name    check_nt

        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$

        }


2、定義主機(jī)host及服務(wù)service

# vim /etc/nagios/objects/windows.cfg 


define host{

        use             windows-server  ; Inherit default values from a template

        host_name       winhost; The name we're giving to this host

        alias           My Windows Server       ; A longer name associated with the host

        address         10.1.1.254      ; IP address of the host

        }


define service{

        use                     generic-service

        host_name               winhost

        service_description     Uptime

        check_command           check_nt!UPTIME

        }

   

3、啟用主機(jī)配置文件

# vim /etc/nagios/nagios.cfg 

cfg_file=/etc/nagios/objects/windows.cfg


4、檢測配置文件語法,并重啟nagios服務(wù)

# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg 

# service nagios restart

瀏覽器訪問http://10.1.1.2/nagios查看監(jiān)控狀態(tài)數(shù)據(jù)

配置check_nrpe監(jiān)控Linux及windows主機(jī)


監(jiān)控端通過check_nrpe與被監(jiān)控端nrpe進(jìn)程通信

nrpe監(jiān)聽在5666/tcp端口 

監(jiān)控端、被監(jiān)控端都需要安裝nrpe addon,被監(jiān)控端需要啟動nrpe服務(wù)

一、監(jiān)控Linux 主機(jī)10.1.1.1

1、在被監(jiān)控主機(jī)上安裝nrpe并配置


1)創(chuàng)建nagios用戶

# useradd -s /sbin/nologin nagios


2)nrpe依賴于nagios-plugins,安裝nagios-plugins 

# tar zxf nagios-plugins-1.4.14.tar.gz 

# cd nagios-plugins-1.4.14

# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

# make all

# make install



3)安裝nrpe

# tar zxf nrpe-2.15.tar.gz  

# cd nrpe-2.15

# ./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



4)配置nrpe

# vim /usr/local/nagios/etc/nrpe.cfg 


log_facility=daemon

pid_file=/var/run/nrpe.pid

server_port=5666

server_address=10.1.1.1

nrpe_user=nagios

nrpe_group=nagios

allowed_hosts=10.1.1.2

command_timeout=60


定義監(jiān)控本地資源的命令

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_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1

command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2

command[check_sda3]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3

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 



5)編寫啟動nrpe服務(wù)腳本

# vim /etc/rc.d/init.d/nrpe

#!/bin/bash

#

# chkconfig: 2345 88 12

# description: NRPE DAEMON

NRPE=/usr/local/nagios/bin/nrpe

NRPECONF=/usr/local/nagios/etc/nrpe.cfg


case $1 in

  start)

    echo -n "Starting NRPE damon...."

    $NRPE -c $NRPECONF -d

    echo "Done..."

    ;;

  stop)

    echo -n "Stopping NRPE daemon...."

    pkill -u nagios nrpe

    echo "Done...."

    ;;

  restart)

    $0 stop

    sleep 2

    $0 start

    ;;

  *)

   echo "Usage: $0 { start | stop | restart }"

   ;;

esac

exit 0


# chmod +x /etc/rc.d/init.d/nrpe

# chkconfig --add nrpe

# service nrpe start

# netstat -tnlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   

tcp        0      0 10.1.1.1:5666               0.0.0.0:*                   LISTEN      6826/nrpe           



2、在監(jiān)控端安裝nrpe


1)安裝nrpe 

# tar zxf nrpe-2.15.tar.gz 

# cd nrpe-2.15

# ./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


安裝完成后,在/usr/local/nagios/libexec目錄下會產(chǎn)生check_nrpe插件

通過以下命令可測試插件是否工作正常

# ./check_nrpe -H 10.1.1.1

NRPE v2.15


3、配置監(jiān)控Linux主機(jī)


1)定義命令command

# vim /etc/nagios/objects/commands.cfg 

define command{

        command_name    check_nrpe

        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}


2)定義主機(jī)host及服務(wù)service

# cp /etc/nagios/objects/windows.cfg /etc/nagios/objects/linux.cfg

# vim /etc/nagios/objects/linux.cfg


define host{

use linux-server ; Inherit default values from a template

host_name linuxhost; The name we're giving to this host

alias My Linux Server ; A longer name associated with the host

address 10.1.1.1 ; IP address of the host

}


define service{

use generic-service

host_name linuxhost

service_description Users

check_command check_nrpe!check_users

}


define service{

use generic-service

host_name linuxhost

service_description Load

check_command check_nrpe!check_load

}


define service{

use generic-service

host_name linuxhost

service_description SDA1

check_command check_nrpe!check_sda1

}


define service{

use generic-service

host_name linuxhost

service_description SDA2

check_command check_nrpe!check_sda2

}


define service{

use generic-service

host_name linuxhost

service_description SDA3

check_command check_nrpe!check_sda3

}



define service{

use generic-service

host_name linuxhost

service_description Zombie procs

check_command check_nrpe!check_zombie_procs

}


define service{

use generic-service

host_name linuxhost

service_description total procs

check_command check_nrpe!check_total_procs

}



check_nrpe!check_total_procs

!后面為被監(jiān)控端定義好的命令名稱

3)啟用主機(jī)配置文件

# vim /etc/nagios/nagios.cfg 

cfg_file=/etc/nagios/objects/linux.cfg

4)檢測配置文件語法,并重啟nagios服務(wù)

# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg

# service nagios restart


在10.1.1.1上分別安裝web及mysql服務(wù),配置監(jiān)控端10.1.1.2監(jiān)控這兩個服務(wù)


1、在10.1.1.1上安裝web及mysql

# yum install -y httpd mysql-server 


需要在mysql服務(wù)器上創(chuàng)建允許遠(yuǎn)程登錄的用戶


2、編輯command.cfg分別定義監(jiān)控web及mysql服務(wù)的命令

# vim /etc/nagios/objects/commands.cfg 


define command{

        command_name    check_http

        command_line    $USER1$/check_http -I $HOSTADDRESS$ $ARG1$

        }

define command{

        command_name    check_mysql

        command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$

        }

3、編輯linux.cfg配置文件,定義web及mysql服務(wù)

# vim /etc/nagios/objects/linux.cfg 


define service{

        use                     generic-service

        host_name               linuxhost

        service_description     Web Server

        check_command           check_http

        }


define service{

        use                     generic-service

        host_name               linuxhost

        service_description     Mysql Server

        check_command           check_mysql!admin!redhat

        }

4、檢測配置文件語法,并重啟nagios服務(wù)

# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg 

# service nagios restart


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI