Chinaunix首页 | 论坛 | 博客
  • 博客访问: 51749
  • 博文数量: 11
  • 博客积分: 47
  • 博客等级: 民兵
  • 技术积分: 87
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-10 10:24
个人简介

不学无术

文章分类

全部博文(11)

文章存档

2015年(8)

2013年(1)

2012年(2)

我的朋友

分类: 网络与安全

2015-06-05 10:58:20

一、服务器搭建

1、安装nagios

     1)yum install -y wget httpd php php-devel php-gd gcc glibc glibc-common gd gd-devel make net-snmp

   2)下载nagios-4.0.8、nagios-plugins-2.0.3

   wget 

   wget 

   3)创建nagios用户与用户组

   useradd nagios

   groupadd nagcmd

   usermod -a -G nagcmd nagios

   4)安装nagios-4.0.8

   tar zxvf nagios-4.0.8.tar.gz 

   cd nagios-4.0.8

   ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --with-nagios-group=nagcmd

   make all

   make install 

   make install-init  

   make install-config 

   make install-commandmode 

   make install-webconf 

   cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

   chown -R nagios:nagcmd /usr/local/nagios/libexec/eventhandlers

   /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

   service nagios start

2、配置httpd

   1)配置web登陆用户名和密码

      htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 

   2) vi /etc/httpd/conf/httpd.conf  

      找到 

      user apache

      group apache

      修改为

      user nagios

      group nagcmd

   3)找到

      #ServerName 

      将前面的#删除

3、安装nagios-plugins

   tar zxvf nagios-plugins-2.0.3.tar.gz 

   cd nagios-plugins-2.0.3

   ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagcmd --with-command-user=nagios --with-command-group=nagcmd

   make

   make install

4、设置开机启动 

   chkconfig nagios on

   service nagios start

   chkconfig httpd on

   service httpd start

5、访问

    输入用户名密码

二、为nagios安装图标pnp4nagios

   1、安装组件

   yum install perl-Time-HiRes rrdtool  rrdtool-perl

   2、安装pnp4nagios-0.6.24

   wget 

   tar zxvf pnp4nagios-0.6.24.tar.gz

   cd pnp4nagios-0.6.24

   ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd

   make all

   make install

   make install-webconf

   make install-config

   make install-init

   3、创建配置文件

   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

  4、重启服务

   service npcd restart

   chkconfig npcd on

  5、修改nagios配置档

   1)vi /usr/local/nagios/etc/nagios.cfg   

      将process_performance_data=0  修改为  process_performance_data=1

      将以下两项的#去掉

      host_perfdata_command=process-host-perfdata

      service_perfdata_command=process-service-perfdata

   2)vi /usr/local/nagios/etc/objects/commands.cfg  添加以下内容

define command{

        command_name process-service-perfdata-file

        command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$

}

define command{

        command_name process-host-perfdata-file

        command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$

}

      把# 'process-host-perfdata' command definition、

        # 'process-service-perfdata' command definition

        两条定义删除,或者注释!

   3)vi /usr/local/nagios/etc/objetcs/templates.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 

        failure_prediction_enabled      1 

        process_perf_data              1

        retain_status_information      1 

        retain_nonstatus_information    1   

        is_volatile                    0     

        check_period                    24x7   

        max_check_attempts              3     

        normal_check_interval          10 

        retry_check_interval            2 

        contact_groups                  admins 

        notification_options            w,u,c,r   

        notification_interval          60       

        notification_period            24x7   

        register                        0 

        action_url        /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$

        process_perf_data  1 
 
        }

   

   4)vi /usr/local/nagios/etc/nagios.cfg   修改参数如下

# Bulk / NPCD mode

#  

process_performance_data=1 

# *** the template definition differs from the one in the original nagios.cfg

#

service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata

service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$

service_perfdata_file_mode=a

service_perfdata_file_processing_interval=15

service_perfdata_file_processing_command=process-service-perfdata-file 

# *** the template definition differs from the one in the original nagios.cfg

#

host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata

host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$

host_perfdata_file_mode=a

host_perfdata_file_processing_interval=15

host_perfdata_file_processing_command=process-host-perfdata-file

6、检查配置是否有误

    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

     重启服务

     service nagios restart    

     service httpd restart

三、nagios监控linux nrpe安装

———————----以下是被监控客户机设置———————————————————

1、下载nrpe2.15

  wget 

2、yum install openssl openssl-devel

   cd nrpe-2.15

   ./configure --enable-ssl --with-nagios-user=nagios --with-nagios-group=nagcmd --with-nrpe-user=nagios --with-nrpe-group=nagcmd

   make all

   make install-plugin

   make install-daemon

   make install-daemon-config

   make install-xinetd

3、编辑nrpe配置文件,增加监控机地址:   

      vi /etc/xinetd.d/nrpe

      only_from = nagios-server-ip,127.0.0.1

4、编辑vi /usr/local/nagios/etc/nrpe.cfg

      allowed_hosts=nagios-server-ip,127.0.0.1

5、修改services文件,增加端口
          vi /etc/services
          nrpe            5666/tcp                        #NRPE

6、启动 nrpe

   /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

   设置开机启动

   vi /etc/rc.d/rc.local

   加入/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

——————————————————————————以下是nagios主机设置————————————————————————

1、vi /usr/local/nagios/etc/nagios.cfg

   加入cfg_file=/usr/local/nagios/etc/objects/my-linux.cfg

2、创建并编辑my-linux.cfg

   vi /usr/local/nagios/etc/objects/my-linux.cfg

define host{

           use linux-server

          host_name my-linux

          alias my-linux

          address IP

        }

define service{

        use generic-service

        host_name my-linux

        service_description check-swap

        check_command check_nrpe!check_swap

               }

define service{

        use generic-service

        host_name my-linux

        service_description check-load

       check_command check_nrpe!check_load

               }

define service{

        use generic-service

        host_name my-linux

       service_description check-disk

       check_command check_nrpe!check_sda1

               }

define service{

        use generic-service

        host_name my-linux

       service_description check-users

       check_command check_nrpe!check_users

               }

define service{

        use generic-service

        host_name my-linux

        service_description otal_procs

        check_command check_nrpe!check_total_procs

}

define service{

        use generic-service ; Name of service template to use

        host_name my-linux

        service_description PING

        check_command check_ping!100.0,20%!500.0,60%

        }

     


vi /usr/local/nagios/etc/objects/commands.cfg 

在最后面增加如下内容 

#############################################

# 'check_nrpe ' command definition 

define command{ 

command_name check_nrpe 

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 

3、service nagios restart

 

 

四、邮件报警设置

1、安装相关组件

   yum install mailx sendmail*

   chkconfig sendmail on

   service sendmail start

2、测试邮件

   echo "Hello World" | mail abc@abc.com   

3、设置发件人

[root@localhost]#vi /etc/mail.rc

set from=XXXXX@163.com 

Set smtp=smtp.163.com 

set smtp-auth-user=XXXXX

Set smtp-auth-password=XXXXX

Set smtp-auth=login

4、编辑command.cfg----下列邮件定义信息无需添加,commmand.cfg文件里已有(nagios 4.0.8)

# 'notify-host-by-email' command definition

define command{

command_name notify-host-by-email

command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

}

# 'notify-service-by-email' command definition

define command{

command_name notify-service-by-email

command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

5、添加联系人

###########################################################

# CONTACTS 

#############################################################
# Just one contact defined by default - the Nagios admin (that's you) 
# This contact definition inherits a lot of default values from the 'generic-contact' 
# template which is defined elsewhere. 
define contact{ 
               contact_name nagiosadmin ;  Short name of user 
               use generic-contact ;Inherit default values from generic-contact template (defined above) 

               alias    Nagios Admin   ; Full name of user 
              email  Email地址   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** 

4、重启nagios

   service nagios restart

 注:转载百度他这里写的都挺好,但是有些并没有指明意思。我自己稍加更改了一下。

阅读(2151) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

bonijun2016-11-29 10:31:40

被监控的主机 提示:Return code of 255 is out of bounds  错误,有遇到过吗?如何解决?