Chinaunix首页 | 论坛 | 博客
  • 博客访问: 514097
  • 博文数量: 230
  • 博客积分: 5726
  • 博客等级: 大校
  • 技术积分: 2765
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-21 13:51
文章分类

全部博文(230)

文章存档

2011年(33)

2010年(40)

2009年(157)

分类: LINUX

2010-09-27 11:41:41

nagios安装及简单配置(ZT)
                                      
摘自网址:
系统安装

下载nagios,  nagios plugin,  apache,  php, gd lib

下载地址:

 Nagios & Nagios Plugins
    

 Apache

 

 PHP

 

 gd lib

 

 一些画图的lib

 
 
安装过程:(用root权限)

1, 安装gd lib

   tar zxvf gd-2.0.33.tar.gz
     cd gd-2.0.33; ./configure && make && make install

2, 安装 apache
              tar httpd-2.0.54.tar.gz

cd httpd-2.0.54

./configure --prefix=/usr/local/apache2 --enable-so && make && make install

3, 安装php

              tar php-5.0.4.tar.gz; cd php-5.0.4

       ./configure --with-apxs2=/usr/local/apache2/bin/apxs && make && make install

    4, 安装Nagios
       adduser nagios

       Mkdir /usr/local/nagios

       Chown nagios.nagios /usr/local/nagios

       Groupadd nagcmd

       Usermod –G nagcmd apache

       Usermod –G nagcmd nagios

      

       tar zxvf nagios-xxx.tar.gz

       Cd nagios-xxx

       ./configure    //默认会安装在/usr/local/nagios下。

       Make && make all && make install

make install-config    #安装配置文件的样例

make install-init       #将nagios注册为service
 
       4, 安装Nagios plugin

       Tar zxvf nagios-plugins-xxx.tar.gz

       Cd nagios-plugins-xxx

       ./configure

       Make && make install
 
       到目前为止环境已经准备好了,下一步是配置nagios Good Luck ……
 
系统配置

              Apache配置选项修改

              将以下配置加入到httpdconf中。
Alias /nagios/cgi-bin/images/ "/usr/local/nagios/share/images/"

    AllowOverride None
        Options None
        Order allow,deny
        Allow from all
        AuthName "Nagios Access"
        AuthType Basic
        AuthUserFile /usr/local/nagios/etc/.htpasswd
        Require valid-user
ScriptAlias /nagios/cgi-bin/ "/usr/local/nagios/sbin/"

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

Alias /nagios/ "/usr/local/nagios/share/"

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

       
              在浏览器中用应该能够看到nagios的界面。

      
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd ddl
Nagios配置(重头戏 ^_^,官方文档非常详细,以下只是说一下最重要的配置文件及说明)

              安装完nagios后,默认安装在/usr/local/nagios下,目录结构如下

              Bin     nagios 程序代码

Etc         nagios 的配置文件目录

Libexec   nagios 的plugin的目录

Sbin        nagios CGI的目录

Share      nagios 静态页面和调用cgi的目录

Var          nagios 日志目录

Var/rw     nagios 及扩展脚本文件
 
Nagios的主要配置文件

       在etc下有几个对nagios相关的配置文件。

       Cgi.cfg                              定义cgi的一些值

Nagios.cfg                       Nagios的主要配置文件

checkcommands.cfg        定义一些监控命令

contactgroups.cfg            定义联系人的组

contacts.cfg                    定义联系人

dependencies.cfg              没有用到

escalations.cfg                        没有用到

hostgroups.cfg                        定义服务组

hosts.cfg                定义服务器

servicegroup.cfg          定义监控服务组

services.cfg                     定义要监控那些服务

timeperiods.cfg                定义监控时间

resource.cfg                    定义指定plugin的目录配置文件

plugincommands.cfg      定义plugin的命令
 
cgi.cfg配置文件其中主要的选项

main_config_file=/usr/local/nagios/etc/nagios.cfg           定义nagios主配置文件的路径

physical_html_path=/usr/local/nagios/share                          定义nagios 静态页面的路径

url_html_path=/nagios                                                        定义在用url访问时的目录

use_authentication=0/1                                                       定义是否需要认证访问监控系统

refresh_rate=60                                                                 定义多长时间刷新一次页面
 
nagios.cfg配置文件其中主要的选项

log_file=/usr/local/nagios/var/nagios.log                            定义nagios的日志文件

cfg_file=/usr/local/nagios/etc/checkcommands.cfg

cfg_file=/usr/local/nagios/etc/plugincommands.cfg

cfg_file=/usr/local/nagios/etc/misccommands.cfg

cfg_file=/usr/local/nagios/etc/contactgroups.cfg

cfg_file=/usr/local/nagios/etc/contacts.cfg

cfg_file=/usr/local/nagios/etc/dependencies.cfg

cfg_file=/usr/local/nagios/etc/escalations.cfg

cfg_file=/usr/local/nagios/etc/hostgroups.cfg

cfg_file=/usr/local/nagios/etc/hosts.cfg

cfg_file=/usr/local/nagios/etc/services.cfg

resource_file=/usr/local/nagios/etc/resource.cfg

cfg_file=/usr/local/nagios/etc/timeperiods.cfg                cfg_file指定要include进来的配置文件
 
checkcommands.cfg配置文件其中主要的选项

# 'check_local_disk' command definition

define command{

        command_name    check_local_disk

        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$

}
 

contactgroups.cfg配置文件其中主要的选项

              define contactgroup{

contactgroup_name       spider

alias   sogou-monitor monitor

       members        ruiguo, guorui

}
 
contacts.cfg配置文件其中主要的选项
 
define contact{

        contact_name                    ruiguo

        alias                           Guo Rui

        service_notification_period             24x7

        host_notification_period               24x7

        service_notification_options             c,r

        host_notification_options              d,r

        service_notification_commands        notify-by-email

        host_notification_commands          host-notify-by-email

        email                           ruiguo at sohu-inc dot com

        pager                           13681374598

}
 
hostgroups.cfg     配置文件其中主要的选项
 
define hostgroup{

        hostgroup_name  spider

        alias           spider servers

        members       spider01,spider02,spider03,spider04

}
 
hosts.cfg配置文件其中主要的选项
 
define host{

        name                        sogou-server

        notifications_enabled           1

        event_handler_enabled          1

        flap_detection_enabled          1

        process_perf_data              1

        retain_status_information        1

        retain_nonstatus_information     1

        register                       0

        notification_interval             0

}
 
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

# spider host definition

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

define host {

        use                             sogou-server

        host_name                       spider01

        alias                            spider01

        address                          10.10.66.133

        check_command                   check-host-alive

        contact_groups                    spider

        max_check_attempts                10

        checks_enabled                    1

        failure_prediction_enabled           1

        notification_period                 24x7

        notification_options                d,u,r

}
 
services.cfg配置文件其中主要的选项
 
define service{

        name                            generic-service

        active_checks_enabled           1

        passive_checks_enabled          1

        parallelize_check               1

        obsess_over_service             1

        check_freshness                 0

        notifications_enabled           1

        event_handler_enabled           1

        flap_detection_enabled          1

        process_perf_data               1

        retain_status_information       1

        retain_nonstatus_information    1

        register                        0

        notification_interval           0

        notification_period             24x7

        notification_options            w,u,c,r

        }
 
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

# spider service

#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

define service {

        use                   generic-service

        hostgroup_name        spider

        service_description   crawler

        is_volatile           0

        check_period          24x7

        max_check_attempts    3

        normal_check_interval 5

        retry_check_interval  1

        contact_groups        spider

        check_command         ssh_procs!Crawler!root    #监控命令

        notification_options    w,u,c,r

}
 

define service {

        use                   generic-service

        hostgroup_name        clustor

        service_description   Disk space

        is_volatile           0

        check_period          24x7

        max_check_attempts    3

        normal_check_interval 5

        retry_check_interval  1

        contact_groups        clustor

        check_command         ssh_disk!20%!10%!/DATA     #监控硬盘空间

        notification_options    w,u,c,r

}
 
timeperiods.cfg配置文件其中主要的选项
 

# '24x7' timeperiod definition

define timeperiod{

        timeperiod_name 24x7

        alias           24 Hours A Day, 7 Days A Week

        sunday          00:00-24:00

        monday          00:00-24:00

        tuesday         00:00-24:00

        wednesday       00:00-24:00

        thursday        00:00-24:00

        friday          00:00-24:00

        saturday        00:00-24:00

}
 
# '22x7' timeperiod definition -- zhaoliyang

define timeperiod{

        timeperiod_name 22x7

        alias           22 Hours A Day, 7 Days A Week

        sunday          00:00-01:00,02:00-24:00

        monday          00:00-01:00,02:00-24:00

        tuesday         00:00-01:00,02:00-24:00

        wednesday       00:00-01:00,02:00-24:00

        thursday        00:00-01:00,02:00-24:00

        friday          00:00-01:00,02:00-24:00

        saturday        00:00-01:00,02:00-24:00

}
 
# 'workhours' timeperiod definition

define timeperiod{

        timeperiod_name workhours

        alias           "Normal" Working Hours

        monday          09:00-17:00

        tuesday         09:00-17:00

        wednesday       09:00-17:00

        thursday        09:00-17:00

        friday          09:00-17:00

}
 
# 'nonworkhours' timeperiod definition

define timeperiod{

        timeperiod_name nonworkhours

        alias           Non-Work Hours

        sunday          00:00-24:00

        monday          00:00-09:00,17:00-24:00

        tuesday         00:00-09:00,17:00-24:00

        wednesday       00:00-09:00,17:00-24:00

        thursday        00:00-09:00,17:00-24:00

        friday          00:00-09:00,17:00-24:00

        saturday        00:00-24:00

}
 

# 'none' timeperiod definition

define timeperiod{

        timeperiod_name none

        alias           No Time Is A Good Time

}
 
resource.cfg配置文件其中主要的选项
 
$USER1$=/usr/local/nagios/libexec   设置变量
 
plugincommands.cfg配置文件其中主要的选项 (定义一些plugin的命令)
 
# 'check_ssh_procs' command definition

define command{

        command_name    ssh_procs

        command_line    /usr/local/nagios/libexec/check_by_ssh -H $HOSTADDRESS$ -l root -C "/usr/local/nagios/l

ibexec/check_procs -w 1:1 -c 1:1 -C $ARG1$ -u $ARG2$"

}
 
运行nagios

注意用绝对路径,在运行nagios之前应该将这台机器到被监控的服务器上的信任关系建好。

1, 第一次运行首先测试一下配置文件是否正确

      /usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagio.cfg

2, 没有问题运行

      /usr/local/nagios/bin/nagios –d /usr/local/nagios/etc/nagio.cfg

3, ps –ef 应该看到nagios进程存在。

4, 用浏览器访问应该能看到界面及定义好的监控主机及对象的列表。
 
 
运行Nagios
#service nagios start
 
安装NRPE
 
服务器端
 
安装环境
Red Hat Enterprise Linux AS release 4 U4
LANG=en_US.UTF-8
 
软件列表
nrpe-2.5.2.tar.gz
 
软件存放位置
/data/software
 
安装过程
#cd /data/software
#tar zxvf nrpe-2.5.2.tar.gz
#cd nrpe-2.5.2
#./configure
#make all
#cp /data/software/nrpe-2.5.2/src/check_nrpe /usr/local/nagios/libexec/
 
客户端
Linux客户端
 
安装环境
CentOS 4.3 LANG=en_US.UTF-8
 
软件列表
nagios-plugins-1.4.5.tar.gz
nrpe-2.5.2.tar.gz
 
软件存放位置
/home/software
 
安装过程
#cd /data/software
#mkdir /usr/local/nagios
#groupadd -g 810 nagios
#useradd -u 811 -g 810 nagios
#tar zxvf nagios-plugins-1.4.5.tar.gz
#cd nagios-plugins-1.4.5
#./configure --prefix=/usr/local/nagios --with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios/ --with-nagios-user=nagios --with-nagios-grp=nagios
#make
#make install
#tar zxvf nrpe-2.5.2.tar.gz
#cd nrpe-2.5.2
#./configure
#make all
#cd src/
#cp nrpe /usr/bin/
#cp ../nrpe.cfg /etc/
#echo "/usr/bin/nrpe -c /etc/nrpe.cfg --daemon" >>/etc/rc.local
#vi nrpe.cfg
--------------------------------------------------------------------------------
server_port=5666
allowed_hosts=127.0.0.1,60.28.24.188
nrpe_user=nagios
nrpe_group=nagios
debug=0
command_timeout=60
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 80% -c 50%
command[check_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_opt]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /opt
command[check_data]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /data
command[check_www]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /www
--------------------------------------------------------------------------------
启动nrpe
#/usr/bin/nrpe -c /etc/nrpe.cfg --daemon
 
Windows客户端
 
安装环境
Windows Server 2003 Enterprise Edition SP1
 
软件列表
nrpe_nt.0.7f-bin.zip   
check_disk-1.13c.zip
nrpe_nt_plugins.zip
 
软件存放位置
D:/software
 
安装过程
将文件解压到D:\nrpe
在cmd执行
D:\nrpe>NRPE_NT.exe  -i -n
NRPE_NT Service sucessfully installed!
 
打开注册表,在
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\NRPE_NT
修改ImagePath="D:\nrpe\NRPE_NT.exe -n"
 
启动服务
Nagios Remote Plugin Executor for NT/W2K
注意:check_nrpe 需要nrpe-2.0并且需要-n选项
 
mail.php
include "smtp.class.php";
exec("echo 2 >> 1.txt");
$smtpserver ="smtp.163.com";
$port = 25 ;
$smtpuser ="clay_333";
$smtppwd ="*******";
$mailtype ="HTML";
$sender = "";
$smtp = new smtp($smtpserver,$port,true,$smtpuser,$smtppwd,$sender);
$smtp->debug = true;
$to = "";
#$subject ="nagios";
$subject =$argv[1];
#$body = "";
$body=$argv[2];
$host=$argv[3];
#echo   $_SERVER['QUERY_STRING'];
#echo  $argv;
#print_r($argv[1]);
$send=$smtp->sendmail($to,$sender,$subject,$body,$mailtype);
if($send==1){
#    echo "mail end";
`/home/haijun/write-maillog.sh "mail success"`;
}
else{
#   echo "mail fail";
`/home/haijun/write-maillog.sh "mail fail"`;
#echo "resion:".$this->smtp->logs;
}
$return=`/usr/local/nagios/libexec/check_nrpe -H $host -t 90 -c check_writelog`
?>
阅读(2114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~