Nagios

Nagios

1、安装yum install gd-devel –y

[root@localhost nagios]# yum installgd-devel –y

 

2、部署lamp环境yum install httpd mysqlmysql-server php php-mysql -y

[root@localhost ~]# yum install httpd mysqlmysql-server php php-mysql –y

 

3、安装主程序nagios

[root@localhostnagios]# tar fvxz nagios-3.2.0.tar.gz

[root@localhost nagios-3.2.0]# ./configure --prefix=/usr/local/nagios报错

checking for a BSD-compatible install... /usr/bin/install-c

checking build system type...i686-pc-linux-gnu

checking host system type...i686-pc-linux-gnu

checking for gcc... no

checking for cc... no

checking for cc... no

checking for cl... no

configure: error: no acceptable C compilerfound in $PATH

See `config.log‘ for more details.

[root@localhost nagios-3.2.0]# yuminstall -y gcc cc cl安装上

[root@localhost nagios-3.2.0]# ./configure --prefix=/usr/local/nagios

*** Configuration summary for nagios 3.2.008-12-2009 ***:

 

 General Options:

 -------------------------

       Nagios executable:  nagios

       Nagios user/group:  nagios,nagios

      Command user/group:  nagios,nagios

           Embedded Perl:  no

            Event Broker:  yes

       Install ${prefix}: /usr/local/nagios

                Lock file:  ${prefix}/var/nagios.lock

  Check result directory: ${prefix}/var/spool/checkresults

          Init directory:  /etc/rc.d/init.d

 Apache conf.d directory: /etc/httpd/conf.d

            Mail program:  /bin/mail

                 Host OS:  linux-gnu

 

 WebInterface Options:

 ------------------------

                 HTML URL:  http://localhost/nagios/

                  CGI URL:  http://localhost/nagios/cgi-bin/

 Traceroute (used by WAP):  /bin/traceroute

 

 

Review the options above for accuracy.  If they look okay,

type ‘make all‘ to compile the main programand CGIs.

 

[root@localhost nagios-3.2.0]# useradd nagios  要以nagios用户执行,所以要建立nagios用户

 

[root@localhost nagios-3.2.0]# makeall

 

*** Compile finished ***

 

If the main program and CGIs compiledwithout any errors, you

can continue with installing Nagios asfollows (type ‘make‘

without any arguments for a list of allpossible options):

 

  make install

    - This installs the main program, CGIs, and HTML files

 

  make install-init

    - This installs the init script in /etc/rc.d/init.d

 

  make install-commandmode

    - This installs and configures permissions on the

      directory for holding the external command file

 

  make install-config

    - This installs *SAMPLE* config files in /usr/local/nagios/etc

      You‘ll have to modify these sample files before you can

      use Nagios.  Read the HTMLdocumentation for more info

      on doing this.  Pay particularattention to the docs on

      object configuration files, as they determine what/how

      things get monitored!

 

  make install-webconf

    - This installs the Apache config file for the Nagios

      web interface

 

[root@localhost nagios-3.2.0]# make install

[root@localhost nagios-3.2.0]# make install-init

[root@localhost nagios-3.2.0]# make install-commandmode

 

[root@localhost nagios-3.2.0]# make install-config

[root@localhost nagios-3.2.0]#make install-webconf

 

4、

[[email protected]]# vim /etc/httpd/conf/httpd.conf 把apache修改成nagios身份执行

技术分享

技术分享修改为:技术分享

 

本主机作为监控要打开Apache和nagios这两个服务。

 

重启apache:

Service httpd restart

技术分享

[root@localhost ~]# chkconfig httpd on   开机启动

启动nagios:

Service nagios start

 技术分享

5、远程连接:

技术分享

技术分享

生成一个用户nagios,密码:123456

[root@localhost nagios-3.2.0]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios

New password:

Re-type new password:

Adding password for user nagios

技术分享

技术分享

给nagios用户开权限,让他能够查看信息!

[root@localhost nagios-3.2.0]#  vim/usr/local/nagios/etc/cgi.cfg

:%s/nagiosadmin/nagiosadmin,nagios/          # 在所有的nagiosadmin后面添加nagios

技术分享

:%s/nagiosadmin/nagiosadmin,nagios/   修改为:

技术分享

[root@localhost nagios-3.2.0]# /etc/init.d/nagios reload

Running configuration check...done.

Reloading nagios configuration...done

本机为什么是down的状态???(少插件)

 

监控分析控制台   ---------------主程序

                                                                                                                                       插件

                                                                                                                                            --------------被监控主机

[root@localhost nagios-3.2.0]# cd /usr/local/nagios/libexec/

[root@localhost libexec]# pwd

/usr/local/nagios/libexec

[root@localhost libexec]# ls 插件目录下是空的

安装插件

[root@localhost libexec]# cd /root/Desktop/nagios/

[root@localhost nagios]# tar zvxf nagios-plugins-2.0.3.tar.gz

[root@localhost nagios-plugins-2.0.3]# ./configure --prefix=/usr/local/nagios/&& make && make install

[root@localhost nagios-plugins-2.0.3]# cd /usr/local/nagios/libexec/

技术分享

技术分享 

添加监控主机

[root@localhost nagios]# cd /usr/local/nagios/etc/

[root@localhost etc]# ls

cgi.cfg htpasswd.users  nagios.cfg  objects  resource.cfg

 

编辑主配置文件

[root@localhost etc]# vim nagios.cfg

技术分享

[root@localhost objects]# vim timeperiods.cfg    #  监控时间

技术分享

[root@localhost objects]# vim localhost.cfg   #  监控对象

definehost {

        host_name     huijinda

        alias           huijinda

        address       192.168.1.227

        check_command   check-host-alive

        notification_options    d,u,r  

        check_interval  1    

        max_check_attempts      2

        contact_groups  admins

        notification_interval   10

        notification_period     24x7

}

技术分享

[root@localhost objects]# vim commands.cfg    #  插件commands.cfg

define command{

       command_name    check-host-alive

       command_line    $USER1$/check_ping-H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5    #  hostaddress(指要监控的IP)

       }

技术分享

[root@localhost objects]# vim contacts.cfg   #  添加联系人zhanghao

 

definecontact {

        contact_name  zhanghao

        alias           zhanghao

        host_notification_commands      notify-host-by-email

        host_notification_period        24x7

        host_notification_options       d,u,r

        service_notification_period     24x7

        service_notification_options    w,u,c,r

        service_notification_commands   notify-service-by-email

        email  [email protected]

}

技术分享

将联系人加入到组:

技术分享

检查错误:

[root@localhostobjects]# /usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg

[root@localhost objects]# /etc/init.d/nagios reload

Running configuration check...done.

Reloading nagios configuration...done

 

查看nagios多了一个监控的HOST(zhanghao):

技术分享

[root@localhost objects]# tail -f /usr/local/nagios/var/nagios.log   #  断开监控主机查看过程

 

监控服务

监控服务,先要监控主机,以zhanghao,192.168.1.252为例

 

[root@localhost objects]# vim localhost.cfg

defineservice {

        host_name       zhanghao

        service_description     web

        check_period    24x7

        normal_check_interval   2

        retry_check_interval    1

        max_check_attempts      5

        notification_period     24x7

        notification_options    w,u,c,r

        check_command   check_http

}

技术分享

 

[root@localhost objects]# vim commands.cfg   调用check_http

技术分享

访问的apache服务没主页403错误:(编辑一个index.http)

[root@localhost objects]# /usr/local/nagios/libexec/check_http -I 192.168.18.166

技术分享

[root@localhost objects]# /usr/local/nagios/libexec/check_http -I192.168.18,166

HTTP OK: HTTP/1.1 200 OK - 277 bytes in0.001 second response time |time=0.001038s;;;0.000000 size=277B;;;0

[root@localhost objects]# /etc/init.d/nagios reload

Running configuration check...done.

Reloading nagios configuration...done

网页技术分享查看:

技术分享技术分享

服务添加成功。

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。