nagios

cacti:
監控工具
收集數據,根據數據繪圖
cpu load:0.8 1.2
thold

nagios
監控工具
主機,服務/資源
ok,warnging,critical,unknown
cpu:90%{critical},80%(warning),ok
unknown
報警系統

nagios core:
本身不做任何監控工作
都是由插件(plugins)來做監控的
plugins(scripts),check_nginx
N種對象實現監控工作:
主機,主機組
服務/資源,服務組
聯繫人,聯繫人組
時段
命令(模板--》應用到某個被監控對象,以實現具體的監控)

N主機
Linux
多個被監控對象,如果有很多屬相同的時候
template

插件:check_by_ssh,check_nrpe,snmp,NSCA

安裝nagios:
yum install httpd php mysql-devel php-mysql

groupadd nagcmd
useradd -G nagcmd nagios
usermod -a -G nagcmd apache

tar -zxvf nagios-3.3.1.tar.gz
cd nagios
./configure --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
service httpd start

安裝插件
tar -zxvf 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

service nagios start

http://172.16.100.1/nagios/

cd /etc/nagios
cd objects
vim nagios.cfg
vim resource.cfg
cd /usr/local/nagios/libexec/
vim command.cfg
vim contact.cfg
vim timeperiods.cfg
vim localhost.cfg:其中有!後面跟一些字符,表示是一個參數,向command.cfg中的命令傳遞(傳到$ARER$,這樣的字符)

宏:變量:$USER1$
resource.cfg用來定義宏文件

基於NSClinet++遠程監控windows主機(172.16.100.66)

首先在windows上面安裝NSClinet++,然後填寫監控主機的ip地址(172.16.100.1),密碼不要寫,其中modules to load中全部勾選,監聽端口爲12489,5666

在172.16.100.1上面:cd
在命令行執行監控
/usr/local/nagios/libexec/
./check_nt -H 172.16.100.66 -p 12489 -v UPTIME
./check_nt -H 172.16.100.66 -p 12489 -v CPULOAD -w 80 -c 90 -l 5,80,90
./check_nt -H 172.16.100.66 -p 12489 -v USEDDISKSAPCE -w 80 -c 90 -l 90 C

在配置文件中配置
cd objects
定義命令:vim commands.cfg
define command {
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
}

定義主機:vim windows.cfg
define host {
use windows-server
host_name winhost
alias my windows host
address 172.168.100.66
}

define service{
use generic-service
host_name winhost
service_description Uptime
check_command check_nt!UPTIME
}

define service{
use generic-service
host_name winhost
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90

所有的host_name都要改成winhost

定義啓用上述的配置文件:vim nagios.cfg
cfg_file=/etc/nagios/objects/windows.cfg

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

service nagios restart

基於nrpe監控遠程Linux主機:

安裝配置被監控端(172.16.100.11):
yum -y groupinstall "Development Tools" "Development Libraries"

tar -zxvf nagios-plugins-1.4.15.tar.gz
useradd -s /sbin/nologin nagios
cd nagios-plugins
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install

tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12.tar.gz
./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

vim /usr/local/nagios/nrpe.cfg
allowed_hosts=172.16.100.1
command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2

啓動腳本:vim /etc/init.d/nrped
#! /bin/bash

chkconfig: 2345 88 12

description: NRPE DAEMON

NRPE=/usr/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 "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

service nrped start

在監控端(172.16.100.1):
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 /sur/local/nagios/libexec
./check_nrpe -H 172.16.100.11

cd /etc/nagios/objects

vim command.cfg
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

vim linhost.cfg
define host{
use linux-server
host_name linhost
alias my linux host
address 172.16.100.11
}

define service{
use generic-service
host_name linhost
service_description CHECK USERS
check_command check_nrpe!check_users(這裏填的是被監控端所命的名)
}

define service{
use generic-service
host_name linhost
service_description LOAD
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name linhost
service_description SDA1
check_command check_nrpe!check_sda1
}

define service{
use generic-service
host_name linhost
service_description SDA2
check_command check_nrpe!check_sda2
}

define service{
use generic-service
host_name linhost
service_description ZOMBIE PROCS
check_command check_nrpe!check_zombie_procs
}

define service{
use generic-service
host_name linhost
service_description TOTAL PROCS
check_command check_nrpe!check_total_procs
}

vim nagios.cfg
cfg_file=/etc/nagios/objects/linhost.cfg

service nagios restart

基於nrpe實現監控windows被監控端:

在安裝NSClien++目錄中找到NSC,並用記事本或者寫字板打開

在cmd中啓動服務:
先切換到NSClien++目錄下執行nsclient++.exe /start

在監控端:
./check_nrpe -H 172.16.100.66 -c checkCPU -a warn=80 crit=90 time=20 time=10 time=5

監控windows端http服務狀態
cd /usr/local/nagios/libexec
./check_http -H 172.16.100.66

cd /etc/nagios
cd objects
vim command.cfg
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $RAG1$

define cmmand{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p$ARG2$

vim windows.cfg
define service{
use generic-service
host_name winhost
service_description web server
check_cmmand check_http
}

define service{
use generic-service
host_name winhost
service_description mysql server
check_cmmand check_http!root!magedu
}

service nagios restart

Fetion:飛信用來接收報警信息的
在飛信機器人網站中下載
mv linuxso_20101113 /usr/local/fetion
vim /etc/ld.so.conf.d/fetion.conf
/usr/local/fetion

ldconfig

vim /etc/ld.so.conf.d/fetion.conf:此目錄下是定義要加載的各種模塊
使用ldconfig 立即生效

使用飛信發信息
/usr/local/fention/fetion --mobile=18827018530 --pwd=chenjiao --to=13607693077 --msg-utif8=“fetion test message”

將飛信整合到nagios中的聯繫人中
vim command.cfg
define command {
command_name notify-host-by-fetion
command_line fetion --mobile=18827018530 --pwd=chenjiao --msg-utif8=“$NOTIFICATIONTYPE$ Host:$HOSTNAME$ State:$HOSTSTATE$ Address:$HOSTADDRESS$ ” --to=$CONTACTPAGER$

define command {
command_name notify-service-by-fetion
command_line fetion --mobile=18827018530 --pwd=chenjiao --msg-utif8=“$NOTIFICATIONTYPE$ Host:$HOSTNAME$ State:$HOSTSTATE$ Address:$HOSTADDRESS$ ” --to=$CONTACTPAGER$

vim contact.cfg
define contact{
contact_name nagiosadmin
use generic-contact
alias nagios admin
email mage@localhost
pager 13080610944
}

vim templates.cfg
define contact{
name generic-contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options
service_notification_commands notify-service-by-fetion,notify-service-by-email
host-notification-commands notify-host-by-fetion,notify-host-by-email
register 0
}

service nagios restart

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