您好,登錄后才能下訂單哦!
Nagios監控工具
不會顯示具體的值,僅顯示主機或服務的狀態
強大的報警功能
高度插件化
Nagios監控主機/服務顯示的4種狀態
OK
WARNING
CRITICAL
UNKNOWN
Nagios對象:
主機,主機組
服務/資源,服務組
聯系人,聯系人組
時間段
命令(模板--->應用到某個被監控對象,以實現監控)
Nagios實現監控的方式:
check_by_ssh
check_by_nrpe:專用于監控Linux或Unix主機
check_by_nsclient++:用于監控Windows主機
check_by_snmp
check_by_nsca:實現被動方式的nagios,由被監控對象主動向nagios發送狀態信息
check_by_xyz:自定義監控方式/腳本
安裝nagios
1、安裝依賴的軟件
# yum install -y httpd php php-mysql mysql-devel mysql
2、創建nagios運行需要的用戶和組
# groupadd nagcmd
# useradd -G nagcmd nagios
將運行apache進程的用戶加入到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
創建一個登錄nagios web頁面的用戶,這個用戶賬號在以后通過web登錄nagios時使用
# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
啟動httpd服務
# 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服務
# chkconfig --add nagios
# service nagios start
6、訪問nagios
http://10.1.1.2/nagios
配置nagios
nagios配置文件保存在/etc/nagios目錄下
nagios插件目錄
/usr/local/nagios/libexec
nagios監控windows主機
SNMP
NSClient++
nagios通過check_nt插件與windows NSClient++通信
NSClient++可提供check_nt,check_nrpe及NSCA的能力
NSClient++監聽在12489/tcp端口與check_nt插件通信
配置check_nt與NSClient++監控windows主機
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、定義主機host及服務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、啟用主機配置文件
# vim /etc/nagios/nagios.cfg
cfg_file=/etc/nagios/objects/windows.cfg
4、檢測配置文件語法,并重啟nagios服務
# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg
# service nagios restart
瀏覽器訪問http://10.1.1.2/nagios查看監控狀態數據
配置check_nrpe監控Linux及windows主機
監控端通過check_nrpe與被監控端nrpe進程通信
nrpe監聽在5666/tcp端口
監控端、被監控端都需要安裝nrpe addon,被監控端需要啟動nrpe服務
一、監控Linux 主機10.1.1.1
1、在被監控主機上安裝nrpe并配置
1)創建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
定義監控本地資源的命令
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服務腳本
# 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、在監控端安裝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目錄下會產生check_nrpe插件
通過以下命令可測試插件是否工作正常
# ./check_nrpe -H 10.1.1.1
NRPE v2.15
3、配置監控Linux主機
1)定義命令command
# vim /etc/nagios/objects/commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
2)定義主機host及服務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
!后面為被監控端定義好的命令名稱
3)啟用主機配置文件
# vim /etc/nagios/nagios.cfg
cfg_file=/etc/nagios/objects/linux.cfg
4)檢測配置文件語法,并重啟nagios服務
# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg
# service nagios restart
在10.1.1.1上分別安裝web及mysql服務,配置監控端10.1.1.2監控這兩個服務
1、在10.1.1.1上安裝web及mysql
# yum install -y httpd mysql-server
需要在mysql服務器上創建允許遠程登錄的用戶
2、編輯command.cfg分別定義監控web及mysql服務的命令
# 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服務
# 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服務
# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg
# service nagios restart
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。