Nagios

Nagios

1、安装yum install gd-devel �Cy

[root@localhost nagios]# yum installgd-devel �Cy

 

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

[root@localhost ~]# yum install httpd mysqlmysql-server php php-mysql �Cy

 

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身份执行

spacer.gif

wKiom1U3CIWCVYdkAAAfG4uj0B8935.jpg修改为:wKiom1U3CFmgV81pAAAh373g2PU768.jpg

 

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

 

重启apache:

Service httpd restart

wKiom1U3CULwIqS0AABHiROE47o289.jpg

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

启动nagios:

Service nagios start

 wKioL1U3ClTDvLtDAABHzOTrbYM171.jpg

5、远程连接:

wKioL1U3CfmToPy3AABBSrGyIVM640.jpg

wKiom1U3CXKRQTEtAAB73dwzqNM897.jpg

生成一个用户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

wKiom1U3Ca7wnyFJAABflwzkVo0610.jpg

wKioL1U3CwuA4HwsAADi5aDDjnY589.jpg

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

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

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

wKiom1U3CdihN8j6AABA91OEpgc539.jpg

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

wKioL1U3C0eA6TgtAABIi8CHY80547.jpg

[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/

wKiom1U3CnaiyxzEAAIsUDqhe8Q051.jpg

wKioL1U3C9LQhfRNAABLkaK8E7E012.jpg 

添加监控主机

[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

wKiom1U3Co2CXFNHAADtAToumws332.jpg

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

wKioL1U3C_3wrFBPAAC9q2FhjCs090.jpg

[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

}

wKiom1U3CrKRNOSWAAFPNUNyl1s221.jpg

[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)

       }

wKiom1U3Ctizl4qGAABFsNGjqLc820.jpg

[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]

}

wKiom1U3Cu-jq2zDAAEaLsSxpv4585.jpg

将联系人加入到组:

wKiom1U3CvvxplEdAABnogvApyM117.jpg

检查错误:

[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):

wKioL1U3DLfzgJ0dAAB0qlglvaU838.jpg

[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

}

wKioL1U3DNihGRNyAAFCkf91W78135.jpg

 

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

wKiom1U3C4nxpWAZAACSIMDY5K4113.jpg

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

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

wKioL1U3DPegd9dKAABO5iI5wpk895.jpg

[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

网页wKioL1U3DXnhH1ZsAAAOyPRN9Ok093.jpg查看:

wKioL1U3DYvSB_5xAAAOyPRN9Ok452.jpgwKiom1U3DC6zfoTgAAAsHj-GaHY805.jpg

服务添加成功。

 

你可能感兴趣的:(安装,nagios)