我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

nagios的安装配置方法-创新互联

这篇文章主要讲解了“nagios的安装配置方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“nagios的安装配置方法”吧!

我们提供的服务有:成都做网站、网站设计、外贸营销网站建设、微信公众号开发、网站优化、网站认证、察雅ssl等。为千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的察雅网站制作公司

简单介绍下nagios

开源网络监控

监控的分类:

状态的连续监控:对实时状态进行监控。

状态的变化监控:但某一时刻监控的状态发生变化时,就进行汇报。

nagios是一款遵循GPLV2的开源网络监控软件,可用来监控制定的多种系统的主机、服务,并在它们的工作状态发生变化时通知管理员。

1)监控网络服务(HTTP/POP3/SMTP/PING/MYSQL等)

2)监控主机资源(磁盘利用率、内存利用率、CPU负载等)

3)简洁的插件设计接口,使得用户可以轻松开发所需的检测脚本(运维则可直接找到相关脚本并使用)

4)并行服务模式

5)轻松描述网络结构,并且能够区辨“宕机”和“主机不可达”

6)通过邮件或用户自定义的方式将主机或服务的工作状态变化情况通知给管理员

7)当服务或主机问题产生与解决时将告警发送给联系人(通过EMail/短信、用户定义方式)

8)自动日志滚动

9)可以通过web方式直观的查看当前网络状态、通知和问题历史、日志文件等,此组件为可选

undefined

Nagios通常由一个主程序(Nagios)、一个插件程序(Nagios-plugins)和四个可选的ADDON(NRPE/NSCA/NSCLIENT++和NDOUTILS)组成。

NRPE:用来在监控的的远程LINUX/UNIX主机上执行脚本插件以实现对这些主机资源的监控;

       试验中用到的版本是NRPE-2.1.2.tar.gz

NSCA:用来让被监控的远程Linux/Unix主机主动将监控信息发送给Nagios服务器(这在冗余监控模式中,特别要用到)

NSCLIENT++:用来监控Windows主机时安装在Windows主机上的组件;

NDOUTILS:则用来将NAGIOS的配置信息和各EVETN产生的数据存入数据库,以实现对这些数据的快速检索和处理;


NAGIOS是通过配置文件来驱动这个监控流程,因为所有的内容都是可配置的,所以也就非常灵活,功能自然也就枪弹,把太多的工作留给使用者。

1、新添加监控主机

要修改localhost.cfg或windows.cfg配置文件

这里的默认路径为/usr/local/nagios/etc/objects/localhost.cfg或者/usr/local/nagios/etc/objects/windows.cfg

2、调整监控的命令

要修改commands.cfg配置文件

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

3、要更改联系人的信息

要修改contacts.cfg配置文件

/usr/local/nagios/etc/objects/contacts.cfg

4、要调整监控时间

要修改timeperiods.cfg配置文件

/usr/local/nagios/etc/objects/contacts.cfg

5、添加具体的监控服务

要修改services.cfg配置文件,这里信息都是来自其他配置文件的

6、存放相关的命令执行脚本

/usr/local/nagios/libexecls

7、/usr/local/nagios/etc/objects/commands.cfg 定义相关命令


yum 源安装配置

vi /etc/yum.repos.d/Centos-Media.repo

[xscl]

baseurl=file:///mnt/cdrom/

gpgcheck=0

enabled=1

:wq


安装nagios必须的基本组件的运行依赖于httpd、gcc和gd.

yum clean all

准备工作:

  1. yum -y install  httpd*  php

  2. yum -y install gcc glibc glibc-common

  3. yum -y install gd gd-devel


groupadd nagcmd

useradd -m nagios

usermod -a -G nagcmd nagios

# usermod -a -G nagcmd apache

#j将apache用户加入nagcmd组使之工作时具有足够的权限

下载所需要的安装组件:

服务器端所用的安装包:nagios  nagios-plugins  ndoutils(非必须)

linux客户端:nrpe

windows客户端:NSCLIENT

创建用户:

chkconfig httpd on

useradd  nagios

cd /root

上传软件包我这里下载的nagios-3.3.1.tar.gz

tar-xzvf nagios-3.3.1.tar.gz

cd nagios

#./configure --with-command-group=nagcmd

make  install

报错解决方法如下:

今天安装nagios3.3.1,不是第一次安装了,之前都很顺利,这次安装的时候,在执行命令make install的时候,报错了。大致如下


  1. [root@magedunagios]#makeinstall

  2. cd./base&&makeinstall

  3. make[1]:Enteringdirectory`/root/nagios/base'

  4. makeinstall-basic

  5. make[2]:Enteringdirectory`/root/nagios/base'

  6. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/bin

  7. /usr/bin/install-c-m774-onagios-gnagiosnagios/var/www/html/nagios/bin

  8. /usr/bin/install-c-m774-onagios-gnagiosnagiostats/var/www/html/nagios/bin

  9. make[2]:Leavingdirectory`/root/nagios/base'

  10. makestrip-post-install

  11. make[2]:Enteringdirectory`/root/nagios/base'

  12. /usr/bin/strip/var/www/html/nagios/bin/nagios

  13. /usr/bin/strip/var/www/html/nagios/bin/nagiostats

  14. make[2]:Leavingdirectory`/root/nagios/base'

  15. make[1]:Leavingdirectory`/root/nagios/base'

  16. cd./cgi&&makeinstall

  17. make[1]:Enteringdirectory`/root/nagios/cgi'

  18. makeinstall-basic

  19. make[2]:Enteringdirectory`/root/nagios/cgi'

  20. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/sbin

  21. forfilein*.cgi;do\

  22. /usr/bin/install-c-m775-onagios-gnagios$file/var/www/html/nagios/sbin;\

  23. done

  24. make[2]:Leavingdirectory`/root/nagios/cgi'

  25. makestrip-post-install

  26. make[2]:Enteringdirectory`/root/nagios/cgi'

  27. forfilein*.cgi;do\

  28. /usr/bin/strip/var/www/html/nagios/sbin/$file;\

  29. done

  30. make[2]:Leavingdirectory`/root/nagios/cgi'

  31. make[1]:Leavingdirectory`/root/nagios/cgi'

  32. cd./html&&makeinstall

  33. make[1]:Enteringdirectory`/root/nagios/html'

  34. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share

  35. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/media

  36. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/stylesheets

  37. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/contexthelp

  38. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/docs

  39. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/docs/p_w_picpaths

  40. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/p_w_picpaths

  41. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/p_w_picpaths/logos

  42. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/includes

  43. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/includes/rss

  44. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/includes/rss/extlib

  45. /usr/bin/install-c-m775-onagios-gnagios-d/var/www/html/nagios/share/ssi

  46. /usr/bin/install-c-m664-onagios-gnagiosrobots.txt/var/www/html/nagios/share

  47. rm-f/var/www/html/nagios/share/index.html

  48. rm-f/var/www/html/nagios/share/main.html

  49. rm-f/var/www/html/nagios/share/side.html

  50. forfilein*.php;\

  51. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share;done

  52. forfileinstylesheets/*.css;\

  53. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/stylesheets;done

  54. forfileincontexthelp/*.html;\

  55. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/contexthelp;done

  56. forfileinp_w_picpaths/*.gif;\

  57. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths;done

  58. forfileinp_w_picpaths/*.jpg;\

  59. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths;done

  60. forfileinp_w_picpaths/*.png;\

  61. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths;done

  62. forfileinp_w_picpaths/*.ico;\

  63. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths;done

  64. forfileinp_w_picpaths/logos/*.*;\

  65. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/p_w_picpaths/logos;done

  66. forfileinincludes/*.*;\

  67. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/includes;done

  68. forfileinincludes/rss/*;\

  69. do/usr/bin/install-c-m664-onagios-gnagios$file/var/www/html/nagios/share/includes/rss;done

  70. /usr/bin/install:omittingdirectory`includes/rss/extlib'

  71. /usr/bin/install:omittingdirectory`includes/rss/htdocs'

  72. /usr/bin/install:omittingdirectory`includes/rss/scripts'

  73. make[1]:***[install]Error1

  74. make[1]:Leavingdirectory`/root/nagios/html'

  75. make:***[install]Error2


很纠结啊,google了一下,有解决方案,好像是makefile里有语法错误,具体怎么导致的不清楚,执行完以下命令,就OK了

  1. # sed-i's:forfileinincludes/rss/\*;:forfileinincludes/rss/\*.\*;:g'./html/Makefile

  2. # sed-i's:forfileinincludes/rss/extlib/\*;:forfileinincludes/rss/extlib/\*.\*;:g'./html/Makefile

  3. 然后,执行以下命令,来完成安装

预配置Nagios主程序的环境以及指定安装路径
[root@nagios-3.3.1]# ./configure --prefix=/usr/local/nagios
预配置成功后将返回配置环境信息
----------------------------------------------------
*** Configuration summary for nagios 2.9 04-10-2007 ***:

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
     Init directory:  /etc/rc.d/init.d
         Host OS:  linux-gnu

Web Interface 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 program and CGIs.


请注意看最后的提示,如果对以上反馈信息接受的话,则需要继续执行“make all”命令来编译主程序以及CGI。


.编译Nagios主程序
[root@KCentOS5C nagios-2.9]# make all
Nagios主程序编译成功后将返回信息
-----------------------------------------------------
*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
如果在编译当中没有发生错误的话,那么可以照以下这些命令继续操作。

 make install
  - This installs the main program, CGIs, and HTML files
 执行“make install”命令来对主程序,CGI以及HTML网页进行安装。

 make install-init
  - This installs the init script in /etc/rc.d/init.d
 执行“install-init”命令来在/etc/rc.d/init.d/目录中安装启动脚本。

 make install-commandmode
  - This installs and configures permissions on the
   directory for holding the external command file
 执行“install-commandmode”命令来安装和配置外部命令对Nagios主路径操作的权限。(这里所谓的外部命令主要是指Apache服务通过CGI来对Nagios的进行的操作。用户将通过Web以执行CGI程序脚本的方式来对Nagios的检测结果进行读取和调用。)

 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 HTML documentation for more info
   on doing this.  Pay particular attention to the docs on
   object configuration files, as they determine what/how
   things get monitored!
 执行“make install-config”命令将会在/usr/local/etc/这个Nagios编译安装的主配置路径下安装示例配置模板,这将对于之后的配置制定帮助很大。

*** Support Notes *******************************************
这些关于支持的信息就不再详细讲了

If you have questions about configuring or running Nagios,
please make sure that you:

  - Look at the sample config files
  - Read the HTML documentation
  - Read the FAQs online at http://www.nagios.org/faqs

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:

  - What version of Nagios you are using
  - What version of the plugins you are using
  - Relevant snippets from your config files
  - Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

http://www.nagios.org/support/

*************************************************************

Enjoy.
-----------------------------------------------------


5.安装Nagios主程序、CGI以及网页
[root@KCentOS5C nagios-2.9]# make install
安装完Nagios主程序、CGI和网页的之后将提示安装成功信息以及剩余可操作的步骤
-----------------------------------------------------
*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

 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 HTML documentation for more info
   on doing this.  Pay particular attention to the docs on
   object configuration files, as they determine what/how
   things get monitored!
-----------------------------------------------------


6.安装Nagios的系统启动脚本
[root@KCentOS5C nagios-2.9]# make install-init
安装完Nagios的系统启动脚本之后将提示脚本安装成功信息以及剩余可操作的步骤
-----------------------------------------------------
*** Init script installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

 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 HTML documentation for more info
   on doing this.  Pay particular attention to the docs on
   object configuration files, as they determine what/how
   things get monitored!
-----------------------------------------------------


7.将Nagios的启动脚本添加到系统服务当中去
[root@KCentOS5C ~]# chkconfig --add nagios

8.将Nagios服务加入到系统启动服务当中去
[root@KCentOS5C ~]# chkconfig nagios on

9.安装和配置外部命令对Nagios主路径的操作权限
[root@KCentOS5C nagios-2.9]# make install-commandmode
安装配置外操作权限后将提示配置成功信息以及剩余可操作步骤
-----------------------------------------------------
*** External command directory configured ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

 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 HTML documentation for more info
   on doing this.  Pay particular attention to the docs on
   object configuration files, as they determine what/how
   things get monitored!
-----------------------------------------------------


10.将Apache服务宿主用户加到nagios组里面
这样做是为了让Apache有适当的权限能够通过CGI脚本程序对Nagios进行调用,否则Apache将没有权限调用Nagios,用户通过Web将无法访问Nagios处理的所有信息。
[root@KCentOS5C nagios-2.9]# usermod -G n apache


11.安装Nagios的配置模板
[root@KCentOS5C nagios-2.9]# make install-config
安装完毕Nagios的配置模板后将反馈安装成功的提示信息。
-----------------------------------------------------
*** Sample config file installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

If you have questions about configuring Nagios properly, please:
   - Look at the sample config files
   - Read the HTML documentation
   - Read the FAQs online at http://www.nagios.org/faqs
*BEFORE* you post a question to one of the mailing lists.
-----------------------------------------------------


为email指定您想用来接收nagios警告信息的邮件地址,默认是本机的nagios用户:

# vi /usr/local/nagios/etc/objects/contacts.cfg

email     nagios@localhost    #这个是默认设置

# make install-webconf

#在/etc/httpd/conf.d/nagios.conf生成web相关配置文件,用于定义nagios使用的CGI选项,web的身份认证等

[root@station71 nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

New password:

Re-type new password:

Adding password for user nagios

#为nagios的web页面创建账号密码,对访问进行身份认证

service httpd restart

chkconfig httpd on

启动httpd,并设置开机启动

进入Nagios-plugins插件包目录
[root@KCentOS5C ~]# cd nagios-plugins-1.4.10

3.预配置Nagios-plugin插件程序的环境以及指定安装路径

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

[root@ nagios-plugins-1.4.10]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql预配置完成的话将会建立Makefile并反馈检测系统环境的结果。
-----------------------------------------------------
config.status: creating po/Makefile
      --with-apt-get-command:
       --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
       --with-ping-command: /bin/ping -n -U -w %d -c %d %s
           --with-ipv6: yes
           --with-mysql: no
          --with-openssl: yes
          --with-gnutls: no
           --with-perl: /usr/bin/perl
      --enable-perl-modules: no
          --with-cgiurl: /nagios/cgi-bin
       --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
-----------------------------------------------------

4.编译Nagios-plugin插件程序
[root@KCentOS5C nagios-plugins-1.4.10]# make

5.安装Nagios-plugin插件程序

[root@KCentOS5C nagios-plugins-1.4.10]# make install


6.查看安装情况

[root@KCentOS5C nagios-plugins-1.4.10]# ll /usr/local/nagios/

-----------------------------------------------------
total 28
drwxrwxr-x 2 nagios nagios 4096 Oct  5 13:25 bin
drwxrwxr-x 2 nagios nagios 4096 Oct  5 19:03 etc
drwxr-xr-x 2 root  root  4096 Oct  5 19:07 libexec
drwxrwxr-x 2 nagios nagios 4096 Oct  5 13:25 sbin
drwxrwxr-x 9 nagios nagios 4096 Oct  5 19:07 share
drwxrwxr-x 4 nagios nagios 4096 Oct  5 19:08 var

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

只要Nagios主路径下出现libexec目录就说明安装成功了,这个目录里面存放着就是Nagios插件执行程序。但是有个问题,就是刚安装好会有一些目录和文件的属主是root。这里的libexec就有这个问题。

4.编译Nagios-plugin插件程序
[root@KCentOS5C nagios-plugins-1.4.10]# make

5.安装Nagios-plugin插件程序

[root@KCentOS5C nagios-plugins-1.4.10]# make install


6.查看安装情况

[root@KCentOS5C nagios-plugins-1.4.10]# ll /usr/local/nagios/

-----------------------------------------------------
total 28
drwxrwxr-x 2 nagios nagios 4096 Oct  5 13:25 bin
drwxrwxr-x 2 nagios nagios 4096 Oct  5 19:03 etc
drwxr-xr-x 2 root  root  4096 Oct  5 19:07 libexec
drwxrwxr-x 2 nagios nagios 4096 Oct  5 13:25 sbin
drwxrwxr-x 9 nagios nagios 4096 Oct  5 19:07 share


drwxrwxr-x 4 nagios nagios 4096 Oct  5 19:08 var

7/ cd /usr/local/nagios/libexec

ll

[root@localhost libexec]# ll

total 6436

-rwxr-xr-x. 1 root root 376516 Jun  4 19:06 check_apt

-rwxr-xr-x. 1 root root  2254 Jun  4 19:06 check_breeze

-rwxr-xr-x. 1 root root 128392 Jun  4 19:06 check_by_ssh

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_clamd -> check_tcp

-rwxr-xr-x. 1 root root  85678 Jun  4 19:06 check_cluster

-r-sr-xr-x. 1 root root 123723 Jun  4 19:06 check_dhcp

-rwxr-xr-x. 1 root root 121722 Jun  4 19:06 check_dig

-rwxr-xr-x. 1 root root 417871 Jun  4 19:06 check_disk

-rwxr-xr-x. 1 root root  9148 Jun  4 19:06 check_disk_smb

-rwxr-xr-x. 1 root root 129579 Jun  4 19:06 check_dns

-rwxr-xr-x. 1 root root  80681 Jun  4 19:06 check_dummy

-rwxr-xr-x. 1 root root  3056 Jun  4 19:06 check_file_age

-rwxr-xr-x. 1 root root  6318 Jun  4 19:06 check_flexlm

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_ftp -> check_tcp

-rwxr-xr-x. 1 root root 123705 Jun  4 19:06 check_hpjd

-rwxr-xr-x. 1 root root 519173 Jun  4 19:06 check_http

-r-sr-xr-x. 1 root root 133809 Jun  4 19:06 check_icmp

-rwxr-xr-x. 1 root root  93400 Jun  4 19:06 check_ide_smart

-rwxr-xr-x. 1 root root  15137 Jun  4 19:06 check_ifoperstatus

-rwxr-xr-x. 1 root root  12601 Jun  4 19:06 check_ifstatus

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_imap -> check_tcp

-rwxr-xr-x. 1 root root  6890 Jun  4 19:06 check_ircd

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_jabber -> check_tcp

-rwxr-xr-x. 1 root root 106623 Jun  4 19:06 check_ldap

lrwxrwxrwx. 1 root root   10 Jun  4 19:06 check_ldaps -> check_ldap

-rwxr-xr-x. 1 root root 106565 Jun  4 19:06 check_load

-rwxr-xr-x. 1 root root  6020 Jun  4 19:06 check_log

-rwxr-xr-x. 1 root root  20287 Jun  4 19:06 check_mailq

-rwxr-xr-x. 1 root root  93126 Jun  4 19:06 check_mrtg

-rwxr-xr-x. 1 root root  92471 Jun  4 19:06 check_mrtgtraf

-rwxr-xr-x. 1 root root 129508 Jun  4 19:06 check_mysql

-rwxr-xr-x. 1 root root 122490 Jun  4 19:06 check_mysql_query

-rwxr-xr-x. 1 root root 105598 Jun  4 19:06 check_nagios

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_nntp -> check_tcp

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_nntps -> check_tcp

-rwxr-xr-x. 1 root root 127807 Jun  4 19:06 check_nt

-rwxr-xr-x. 1 root root 130198 Jun  4 19:06 check_ntp

-rwxr-xr-x. 1 root root 119287 Jun  4 19:06 check_ntp_peer

-rwxr-xr-x. 1 root root 117856 Jun  4 19:06 check_ntp_time

-rwxr-xr-x. 1 root root 159492 Jun  4 19:06 check_nwstat

-rwxr-xr-x. 1 root root  8324 Jun  4 19:06 check_oracle

-rwxr-xr-x. 1 root root 109022 Jun  4 19:06 check_overcr

-rwxr-xr-x. 1 root root 105553 Jun  4 19:06 check_pgsql

-rwxr-xr-x. 1 root root 132787 Jun  4 19:06 check_ping

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_pop -> check_tcp

-rwxr-xr-x. 1 root root 396825 Jun  4 19:06 check_procs

-rwxr-xr-x. 1 root root 106620 Jun  4 19:06 check_real

-rwxr-xr-x. 1 root root  9584 Jun  4 19:06 check_rpc

-rwxr-xr-x. 1 root root  1412 Jun  4 19:06 check_sensors

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_simap -> check_tcp

-rwxr-xr-x. 1 root root 445174 Jun  4 19:06 check_smtp

-rwxr-xr-x. 1 root root 447023 Jun  4 19:06 check_snmp

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_spop -> check_tcp

-rwxr-xr-x. 1 root root 103128 Jun  4 19:06 check_ssh

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_ssmtp -> check_tcp

-rwxr-xr-x. 1 root root 108201 Jun  4 19:06 check_swap

-rwxr-xr-x. 1 root root 158985 Jun  4 19:06 check_tcp

-rwxr-xr-x. 1 root root 105150 Jun  4 19:06 check_time

lrwxrwxrwx. 1 root root    9 Jun  4 19:06 check_udp -> check_tcp

-rwxr-xr-x. 1 root root 117678 Jun  4 19:06 check_ups

-rwxr-xr-x. 1 root root  83418 Jun  4 19:06 check_users

-rwxr-xr-x. 1 root root  2939 Jun  4 19:06 check_wave

-rwxr-xr-x. 1 root root 109707 Jun  4 19:06 negate

-rwxr-xr-x. 1 root root 103234 Jun  4 19:06 urlize

-rwxr-xr-x. 1 root root  1939 Jun  4 19:06 utils.pm

-rwxr-xr-x. 1 root root  2728 Jun  4 19:06 utils.sh

8、

7.递归更改Nagios主路径的属主

[root@KCentOS5C nagios-plugins-1.4.10]# chown -R nagios.nagios /usr/local/nagios/

8.递归增加Nagios主路径同组用户读写属性

[root@KCentOS5C nagios-plugins-1.4.10]# chmod -R g+wr /usr/local/nagios/



四.配置Apache服务:
1.备份Apache服务的主配置文件
[root@KCentOS5C ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup

2.配置Apache服务的主配置文件
[root@KCentOS5C ~]# vi /etc/httpd/conf/httpd.conf
这里主要改动以下这些参数:
-----------------------------------------------------
ServerName *:80

配置Apache的服务器名,如果有域名的话请填写正确的服务器名。

Include conf.d/*.conf

确认Apache扩展配置文件的存放路径。
-----------------------------------------------------


3.察看Nagios网页配置模板文件
[root@KCentOS5C ~]# less nagios-2.9/sample-config/httpd.conf
-----------------------------------------------------
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file.  Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

设定了Nagios的CGI执行目录对应的系统路径。


#  SSLRequireSSL
 Options ExecCGI
 AllowOverride None
 Order allow,deny
 Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
 AuthName "Nagios Access"
 AuthType Basic
 AuthUserFile /usr/local/nagios/etc/htpasswd.users

这里指定了访问用户帐户库文件。
 Require valid-user

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

设定了Nagios的网页URL对应的系统路径。


#  SSLRequireSSL
 Options None
 AllowOverride None
 Order allow,deny
 Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
 AuthName "Nagios Access"
 AuthType Basic
 AuthUserFile /usr/local/nagios/etc/htpasswd.users

这里指定了访问用户帐户库文件
 Require valid-user

-----------------------------------------------------
基本上这个文件可以直接使用。根据这个配置文件中指定的AuthUserFile项,它指定的是通过Apache访问Nagios的合法用户的帐户名单库文件,需要使用htpasswd命令对这个名单库进行用户的添加。而默认安装环境下在/usr/local/nagios/etc/目录下是没有htpasswd.user这个文件的,所以需要手动添加。请特别注意,用root身份建立的htpasswd.user文件的权限问题,应该在建立该文件完毕后立即更改为nagios用户nagios组的所有权,并且要增加Nagios同组用户读写权限。


4.整合Nagios网页配置文件到Apache中
将Nagios网页配置文件作为Apache的扩展配置文件复制改名到Apache的扩展配置文件目录/etc/httpd/conf.d/目录下
[root@KCentOS5C ~]# cp nagios-2.9/sample-config/httpd.conf /etc/httpd/conf.d/nagios-httpd.conf

5.建立Nagios的网页访问用户帐户文件(这里必须要与Nagios网页配置文件当中AuthUserFile指定的路径文件名一致)
[root@KCentOS5C ~]# touch /usr/local/nagios/etc/htpasswd.user

6.更改Nagios网页访问用户帐户文件的属主
[root@KCentOS5C ~]# chown nagios.nagios /usr/local/nagios/etc/htpasswd.users

7.对Nagios网页访问用户帐户文件增加同组成员读写权限(这主要是赋给apache这个系统用户)
[root@KCentOS5C ~]# chmod g+wr /usr/local/nagios/etc/htpasswd.users

8.察看Nagios网页访问用户帐户文件的属性信息
[root@KCentOS5C ~]# ll /usr/local/nagios/etc/htpasswd.users
-rw-rw-r-- 1 nagios nagios 0 Oct  5 14:05 /usr/local/nagios/etc/htpasswd.users

9.添加htpasswd.user用户
我添加了一个kanecruise用户,口令是123456。
[root@KCentOS5C ~]# htpasswd -m /usr/local/nagios/etc/htpasswd.user kanecruise
------------------------------------------------------------
New password: 123456
Re-type new password: 123456
Adding password for user kanecruise
------------------------------------------------------------


10.察看htpasswd的使用方法,这里我就解释一些比较重要和常用的。
[root@KCentOS5C ~]# htpasswd
-------------------------------------------------------------
Usage:
    htpasswd [-cmdpsD] passwordfile username
    htpasswd -b[cmdpsD] passwordfile username password
    htpasswd -n[mdps] username
    htpasswd -nb[mdps] username password

-c  Create a new file.
  建立新的帐户库文件。

-n  Don't update file; display results on stdout.

-m  Force MD5 encryption of the password.
  添加一个MD5口令加密的新用户。

-d  Force CRYPT encryption of the password (default).

-p  Do not encrypt the password (plaintext).
  添加一个口令不加密的新用户。

-s  Force SHA encryption of the password.
  添加一个SHA口令加密的新用户。

-b  Use the password from the command line rather than prompting for it.

-D  Delete the specified user.
  删除一个指定的用户

On Windows, NetWare and TPF systems the '-m' flag is used by default.
在Windows、NetWare以及TPF这些操作系统中“-m”参数(启用MD5对口令加密)是默认使用的
On all other systems, the '-p' flag will probably not work.
在其他的所有操作系统中“-p”(不对口令启用加密)参数将可能会引起失败。
-------------------------------------------------------------


11.检查htpasswd帐户文件
[root@KCentOS5C ~]# cat /usr/local/nagios/etc/htpasswd.users
-------------------------------------------------------------
kanecruise:$apr1$Qwk9h/..$HaRakpabADGZL10dwPcrx1
-------------------------------------------------------------
用户添加正确,并且口令都以MD5的方式加密了。

五.Nagios的配置文件:
默认下Nagios编译安装后都没有现成的配置文件,它们都以模板配置文件的方式在/usr/local/nagios/etc/这个主配置路径下,需要手动复制并配置成可用的配置文件。

1.处理Nagios的主配置文件
Nagios的主配置文件为nagios.cfg。
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/nagios.cfg-sample /usr/local/nagios/etc/nagios.cfg

2.配置Nagios的主配置文件
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/nagios.cfg
主要修改和确认以下几个较重要的配置项,其余的类似优化涉及到的配置调整这里暂不交待了。这次不像上回我用RPM包安装Nagios那次的配置方式,这次我打算将所有Nagios功能定义配置都集中在localhost.cfg这一个文件当中去,而命令定义文件commands.cfg独立保存一个文件,因此除了这两个文件不注释外,其他的Nagios功能定义文件都保持注释状态。
-------------------------------------------------------------
log_file=/usr/local/nagios/var/nagios.log
确认Nagios服务的日志记录文件,需要确认此项是解注状态的。默认编译安装后没有该文件,要手动添加并指定适当的读写权限。

cfg_file=/usr/local/nagios/etc/commands.cfg
在Nagios中将对应功能插件定义成命令的命令定义文件,需要确认此项是解注状态的。默认编译安装后也没有该文件,需要从模版复制。

cfg_file=/usr/local/nagios/etc/localhost.cfg
设定Naigos对象功能定义的配置文件,需要确认此项是解注状态的。默认编译安装后也没有该文件,需要从模版复制。

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

设定Nagios的资源文件,需要确认此项是解注状态的。默认编译安装后也没有该文件,需要从模版复制。

#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
#cfg_file=/usr/local/nagios/etc/timeperiods.cfg
#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
以上这些分块功能的定义配置文件需要保持注释,因为这些文件的作用都已经集中到localhost.cfg这一个文件当中去了。

nagios_user=nagios
nagios_group=nagios
设定Nagios服务的宿主用户和组。

#check_external_commands=0
check_external_commands=1
设定Nagios外部检查命令功能开关,默认是值0。将原来的注释掉,更改为值1,必须要打开该功能,否则CGI将不能调用。

command_check_interval=15s
#command_check_interval=-1
设定命令检查的时间间隔,将原来值-1的项注释掉,启用原来备用值为15s(15秒)。这项的时间间隔值请按实际需求情况设定。
-------------------------------------------------------------

对Nagios的主日志文件的操作如下:

手动建立Nagios主日志文件
[root@KCentOS5C ~]# touch /usr/local/nagios/var/nagios.log


改变Nagios主日志文件的属主。

[root@KCentOS5C ~]# chown nagios.nagios /usr/local/nagios/var/nagios.log


添加同组成员的读写权限。

[root@KCentOS5C ~]# chmod g+rw /usr/local/nagios/var/nagios.log


查看日志文件的属性。

[root@KCentOS5C ~]# ll /usr/local/nagios/var/nagios.log
-rw-rw-r-- 1 nagios nagios 0 Oct  5 15:28 /usr/local/nagios/var/nagios.log



3.处理Nagios的CGI配置文件:
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/cgi.cfg-sample /usr/local/nagios/etc/cgi.cfg

4.配置Nagios的CGI配置文件
[root@KCentOS5C ~]# vi /usr/local/nagios/etc/cgi.cfg
这里主要注意关于访问用户身份验证的配置项的设定。Nagios系统将各种操作行为的授权用户分的非常的仔细,所以在实际应用当中可以分的非常细,什么用户可以做哪些操作而哪些用户又没有权限做哪些操作。但是这里我只简单的授权给同一个用户。请特别注意,这里的授权用户的对象必须只能够是在htpasswd中添加注册过的用户。
-------------------------------------------------------------
use_authentication=1
设定启用身份验证。

authorized_for_system_information=kanecruise
设定系统信息的授权用户。

authorized_for_configuration_information=kanecruise
设定配置信息的授权用户。

authorized_for_system_commands=kanecruise
设定系统命令的授权用户。

authorized_for_all_services=kanecruise
设定全部监测服务的授权用户。

authorized_for_all_hosts=kanecruise
设定全部被监测主机的授权用户。

authorized_for_all_service_commands=kanecruise
设定全部监测服务命令的授权用户。

authorized_for_all_host_commands=kanecruise
设定全部主机命令的授权用户。
-------------------------------------------------------------

5.处理Nagios的命令定义文件
[root@KCentOS5C ~]# cp /usr/local/nagios/etc/commands.cfg-sample /usr/local/nagios/etc/commands.cfg

6.处理Nagios的资源文件

[root@KCentOS5C ~]# cp /usr/local/nagios/etc/resource.cfg-sample /usr/local/nagios/etc/resource.cfg


目前来说暂时不需要对Nagios命令定义文件做什么修改。但是如果要添加新的命令或者修改现有命令的定义的话,则需要修改该文件。

感谢各位的阅读,以上就是“nagios的安装配置方法”的内容了,经过本文的学习后,相信大家对nagios的安装配置方法这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:nagios的安装配置方法-创新互联
转载来于:http://shouzuofang.com/article/didsoh.html

其他资讯