Nagios 系统监控

====================================================================================================
安装nagios服务器端
====================================================================================================
# groupadd nagios
# groupadd nagcmd
# useradd -g nagios -s /sbin/nologin -d /usr/local/nagios nagios
# usermod -G nagcmd nagios
# usermod -G nagcmd www
# chmod 755 /usr/local/nagios

# yum -y install gcc gcc-c++ flex bison autoconf automake bzip2 bzip2-devel zlib zlib-devel
# yum -y install ncurses ncurses-devel libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel
# yum -y install freetype freetype-devel pam pam-devel gd gd-devel libgdata libgdata-devel cairo cairo-devel
# yum -y install libxml2 libxml2-devel pango pango-devel libart_lgpl libart_lgpl-devel

注:httpd php 安装略,httpd在configure时,加上参数--enable-cgi和--enable-cgid

====================================================================================================
# wget -c http://sourceforge.net/projects/nagios-cn/files/latest/download?source=files [中文版]
# tar -jxvf nagios-cn-3.2.3.tar.bz2
# cd nagios-cn-3.2.3
or
# wget -c http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz  [英文版]
# tar -xvzf nagios-3.3.1.tar.gz
# cd nagios

# ./configure --prefix=/usr/local/nagios \
--with-nagios-user=nagios \
--with-nagiso-group=nagios \
--with-httpd-conf=/usr/local/apache/conf \
--with-command-group=nagcmd

# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# make install-webconf
# /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  [密码: blzvdwl369328]

# vi /usr/local/apache/conf/extra/httpd-vhosts.conf
ScriptAlias "/nagios/cgi-bin" "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
 Options ExecCGI
 AllowOverride None
 Order allow,deny
 Allow from all
 AuthName "Nagios Access"
 AuthType Basic
 AuthUserFile /usr/local/nagios/etc/htpasswd.users
 Require valid-user
</Directory>

Alias "/nagios" "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
 Options None
 AllowOverride None
 Order allow,deny
 Allow from all
 AuthName "Nagios Access"
 AuthType Basic
 AuthUserFile /usr/local/nagios/etc/htpasswd.users
 Require valid-user
</Directory>

----------------------------------------------------------------------------------------------------
# wget -c http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
# tar -xvzf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --prefix=/usr/local/nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-mysql=/usr/local/mysql \
--enable-perl-modules

# make all
# make install

----------------------------------------------------------------------------------------------------
# wget -c http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz
# tar -xvzf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure
# make all
# make install
# make install-plugin

----------------------------------------------------------------------------------------------------
# yum -y install rrdtool
# yum -y install rrdtool-perl

----------------------------------------------------------------------------------------------------
# wget -c http://nchc.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.16.tar.gz
# tar -xvzf pnp4nagios-0.6.16.tar.gz
# cd pnp4nagios-0.6.16
# ./configure --prefix=/usr/local/pnp4nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-httpd-conf=/usr/local/apache/conf

# make all
# make install
# make install-webconf
# make install-config
# make install-init

# vi /usr/local/apache/conf/extra/httpd-vhosts.conf
Alias /pnp4nagios "/usr/local/pnp4nagios/share"
<Directory "/usr/local/pnp4nagios/share">
    AllowOverride None
    Order allow,deny
    Allow from all

    AuthName "Nagios Access"
    AuthType Basic
    AuthUserFile /usr/local/nagios/etc/htpasswd.users
    Require valid-user
   
    <IfModule mod_rewrite.c>
        RewriteEngine On
        Options FollowSymLinks
        RewriteBase /pnp4nagios/
        RewriteRule ^(application|modules|system) - [F,L]

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d

        RewriteRule .* index.php/$0 [PT,L]
    </IfModule>
</Directory>

# cd /usr/local/pnp4nagios/etc
# mv misccommands.cfg-sample misccommands.cfg
# mv nagios.cfg-sample nagios.cfg
# mv rra.cfg-sample rra.cfg

# cd pages
# mv web_traffic.cfg-sample web_traffic.cfg

# cd ../check_commands
# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
# mv check_nrpe.cfg-sample check_nrpe.cfg
# mv check_nwstat.cfg-sample check_nwstat.cfg

# vi /usr/local/nagios/etc/nagios.cfg
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg [配置检查]

# vi /usr/local/nagios/etc/objects/commands.cfg
define command{
 command_name process-host-perfdata
 command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
 }

define command{
 command_name process-service-perfdata
 command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl
 }

# vi /usr/local/nagios/etc/objects/templates.cfg
define host{
 name host-pnp
 action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
 register 0
 }

define service{
 name srv-pnp
 action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
 register 0
 }

# vi /usr/local/nagios/etc/objects/localhost.cfg
define host{
    use                 linux-server,host-pnp
    host_name           HomeSwitch
    alias               HomeSwitch
    address             127.0.0.1
    icon_image          switch.gif
    statusmap_image     switch.gd2
    2d_coords          100,200
    3d_coords           100,200,100
    }

define service{
 use     local-service,srv-pnp
 host_name    localhost
 service_description PING
 check_command   check_ping!100.0,20%!500.0,60%
 }

# cd /usr/local/pnp4nagios/share
# mv install.php install.php.bak

----------------------------------------------------------------------------------------------------
# wget -c http://sourceforge.net/projects/nagiosql/files/nagiosql/NagiosQL%203.1.1/nagiosql_311.tar.gz

 

====================================================================================================
被监控端安装
====================================================================================================
# groupadd nagios
# useradd -g nagios -s /sbin/nologin nagios

# wget -c http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.9/nagios-plugins-1.4.9.tar.gz
# tar -xvzf nagios-plugins-1.4.9.tar.gz
# cd nagios-plugins-1.4.9
# ./configure --prefix=/usr/local/nagios
# make
# make install
# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec

----------------------------------------------------------------------------------------------------
# wget -c http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz
# tar -xvzf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# /usr/local/nagios/libexec/check_nrpe -H localhost

# vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1  [注:为Nagios监控平台的地址或域名]

# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local

# iptables -A INPUT -m state --state NEW -p tcp --dport 5666 -j ACCEPT

此命令生成的日志会在系统的日志(/var/log/message)中
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1   [注:在本机]
# /usr/local/nagios/libexec/check_nrpe -H 目标主机地址  [注:在nagios监控平台服务器]
 
通过NRPE,可以监控到被监控服务器上有的插件(/usr/local/nagios/libexec中的所有插件)。也就是说,
你想监控什么,只要有对应的插件,就可以实现。例如,我希望监控一台远程服务器上的cpu负载。
在远程主机的插件中有“check_load”,那么,在nrpe.conf中定义一个cpu负载的监控:
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

----------------------------------------------------------------------------------------------------
被监控机:[以监控内存使用为例]
http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=1154&cf_id=24

# vi /usr/local/nagios/etc/nrpe.cfg
command[check_mem]=/usr/local/nagios/libexec/check_mem -w 110,50 -c 150,80

# chmod 755 /usr/local/nagios/libexec/check_mem
# chown nagios.nagios /usr/local/nagios/libexec/check_mem

监控机:
# vi /usr/local/nagios/etc/objects/commands.cfg
define command{
    command_name    check_mem
    command_line    $USER1$/check_mem -w $ARG1$ -c $ARG2$
    }
 
# vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/linuxserver.cfg

# vi /usr/local/nagios/etc/objects/linuxserver.cfg
define host{
    use                     linux-server,host-pnp
    host_name               weiliao_server78
    alias                   weiliao_server78
    contact_groups          admins
    max_check_attempts      5
    address                 192.168.1.238
 icon_image              server.gif
    statusmap_image         server.gd2
    2d_coords               100,200
    3d_coords               100,200,100
    }

define hostgroup{     
    hostgroup_name    linux-server
    alias             Linux Servers
    members            weiliao_server78
    }

define service{
    host_name           weiliao_server78
    service_description     memory_monitor
    is_volatile             0
    check_period            24x7
    max_check_attempts      5
    normal_check_interval   1
    retry_check_interval    1
    notification_options    w,u,c,r
    notification_interval   1
    notification_period     24x7
    check_command           check_nrpe!check_mem!110,50!150,80
    notifications_enabled   0
    }
 

你可能感兴趣的:(职场,nagios,休闲)