Nagios监控服务

2018-11-24  本文已影响12人  魔力冬瓜茶

安装Nagios

安装前准备

~]# yum -y install httpd php gcc glibc glibc-common gd gd-devel libpng libjpeg zlib

~]# vim /etc/httpd/conf/httpd.conf
DirectoryIndex index.php index.html index.html.var

~]# service httpd start

~]# vim /var/www/html/index.php 
<?php
    phpinfo();
?>

安装Nagios

~]# useradd -s /sbin/nologin nagios
~]# groupadd nagcmd
~]# usermod -G nagcmd nagios
~]# usermod -G nagcmd apache
~]# tar -zxvf nagios-3.2.1.tar.gz -C  /usr/src
~]# cd /usr/src/nagios-3.2.1/
~]# ./configure --with-command-group=nagcmd 
~]# make all
~]# make install
~]# make install-init
~]# make install-config
~]# make install-commandmode
~]# make install-webconf

配置文件解析

Nagios安装目录

/usr/local/nagios       //默认安装目录
bin                     //测试命令目录
etc                     //配置文件目录
libexec                 //插件目录
sbin                    //cgi脚本目录
share                   //Nagios网页文件目录
var                     //Nagios运行中产生的数据

Nagios配置文件解析

/usr/local/nagios/etc/      //配置文件目录
cgi.cfg                     //cgi程序配置文件
nagios.cfg                  //nagios服务主配置文件
resource.cfg                //定义nagios变量文件
/usr/local/nagios/etc/objects/      //监控对象及模板目录
commands.cfg                        //监控命令配置文件
localhost.cfg                       //监控本机对象配置文件
contacts.cfg                        //指定报警邮件发送邮箱
timeperiods.cfg                     //监控时间模板文件
templates.cfg                       //监控方式模板文件

Nagios监控插件

安装监控插件

~]# tar -zxvf nagios-plugins-1.4.14.tar.gz 
~]# cd nagios-plugins-1.4.14
nagios-plugins-1.4.14]#./configure --with-nagios-user=nagios  \
> --with-nagios-group=nagcmd
nagios-plugins-1.4.14]# make && make install  
~]# ls /usr/local/nagios/libexec/
check_apt      check_disk_smb  check_ide_smart     check_mrtg      check_nwstat  check_sensors  check_users  ...

监控插件应用案例

~]# cd /usr/local/nagios/libexec/
libexec]# ./check_http --help

libexec]# ./check_http -H localhost -p 80
HTTP OK: HTTP/1.1 200 OK - 46821 bytes in 0.016 second response time |time=0.016157s;;;0.000000 size=46821B;;;0

libexec]# service httpd stop
停止 httpd:                                               [确定]
libexec]# ./check_http -H localhost -p 80
拒绝连接
HTTP CRITICAL - Unable to open TCP socket
libexec]# ./check_ftp -H localhost -p 21
拒绝连接
libexec]# service vsftpd status
vsftpd 已停
libexec]# ./check_tcp -p 2049
拒绝连接
libexec]# ./check_ping -H 127.0.0.1 -w 5,10% -c 10,20% -p 10 -t 20
PING OK - Packet loss = 0%, RTA = 0.04 ms|rta=0.038000ms;5.000000;10.000000;0.000000 pl=0%;10;20;0
libexec]# df -h | grep /$
/dev/sda3       8.8G  4.2G  4.2G  51% /
libexec]# ./check_disk -w 80% -c 78% -p /dev/sda3
DISK CRITICAL - free space: / 4246 MB (49% inode=77%);| /=4287MB;1799;1979;0;8997
上一篇 下一篇

猜你喜欢

热点阅读