OK,WARNING,CRITICAL,UNKNOWNphp
CPU:90%(CRITICAL),80%(WARNING),OK,UNKOWmysql
check_nginx linux
1) 主機,主機組ios
2) 服務/資源, 服務組nginx
3) 聯繫人(發送通知),聯繫人組web
4) 時段sql
5) 命令 定義在模板中-> 應用到某個被監控對象,以實現具體的監控apache
Linux多個監控對象,若是有不少屬性相同能夠定義爲模板vim
1) 獲取遠端主機信息windows
2) Linux nrpe ssh
3) Windows NSclient++
4) 被動監控nsca被動監控
yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server
yum install xinetd openssl-devel
groupadd nagcmd
useradd -G nagcmd nagios
passwd nagios
usermod -a -G nagcmd apache
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
tar xf nagios-4.0.8.tar.gz
cd nagios-4.0.8
./configure --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker
make all
make install
make install-init // service
make install-commandmode
make install-config
make install-webconf
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin 建立一個加密文件 參數是用戶名
設置密碼 nagiosadmin
less /etc/httpd/conf.d/nagios.conf
service httpd start
chkconfig httpd on
chkconfig --add nagios
chkconfig nagios on
service nagios start
tar xf nagios-plugins-2.0.tar.gz
ls
cd nagios-plugins-2.0
./configure --with-nagios-user=nagios --with-nagios-group=nagios 注意:此處不適用nagcmd
make
make install
service nagios restart
service httpd restart
/usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg
getenforce
setenforce 0
getenforce
vim /etc/sysconfig/selinux
n cfg_file 須要附加的object目錄下的文件
n cfg_dir 直接包含某個目錄 目錄下的全部文件所有包含進來
n resource.cfg 中信息敏感,$USER1$全局宏變量定義文件,最多支持32個,/usr/local/nagios/libexec/插件所在目錄,
n Command.cfg命令配置文件
u Command_name 和 command_line
u 舉例,-w 警告信息 -c 嚴重信息 -p 檢測多少數據包
u 命令能夠傳遞參數(如何傳遞?)
n Contact.cfg配置聯繫人文件
u Contack_name 全局惟一,名字
u Use 從那個模板繼承
u Alias 別名
u Email email地址
n
Timeperiods.cfg
該主機的配置文件(在/etc/Nagios/object/目錄下新建一個便可)
define host{
use linux-server //引用模板
host_name localhost //全局惟一
alias localhost //別名
address 127.0.0.1 //ip地址
}
define hostgroup{
hostgroup_name linux-servers
alias Linux Servers
members localhost
}
define service{
use local-service
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
-H 自動指定 $ARG1$ $ARG2$ 對應上面!之間的參數
SNMP 和 NSClient++,NSClient支持nrpe,nsca(被動檢測)
查看端口12489(check_nt和NSclient通訊)5666是nrpe端口
先到插件目錄下檢測一下是否能使用
-H ip -p 端口 -v 測試內容 -w -c -l 5,80,90 (過去5分鐘參數,80警告,90緊急)
注意輸出:
通常信息和性能信息。必需要使用|隔開
添加一個新的命令
-l 後面全部都是一個參數
/usr/local/Nagios/bin/Nagios -v /etc/Nagios/Nagios.cfg
Service Nagios restart
Nagios Server使用check_nrpe與被監控端NRPE進程通訊
被監控端必須安裝NRPE,NRPE依賴於nagios-plugins
NRPE默認監聽5666端口
yum -y groupinstall "Development Tools" "Development Libraries
date 0000
useradd -s /sbin/nologin nagios
tar xf nagios-plugins-2.0.tar.gz
./configure --with-nagios-user=nagios --with-nagios-group=nagios 能夠加上--sysconfig=
make all
make install
yum install openssh openssl-devel
tar -zxvf nrpe-nrpe-2-15.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/etc/nrpe.conf
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_address=172.16.100.11 (服務監聽地址,默認0.0.0.0)
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
這個得改allowed_hosts=172.16.100.1 (容許誰來監控)
command_timeout=60
connection_timeout=300
debug=0
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg
vim /etc/init.d/nrped
#!/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 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
或者,也能夠在/etc/xinetd.d目錄中建立nrpe文件,使其成爲一個基於非獨立守護進程的服務,文件內容以下:
service nrpe
{
flags = REUSE
socket_type = stream
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /etc/nagios/nrpe.cfg -i
log_on_failure += USERID
disable = no
}
在被監控端,能夠經過NRPE監控的服務或資源須要經過nrpe.conf文件使用命令進行定義,定義命令的語法格式爲:command[<command_name>]=<command_to_execute>。好比:
command[check_rootdisk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_swap]=/usr/local/nagios/libexec/check_disk -w 40% -c 20%
command[check_sensors]=/usr/local/nagios/libexec/check_sensors
command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 20
command[check_load]=/usr/local/nagios/libexec/check_load -w 10,8,5 -c 20,18,15
command[check_zombies]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_all_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
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
define command
{
command_name check_nrpe
command_line $USER1$/check_nrpe –H "$HOSTADDRESS$" -c $ARG1$
// -H 自動對應hostaddress $ARG1$指定對方執行的命令
}
經過NRPE監控遠程Linux主機要使用chech_nrpe插件進行,其語法格式以下:
check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]
-H 指定主機
-c 指定要在被監控服務器執行的命令
-a 指定參數(可接受多個參數)
編譯nrpe的時候須要增長參數--enable-command-args
修改nrpe.cfg文件中參數dont_blame_nrpe=1
define service
{
use generic-service
host_name linuxserver1,linuxserver2
hostgroup_name linux-servers
service_description SWAP
check_command check_nrpe!check_swap
normal_check_interval 30
}
使用示例3:(重要)
若是還但願在監控遠程Linux主機時還能向其傳遞參數,則可使用相似以下方式進行:
定義監控遠程Linux主機disk資源的命令:
define command
{
command_name check_swap_nrpe
command_line $USER1$/check_nrpe –H "$HOSTADDRESS$" -c "check_swap" -a $ARG1$ $ARG2$
}
定義遠程Linux主機的swap資源:
define service
{
use generic-service
host_name linuxserver1,linuxserver2
hostgroup_name linux-servers
service_description SWAP
check_command check_swap_nrpe!20!10
normal_check_interval 30
}
須要修改NFS配置文件
check_nrpe -h 獲取幫助