阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下Nagios的安装与配置

151次阅读
没有评论

共计 33678 个字符,预计需要花费 85 分钟才能阅读完成。

一、Nagios 概述

1、简介

Nagios 是插件式的结构,它本身没有任何监控功能,所有的监控都是通过插件进行的,因此其是高度模块化和富于弹性的。Nagios 监控的对象可分为两类:主机和服务。主机通常指的是物理主机,如服务器、路由器、工作站和打印机等,这里的主机也可以是虚拟设备,如 xen 虚拟出的 Linux 系统;而服务通常指某个特定的功能,如提供 http 服务的 httpd 进程等。而为了管理上的方便,主机和服务还可以分别被规划为主机组和服务组等。

Nagios 不监控任何具体数值指标 (如操作系统上的进程个数),它仅用四种抽象属性对被监控对象的状态进行描述:OK、WARNING, CRITICAL 和 UNKNOWN。于是,管理员只需要对某种被监控对象的 WARNING 和 CRITICAL 状态的阈值进行关注和定义即可。Nagios 通过将 WARTING 和 CRTICAL 的阈值传递给插件,并由插件负责某具体对象的监控及结果分析,其输出信息为状态信息(OK,WARNING,CRITICAL 或 UNKOWN) 以及一些附加的详细说明信息。

2、特性

由上述说明可以,Nagios 是极富弹性的,其监控功能完全可以按照管理员的期望进行。此外,它外提供了对问题的自动响应能力和一个功能强大的通知系统。所有这些功能的实现是基于一个结构明晰的对象定义系统和少数几个对象类型实现的。

1) 命令(Commands)

“命令”用于定义 Nagios 如何执行某特定的监控工作。它是基于某特定的 Nagios 插件定义出的一个抽象层,通常包含一组要执行的操作。

2)时段(Time periods)

“时段”用于定义某“操作”可以执行或不能执行的日期和时间跨度,如工作日内的每天 8:00-18:00 等;

3)联系人和联系人组(Contacts and contact groups)

“联系人”用于定义某监控事件的通知对象、要通知的信息以及这些接收通知者何时及如何接收通知;一个或多个联系人可以定义为联系人组,而一个联系人也可以属于多个组;

4) 主机和主机组(Host and Host groups)

“主机”通常指某物理主机,其包括此主机相关的通知信息的接收者(即联系人)、如何及何时进行监控的定义。主机也可以分组,即主机组(host groups),一个主机可同时属于多个组;

5) 服务(Services)

“服务”通常指某主机上可被监控的特定的功能或资源,其包括此服务相关的通知信息的接收者、如何及何时进行监控等。服务也可以分组,即服务组(Service groups),一个服务可同时属于多个服务组;

3、依赖关系

Nagios 的强大功能还表现在其成熟的依赖关系系统上。比如,某路由设备故障必然会导致关联在其上的其它主机无法被正常访问,如果不能定义这些设备间的依赖关系,那么监控系统上必然会出现大量的设备故障信息。而 Nagios 则通过依赖关系来描述网络设备的拓扑结构,并能够实现在某设备故障时不再对依赖于此设备的其它设备进行检测,从而避免了无谓的故障信息,方便管理员及时定位并排除故障。此外,Nagios 的依赖关系还可以在服务级别上实现,如果某服务依赖于其它服务时,也能实现类似主机依赖关系的功能。

4、宏

Nagios 还能够使用宏,并且宏的定义在整个 Nagios 系统中具有一致性。宏是能够用于对象定义中的变量,其值通常依赖于上下文。在“命令”中定义的宏,相对于主机、服务或其它许多参数来说,其值会随之不同。比如,某命令可以根据向其传递的 IP 地址的不同来监控不同的主机。

5、计划中宕机

Nagios 还提供了调度性计划中的宕机机制,管理员可以周期性的设定某主机或服务为计划中的不可用状态。这种功能可以阻止 Nagios 在调度宕机时段通知任何信息。当然,这也可以让 Nagios 自动通知管理员该进行主机或服务维护了。

6、软状态和硬状态(Soft and Hard States)

如上所述,Nagios 的主要工作是检测主机或服务的状态,并将其存储下来。某一时刻,主机或服务状态仅可以是四种可用状态之一,因此,其状态能够正确反映主机或服务的实际状况就显得特别关键。为了避免某偶然的临时性或随机性问题,Nagios 引入了软状态和硬状态。在实际的检测中,Nagios 一旦发现某主机或服务的状态为 UNKOWN 或不同于上一次检测时的状态,其将会对此主机或服务进行多次测试以确保此状态的变动是非偶然性的。具体共要做出几次测试是可以配置的,在这个指定次数的测试时段内,Nagios 假设此变化后的状态为软件状态。一旦测试完成后状态仍然为新变的状态时,此状态就成了硬状态。

二、安装配置 Nagios

1、Nagios 程序简介

Nagios 通常由一个主程序 (Nagios)、一个插件程序(Nagios-plugins) 和四个可选的 ADDON(NRPE、NSCA、NSClient++ 和 NDOUtils)组成。Nagios 的监控工作都是通过插件实现的,因此,Nagios 和 Nagios-plugins 是服务器端工作所必须的组件。而四个 ADDON 中,NRPE 用来在监控的远程 Linux/Unix 主机上执行脚本插件以实现对这些主机资源的监控;NSCA 用来让被监控的远程 Linux/Unix 主机主动将监控信息发送给 Nagios 服务器 (这在冗余监控模式中特别要用到);NSClient++ 是用来监控 Windows 主机时安装在 Windows 主机上的组件;而 NDOUtils 则用来将 Nagios 的配置信息和各 event 产生的数据存入数据库,以实现这些数据的快速检索和处理。这四个 ADDON(附件) 中,NRPE 和 NSClient++ 工作于客户端,NDOUtils 工作于服务器端,而 NSCA 则需要同时安装在服务器端和客户端。

Linux 下 Nagios 的安装与配置

目前,Nagios 只能安装在 Linux 系统主机上,其编译需要用到 gcc。同时,如果打算使用 web 界面的管理工具的话,还需要有 apache 服务器和 GD 图形库的支持。

在 Ubuntu 下配置 Mrtg 监控 Nginx 和服务器系统资源 http://www.linuxidc.com/Linux/2013-08/88417.htm

使用 snmp+Mrtg 监控 Linux 系统 http://www.linuxidc.com/Linux/2012-11/73561.htm

Mrtg 服务器搭建(监控网络流量)http://www.linuxidc.com/Linux/2012-07/64315.htm

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统(使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

2、安装前的准备工作

(1)解决安装 Nagios 的依赖关系:

Nagios 基本组件的运行依赖于 httpd、gcc、gd。可以通过以下命令来检查 nagios 所依赖的 rpm 包是否已经完全安装:

[root@DB2 ~]# yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server

说明:以上软件包您也可以通过编译源代码的方式安装,只是后面许多要用到的相关文件的路径等需要按照您的源代码安装时的配置逐一修改。此外,您还得按需启动必要的服务,如 httpd 等。

(2)添加 nagios 运行所需要的用户和组:

[root@DB2 ~]# groupadd nagcmd

[root@DB2 ~]# useradd -G nagcmd nagios

[root@DB2 ~]# passwd nagios

把 apache 加入到 nagcmd 组,以便于在通过 web Interface 操作 nagios 时能够具有足够的权限:

[root@DB2 ~]# usermod -a -G nagcmd apache

3、编译安装 nagios:

[root@DB2 ~]# tar -zxf nagios-3.3.1.tar.gz

[root@DB2 ~]# cd nagios

[root@DB2 nagios]# ./configure –with-command-group=nagcmd –enable-event-broker

*** Configuration summary for nagios 3.3.1 07-25-2011 ***:

 General Options:

 ————————-

        Nagios executable:  nagios

        Nagios user/group:  nagios,nagios

      Command user/group:  nagios,nagcmd

            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

 

 Web Interface Options:

 ————————

                HTML URL:  http://localhost/nagios/

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

 Traceroute (used by WAP): 

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

type ‘make all’ to compile the main program and CGIs.
 

[root@DB2 nagios]# make all

*** 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-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!

 

  make install-webconf

    – This installs the Apache config file for the Nagios

      web interface

 

  make install-exfoliation

    – This installs the Exfoliation theme for the Nagios

      web interface

 

  make install-classicui

    – This installs the classic theme for the Nagios

      web interface

 

 

 

*** Support Notes *******************************************

 

If you have questions about configuring or running Nagios,

please make sure that you:

 

    – Look at the sample config files

    – Read the documentation on the Nagios Library at:

          http://library.nagios.com

 

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://support.nagios.com

 

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

 

Enjoy.
 

[root@DB2 nagios]# make install

*** 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

 

make[1]: Leaving directory `/root/nagios’
 

[root@DB2 nagios]# make install-init

 

/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d

/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

 

*** Init script installed ***
 

[root@DB2 nagios]# make install-commandmode

 

/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw

chmod g+s /usr/local/nagios/var/rw

 

*** External command directory configured ***
 

[root@DB2 nagios]# make install-config

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg

/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

 

*** Config files 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.
 

 

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

[root@DB2 nagios]# vi /usr/local/nagios/etc/objects/contacts.cfg

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

 

在 httpd 的配置文件目录 (conf.d) 中创建 Nagios 的 Web 程序配置文件:

[root@DB2 nagios]# cd /etc/httpd/conf.d/

[root@DB2 nagios]# make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

 

*** Nagios/Apache conf file installed ***
 

 

创建一个登录 nagios web 程序的用户,这个用户帐号在以后通过 web 登录 nagios 认证时所用:

 

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

New password:

Re-type new password:

Adding password for user nagiosadmin
 

 

以上过程配置结束以后需要重新启动 httpd:

[root@DB2 nagios]# service httpd restart

Stopping httpd: [OK]

Starting httpd: httpd: apr_sockaddr_info_get() failed for DB2

httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName

[OK]
 

 

Apache 的安装:

[root@DB2 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz

[root@DB2 ~]# tar -zxf httpd-2.2.23.tar.gz

[root@DB2 ~]# cd httpd-2.2.23

[root@DB2 httpd-2.2.23]# ./configure –prefix=/usr/local/apache2

[root@DB2 httpd-2.2.23]# make && make install

 

[root@DB2 php-5.6.2]# yum -y install libxml2

[root@DB2 php-5.6.2]# yum install libxml2-devel -y

 

PHP 的安装:

[root@DB2 ~]# wget http://cn2.php.net/distributions/php-5.6.2.tar.gz

[root@DB2 ~]# tar zxf php-5.6.2.tar.gz

[root@DB2 ~]# cd php-5.6.2

[root@DB2 php-5.6.2]# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs

 

Generating files

configure: creating ./config.status

creating main/internal_functions.c

creating main/internal_functions_cli.c

+——————————————————————–+

| License:                                                          |

| This software is subject to the PHP License, available in this    |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.    |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+——————————————————————–+

 

Thank you for using PHP.

 

config.status: creating php5.spec

config.status: creating main/build-defs.h

config.status: creating scripts/phpize

config.status: creating scripts/man1/phpize.1

config.status: creating scripts/php-config

config.status: creating scripts/man1/php-config.1

config.status: creating sapi/cli/php.1

config.status: creating sapi/cgi/php-cgi.1

config.status: creating ext/phar/phar.1

config.status: creating ext/phar/phar.phar.1

config.status: creating main/php_config.h

config.status: executing default commands
 

[root@DB2 php-5.6.2]# make && make install

Build complete.

Don’t forget to run ‘make test’.

 

Installing PHP SAPI module:      apache2handler

/usr/local/apache2/build/instdso.sh SH_LIBTOOL=’/usr/local/apache2/build/libtool’ libphp5.la /usr/local/apache2/modules

/usr/local/apache2/build/libtool –mode=install cp libphp5.la /usr/local/apache2/modules/

cp .libs/libphp5.so /usr/local/apache2/modules/libphp5.so

cp .libs/libphp5.lai /usr/local/apache2/modules/libphp5.la

libtool: install: warning: remember to run `libtool –finish /root/php-5.6.2/libs’

chmod 755 /usr/local/apache2/modules/libphp5.so

[activating module `php5′ in /usr/local/apache2/conf/httpd.conf]

Installing shared extensions:    /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

Installing PHP CLI binary:        /usr/local/php/bin/

Installing PHP CLI man page:      /usr/local/php/php/man/man1/

Installing PHP CGI binary:        /usr/local/php/bin/

Installing PHP CGI man page:      /usr/local/php/php/man/man1/

Installing build environment:    /usr/local/php/lib/php/build/

Installing header files:          /usr/local/php/include/php/

Installing helper programs:      /usr/local/php/bin/

  program: phpize

  program: php-config

Installing man pages:            /usr/local/php/php/man/man1/

  page: phpize.1

  page: php-config.1

Installing PEAR environment:      /usr/local/php/lib/php/

[PEAR] Archive_Tar    – installed: 1.3.12

[PEAR] Console_Getopt – installed: 1.3.1

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util      – installed: 1.2.3

[PEAR] PEAR          – installed: 1.9.5

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf

You may want to add: /usr/local/php/lib/php to your php.ini include_path

/root/php-5.6.2/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin

ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar

Installing PDO headers:          /usr/local/php/include/php/ext/pdo/

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2015-01/111554p2.htm

4、编译、安装 nagios-plugins

nagios 的所有监控工作都是通过插件完成的,因此,在启动 nagios 之前还需要为其安装官方提供的插件。

[root@DB2 ~]# tar zxf nagios-plugins-1.4.15.tar.gz

[root@DB2 ~]# cd nagios-plugins-1.4.15

[root@DB2 nagios-plugins-1.4.15]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios

[root@DB2 nagios-plugins-1.4.15]# make && make install

 

5、配置并启动 Nagios

 

(1)把 nagios 添加为系统服务并将之加入到自动启动服务队列:

[root@DB2 ~]# chkconfig –add nagios

[root@DB2 ~]# chkconfig –level 35 nagios on

[root@DB2 ~]# chkconfig –list nagios

nagios          0:off  1:off  2:off  3:on    4:on    5:on    6:off

 

(2)检查其主配置文件的语法是否正确:

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

 

(3)如果上面的语法检查没有问题,接下来就可以正式启动 nagios 服务了:

[root@DB2 nagios]# service nagios start

Starting nagios: done.

 

(4)配置 selinux

如果您的系统开启了 selinux 服务,则默认为拒绝 nagios web cgi 程序的运行。您可以通过下面的命令来检查您的系统是否开启了 selinux:

[root@DB2 ~]# getenforce

 

如果上面命令的结果显示开启了 selinux 服务,您可以通过下面的命令暂时性的将其关闭:

[root@DB2 ~]# setenforce 0

 

[root@DB2 ~]# service iptables stop

iptables: Setting chains to policy ACCEPT: filter [OK]

iptables: Flushing firewall rules: [OK]

iptables: Unloading modules: [OK]

[root@DB2 ~]# set enforce 0

 

如果您想在以后完全关闭 selinux,可以通过编辑 /etc/sysconfig/selinux 文件,将其中的 selinux 后面的值“force”修改为“disable”即可。

 

当然,您也可以通过以下方式将 nagios 的 CGI 程序运行于 SELinux/targeted 模式而不用关闭 selinux:

[root@DB2 ~]# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin

[root@DB2 ~]# chcon -R -t httpd_sys_content_t /usr/local/nagios/share

 

(5)通过 web 界面查看 nagios:

 

http://192.168.123.132/nagios

 

登录时需要指定前面设定的 web 认证帐号和密码。

 

wKiom1R5l06iHFB3AAEhHuw5evI770.jpg

 

 

wKioL1R5mB6jUsNhAAUXnds-Ycw483.jpg

 

注意:为了 nagios 系统的安全,建议您使用信息摘要强认证模式(如 MD5),强制使用 web 的 TSL/SSL 安全通讯模式,并且通过访问控制列表设定能访问 nagios 的 web 界面的客户端地址。

 

四、配置 Nagios

 

1、Nagios 的主配置文件

Nagios 的主配置文件为 nagios.cfg,其语法非常简洁,通常 #开头的行为注释行,而参数的设置格式为 <parameter>=<value>;其中,有些参数是可以重复出现的。其中常用的参数说明如下:

 

log_file: 设定 Nagios 的日志文件;

cfg_file: Nagios 对象定义的相关文件,此参数可重复使用多次以指定多个文件;

cfg_dir:  设定 Nagios 对象定义的相关文件所在的目录,此目录中的所有文件都会被作为对象定义的文件;此参数可重复使用多次以指定多个目录;

resource_file: 设定 Nagios 附加的宏定义的相关文件;

status_file: 设定 Nagios 存储所有主机和服务当前状态信息的文件;

status_update_interval: 设定 status_file 指定的文件中状态信息的更新频率;

service_check_timeout: 设定服务检测的超时时间,默认为 60 秒;

host_check_timeout: 设定主机检测的超时时间,默认为 30 秒;

notification_timeout: 设定通知信息发送尝试的超时时间,默认为 30 秒;
 

 

 

2、resource_file 和宏定义

在主配置文件中,参数 resource_file 用于定义所有用户变量 (即“宏”) 的存储文件,它用于存储对象定义中的可以访问的额外信息,如访问某服务的密码等;因此,这些信息通常都是些敏感数据,一般不允许通过 Web 接口来访问。此文件中可以定义的宏可多达 32 个,它们分别为 $USER1$,$USER2$…$USER32,这些宏一般在 check 命令中引用。通常情况下 $USER1$ 用于引用 Nagios 插件所在目录这个路径信息,因此,一般不建议修改其值。

 

Nagios 事先定义了许多宏,它们的值通常依赖于其上下文。如下:

 

HOSTNAME: 用于引用 host_name 指定所定义的主机的主机名;每个主机的主机名都是唯一的;

HOSTADDRESS: 用于引用 host 对象中的 address 指令的值,它通常可以为 IP 地址或主机名;

HOSTDISPLAYNAME: 用于引用 host 对象中 alias 指令的值,用以描述当前主机,即主机的显示名称;

HOSTSTATE:某主机的当前状态,为 UP,DOWN,UNREACHABLE 三者之一;

HOSTGROUPNAMES: 用于引用某主机所属的所有主机组的简名,主机组名称之间以逗号分隔;

LASTHOSTCHECK:用于引用某主机上次检测的时间和日期,Unix 时间戳格式;

LISTHOSTSTATE:用于引用某主机前一次检测时的状态,为 UP,DOWN 或 UNREACHABLE 三者之一;

SERVICEDESC: 用于引用对应 service 对象中的 desccription 指令的值;

SERVICESTATE: 用于引用某服务的当前状态,为 OK,WARNING,UNKOWN 或 CRITICAL 四者之一;

SERVICEGROUPNAMES: 用于引用某服务所属的所有服务组的简名,服务组名称之间以逗号分隔;

CONTACTNAME: 用于引用某 contact 对象中 contact_name 指令的值;

CONTACTALIAS: 用于引用某 contact 对象中 alias 指令的值;

CONTACTEMAIL: 用于引用某 contact 对象中 email 指令的值;

CONTACTGROUPNAMES: 用于引用某 contact 所属的所有 contact 组的简名,contact 组名称之间以逗号分隔;

 

Nagios 3 还支持自定义宏,只是它的定义和使用方式比较独特。管理员可以在某类型对象的定义中使用额外的指令,并能够在命令中使用特别格式的宏来引用此指令的值。其引用方式根据对象类型的不同也有所不同,具体如下:

 

$_HOST<variable>$ – 引用在主机对象中定义的指令的值;

$_SERVICE<variable>$ – 引用在服务对象中定义的指令的值;

$_CONTACT<variable>$ – 引用在联系人对象中定义的指令的值;

 

一个简单的例子如下:

 

如某主机定义为:

define host

  {

    host_name somemachine

    address 10.0.0.1

    _MAC 12:34:56:78:90:ab

    check_command check-host-by-mac

  }

 

对应的检测命令则可以定义为:

  define command

  {

    command_name check-host-by-mac

    command_line $USER1$/check_hostmac -H $HOSTADDRESS$ -m $_HOSTMAC$

  }
 

 

 

 

3、定义主机对象

“主机”指的是被监控的机器,可是物理主机,也可以是虚拟设备。一个主机对象的定义至少应该包含一个简名(short name)、一个别名、一个 IP 地址和用到的检测命令。此外,很多时候,其定义中还应该包含监控时段、联系人及要通知的相关问题、检测的频率、重试检测的方式、发送通知的频率等。具体的各指令及说明请参见官方文档:http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html#host。

 

一个主机定义的例子:

define host

{

host_name webserver1

hostgroups webservers

alias www.magedu.com

address 172.16.100.11

check_command check-host-alive

check_interval 5

retry_interval 1

max_check_attempts 5

check_period 24×7

contact_groups linux-admins

notification_interval 30

notification_period 24×7

notification_options d,u,r

}

 

其中的 notification_options 用于指定当主机处于什么状态时应该发送通知。其各状态及其表示符如下:

d —— DOWN

u —— UNREACHABLE

r —— UP(host recovery)

f —— flapping

s —— 调试宕机时间开始或结束

 

主机可以被划分成组,这些组即主机组。每一个主机组对象一般包含一个全局唯一的简名、一个描述名以及属于这个组的成员。此外,一个主机组的成员也可以是其它主机组。主机组的定义例子如下:

 

define hostgroup

{

hostgroup_name webservers

alias Linux web servers

members webserver1

}
 

 

4、定义服务对象

“服务”即某“主机”所提供的功能或资源对象,如 HTTP 服务、存储空间资源或 CPU 负载等。服务附属于主机,每一个服务使用服务名来标识,此服务名要求在特定的主机上具有唯一性。每一个服务对象还通常定义一个检测命令及如何进行问题通知等。

 

define service

{

host_name webserver1

service_description www

check_command check_http

check_interval 10

check_period 24×7

retry_interval 3

max_check_attempts 3

notification_interval 30

notification_period 24×7

notification_options w,c,u,r

contact_groups linux-admins

}

 

其中的 notification_options 用于指定当服务处于什么状态时应该发送通知。其各状态及其表示符如下:

w —— WARNING

u —— UNKNOWN

c —— CRITICAL

r —— OK(recovery)

f —— flapping

s —— 调试宕机时间开始或结束

 

与主机对象有所不同的是,有时个,多个主机可能会提供同样的服务,比如多台服务器同时提供 Web 等。因此,在定义服务对象时,其 host_name 可以为逗号隔开的多个主机。

 

服务可以被划分成组,这些组即服务组。每一个服务组对象一般包含一个全局唯一的简名、一个描述名以及属于这个组的成员。此外,一个服务组的成员通常是某主机上的某服务,其指定时使用 <host>,<service> 的格式,多个服务也使用逗号分隔。服务组的定义例子如下:

 

define servicegroup

{

servicegroup_name webservices

alias All services related to web

members webserver1,www,webserver2,www

}
 

 

 

 

5、定义命令对象

“命令”用于描述如何对主机或服务进行状态检测。服务对象的定义包含两个指令:名字 (command_name) 和命令行(command_line);名字用于标识此命令对象,命令行则是执行检测时真正要执行的命令。

 

当命令对象用于检测其它对象时,其通常需要用到额外的参数以标识要检测的某特定对象,此时,命令对象需要以 command_name[!arg1][!arg2][…]的语法格式进行引用。因此,命令对象的定义中,命令行指令中通常会用到宏 $ARG1$, $ARG2$…,对应用于接收 [!arg1][!arg2][…] 传递而来的参数。

 

如下命令对象的定义:

define command

{

command_namecheck_local_swap

command_line$USER1$/check_swap -w $ARG1$ -c $ARG2$

}

 

如下的服务中使用上面定义的命令对象来检测服务对象:

 

define service

{

    host_name  localhost

    service_description  Swap Usage

check_command check_local_swap!20!10

  }

 

6、定义“时段”对象

 

“时段”用于定义某“操作”可以执行或不能执行的日期和时间跨度,如工作日内的每天 8:00-18:00 等,其可以在多个不同的操作中重复引用。一个时段对象的定义包含一个全局唯一的名称标识及一个或多个时间跨度。例如:

 

define timeperiod

{

timeperiod_name workinghours

alias Working Hours, from Monday to Friday

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

}

 

其中,时间的指定格式有许多方式:

日历时间:格式为 YYYY-MM-DD,如 2012-04-21;

日期:如 April 21;

每月的某一天:如 day 21,指每月的 21 号;

每月的第几个周几:如 saturday 1,指每月的第一个星期六;

星期几:如 monday, tuesday 等;
 

 

 

7、定义联系人对象

“联系人”对象用于定义某主机设备的拥有者或某问题出现时接受通知者。联系人对象的定义包含一个全局唯一的标识名称、一个描述名及一个或多个邮件地址等。此外,其通常还应该包括对相应的主机或服务出现故障时所用到的通知命令。例如:

 

define contact

{

contact_name mageedu

alias Mage Education

email linuxedu@magedu.com

host_notification_period  workinghours

service_notification_period  workinghours

host_notification_options  d,u,r

service_notification_options  w,u,c,r

host_notification_commands    host-notify-by-email

service_notification_commands  notify-by-email

}

 

联系人也可划分为组,即联系人组。一个联系人组对象包含一个全局惟一的标识名称,一个描述名称和属于此联系人组的联系人成员 (members) 或其人联系人组成员(contactgroup_members)。例如:

 

define contactgroup

{

contactgroup_name linux-admins

alias Linux Administrators

members magedu, mageedu

}

 

在主机或服务对象的定义中,既可以指定联系人,也可以指定联系人组。当然,某主机的问题联系人与其上运行的服务的联系人也可以不同。
 

 

 

 

8、模板及对象继承

Nagios 通过功能强大的继承引擎来实现基于模板的对象继承。这就意味着可以定义将某类型的对象的通用属性组织起来定义为对象模板,并在定义其类型中的对象时直接从此模板继承其相关属性的定义。定义对象模板的方法很简单,通常只需要在定义某类型对象时使用 register 指令并将其值设定为 0 即可。对象模板的名称通常使用 name 指令定义,这与某特定类型对象使用的指令也有所不同。而定义此种类型的对象时,只需要使用 use 指令并将其值设定为对应模板的名称即可。例如:

 

define host

{

name generic-server

check_command check-host-alive

check_interval 5

retry_interval 1

max_check_attempts 5

check_period 24×7

notification_interval 30

notification_period 24×7

notification_options d,u,r

register 0

}

 

define host

{

use generic-server

name webserver1

alias Web Server 01

address 172.16.100.11

contact_groups linux-admins

}

 

一个对象在定义时也以同时继承多个模板,此时只需要为 use 指令指定以逗号分隔的多个模板名称即可。同时,Nagios 也支持模板的多级继承。
 

 

 

 

9、依赖关系

为了描述 Nagios 对象间的依赖关系,这里要用到两个术语:master(被依赖的主机或服务)和 dependent(依赖关系中的依赖于 master 的 Nagios 对象)。Nagios 可以定义对象间的彼此依赖性,也可以为某对象定义其父对象,甚至也可以指定此依赖关系生效的时段。下面是一个关于依赖关系定义的例子:

 

define hostdependency

{

dependent_host_name backuphost

host_name vpnserver1

dependency_period maintenancewindows

}

 

其中 host_name 用于定义 master 主机,dependent_host_name 定义 dependent 主机。而在依赖关系的定义中,通常还会用到 execution_failure_criteria 定义 master 主机为何种状态时不再对依赖于此 master 的主机进行检测,notification_failure_criteria 用于定义 master 处于何种状态时不会发送 dependent 相关的主机问题通知到联系人。

 

服务间依赖关系的定义类似于主机间的依赖关系,例如:

 

define servicedependency

{

host_name mysqlserver

service_description mysql

dependent_hostgroup_name apacheservers

dependent_service_description webservice

execution_failure_criteria c,u

notification_failure_criteria c,u,w

}

Nagios 的详细介绍:请点这里
Nagios 的下载地址:请点这里

一、Nagios 概述

1、简介

Nagios 是插件式的结构,它本身没有任何监控功能,所有的监控都是通过插件进行的,因此其是高度模块化和富于弹性的。Nagios 监控的对象可分为两类:主机和服务。主机通常指的是物理主机,如服务器、路由器、工作站和打印机等,这里的主机也可以是虚拟设备,如 xen 虚拟出的 Linux 系统;而服务通常指某个特定的功能,如提供 http 服务的 httpd 进程等。而为了管理上的方便,主机和服务还可以分别被规划为主机组和服务组等。

Nagios 不监控任何具体数值指标 (如操作系统上的进程个数),它仅用四种抽象属性对被监控对象的状态进行描述:OK、WARNING, CRITICAL 和 UNKNOWN。于是,管理员只需要对某种被监控对象的 WARNING 和 CRITICAL 状态的阈值进行关注和定义即可。Nagios 通过将 WARTING 和 CRTICAL 的阈值传递给插件,并由插件负责某具体对象的监控及结果分析,其输出信息为状态信息(OK,WARNING,CRITICAL 或 UNKOWN) 以及一些附加的详细说明信息。

2、特性

由上述说明可以,Nagios 是极富弹性的,其监控功能完全可以按照管理员的期望进行。此外,它外提供了对问题的自动响应能力和一个功能强大的通知系统。所有这些功能的实现是基于一个结构明晰的对象定义系统和少数几个对象类型实现的。

1) 命令(Commands)

“命令”用于定义 Nagios 如何执行某特定的监控工作。它是基于某特定的 Nagios 插件定义出的一个抽象层,通常包含一组要执行的操作。

2)时段(Time periods)

“时段”用于定义某“操作”可以执行或不能执行的日期和时间跨度,如工作日内的每天 8:00-18:00 等;

3)联系人和联系人组(Contacts and contact groups)

“联系人”用于定义某监控事件的通知对象、要通知的信息以及这些接收通知者何时及如何接收通知;一个或多个联系人可以定义为联系人组,而一个联系人也可以属于多个组;

4) 主机和主机组(Host and Host groups)

“主机”通常指某物理主机,其包括此主机相关的通知信息的接收者(即联系人)、如何及何时进行监控的定义。主机也可以分组,即主机组(host groups),一个主机可同时属于多个组;

5) 服务(Services)

“服务”通常指某主机上可被监控的特定的功能或资源,其包括此服务相关的通知信息的接收者、如何及何时进行监控等。服务也可以分组,即服务组(Service groups),一个服务可同时属于多个服务组;

3、依赖关系

Nagios 的强大功能还表现在其成熟的依赖关系系统上。比如,某路由设备故障必然会导致关联在其上的其它主机无法被正常访问,如果不能定义这些设备间的依赖关系,那么监控系统上必然会出现大量的设备故障信息。而 Nagios 则通过依赖关系来描述网络设备的拓扑结构,并能够实现在某设备故障时不再对依赖于此设备的其它设备进行检测,从而避免了无谓的故障信息,方便管理员及时定位并排除故障。此外,Nagios 的依赖关系还可以在服务级别上实现,如果某服务依赖于其它服务时,也能实现类似主机依赖关系的功能。

4、宏

Nagios 还能够使用宏,并且宏的定义在整个 Nagios 系统中具有一致性。宏是能够用于对象定义中的变量,其值通常依赖于上下文。在“命令”中定义的宏,相对于主机、服务或其它许多参数来说,其值会随之不同。比如,某命令可以根据向其传递的 IP 地址的不同来监控不同的主机。

5、计划中宕机

Nagios 还提供了调度性计划中的宕机机制,管理员可以周期性的设定某主机或服务为计划中的不可用状态。这种功能可以阻止 Nagios 在调度宕机时段通知任何信息。当然,这也可以让 Nagios 自动通知管理员该进行主机或服务维护了。

6、软状态和硬状态(Soft and Hard States)

如上所述,Nagios 的主要工作是检测主机或服务的状态,并将其存储下来。某一时刻,主机或服务状态仅可以是四种可用状态之一,因此,其状态能够正确反映主机或服务的实际状况就显得特别关键。为了避免某偶然的临时性或随机性问题,Nagios 引入了软状态和硬状态。在实际的检测中,Nagios 一旦发现某主机或服务的状态为 UNKOWN 或不同于上一次检测时的状态,其将会对此主机或服务进行多次测试以确保此状态的变动是非偶然性的。具体共要做出几次测试是可以配置的,在这个指定次数的测试时段内,Nagios 假设此变化后的状态为软件状态。一旦测试完成后状态仍然为新变的状态时,此状态就成了硬状态。

二、安装配置 Nagios

1、Nagios 程序简介

Nagios 通常由一个主程序 (Nagios)、一个插件程序(Nagios-plugins) 和四个可选的 ADDON(NRPE、NSCA、NSClient++ 和 NDOUtils)组成。Nagios 的监控工作都是通过插件实现的,因此,Nagios 和 Nagios-plugins 是服务器端工作所必须的组件。而四个 ADDON 中,NRPE 用来在监控的远程 Linux/Unix 主机上执行脚本插件以实现对这些主机资源的监控;NSCA 用来让被监控的远程 Linux/Unix 主机主动将监控信息发送给 Nagios 服务器 (这在冗余监控模式中特别要用到);NSClient++ 是用来监控 Windows 主机时安装在 Windows 主机上的组件;而 NDOUtils 则用来将 Nagios 的配置信息和各 event 产生的数据存入数据库,以实现这些数据的快速检索和处理。这四个 ADDON(附件) 中,NRPE 和 NSClient++ 工作于客户端,NDOUtils 工作于服务器端,而 NSCA 则需要同时安装在服务器端和客户端。

Linux 下 Nagios 的安装与配置

目前,Nagios 只能安装在 Linux 系统主机上,其编译需要用到 gcc。同时,如果打算使用 web 界面的管理工具的话,还需要有 apache 服务器和 GD 图形库的支持。

在 Ubuntu 下配置 Mrtg 监控 Nginx 和服务器系统资源 http://www.linuxidc.com/Linux/2013-08/88417.htm

使用 snmp+Mrtg 监控 Linux 系统 http://www.linuxidc.com/Linux/2012-11/73561.htm

Mrtg 服务器搭建(监控网络流量)http://www.linuxidc.com/Linux/2012-07/64315.htm

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统(使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

2、安装前的准备工作

(1)解决安装 Nagios 的依赖关系:

Nagios 基本组件的运行依赖于 httpd、gcc、gd。可以通过以下命令来检查 nagios 所依赖的 rpm 包是否已经完全安装:

[root@DB2 ~]# yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server

说明:以上软件包您也可以通过编译源代码的方式安装,只是后面许多要用到的相关文件的路径等需要按照您的源代码安装时的配置逐一修改。此外,您还得按需启动必要的服务,如 httpd 等。

(2)添加 nagios 运行所需要的用户和组:

[root@DB2 ~]# groupadd nagcmd

[root@DB2 ~]# useradd -G nagcmd nagios

[root@DB2 ~]# passwd nagios

把 apache 加入到 nagcmd 组,以便于在通过 web Interface 操作 nagios 时能够具有足够的权限:

[root@DB2 ~]# usermod -a -G nagcmd apache

3、编译安装 nagios:

[root@DB2 ~]# tar -zxf nagios-3.3.1.tar.gz

[root@DB2 ~]# cd nagios

[root@DB2 nagios]# ./configure –with-command-group=nagcmd –enable-event-broker

*** Configuration summary for nagios 3.3.1 07-25-2011 ***:

 General Options:

 ————————-

        Nagios executable:  nagios

        Nagios user/group:  nagios,nagios

      Command user/group:  nagios,nagcmd

            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

 

 Web Interface Options:

 ————————

                HTML URL:  http://localhost/nagios/

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

 Traceroute (used by WAP): 

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

type ‘make all’ to compile the main program and CGIs.
 

[root@DB2 nagios]# make all

*** 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-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!

 

  make install-webconf

    – This installs the Apache config file for the Nagios

      web interface

 

  make install-exfoliation

    – This installs the Exfoliation theme for the Nagios

      web interface

 

  make install-classicui

    – This installs the classic theme for the Nagios

      web interface

 

 

 

*** Support Notes *******************************************

 

If you have questions about configuring or running Nagios,

please make sure that you:

 

    – Look at the sample config files

    – Read the documentation on the Nagios Library at:

          http://library.nagios.com

 

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://support.nagios.com

 

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

 

Enjoy.
 

[root@DB2 nagios]# make install

*** 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

 

make[1]: Leaving directory `/root/nagios’
 

[root@DB2 nagios]# make install-init

 

/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d

/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

 

*** Init script installed ***
 

[root@DB2 nagios]# make install-commandmode

 

/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw

chmod g+s /usr/local/nagios/var/rw

 

*** External command directory configured ***
 

[root@DB2 nagios]# make install-config

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg

/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

 

*** Config files 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.
 

 

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

[root@DB2 nagios]# vi /usr/local/nagios/etc/objects/contacts.cfg

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

 

在 httpd 的配置文件目录 (conf.d) 中创建 Nagios 的 Web 程序配置文件:

[root@DB2 nagios]# cd /etc/httpd/conf.d/

[root@DB2 nagios]# make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

 

*** Nagios/Apache conf file installed ***
 

 

创建一个登录 nagios web 程序的用户,这个用户帐号在以后通过 web 登录 nagios 认证时所用:

 

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

New password:

Re-type new password:

Adding password for user nagiosadmin
 

 

以上过程配置结束以后需要重新启动 httpd:

[root@DB2 nagios]# service httpd restart

Stopping httpd: [OK]

Starting httpd: httpd: apr_sockaddr_info_get() failed for DB2

httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName

[OK]
 

 

Apache 的安装:

[root@DB2 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz

[root@DB2 ~]# tar -zxf httpd-2.2.23.tar.gz

[root@DB2 ~]# cd httpd-2.2.23

[root@DB2 httpd-2.2.23]# ./configure –prefix=/usr/local/apache2

[root@DB2 httpd-2.2.23]# make && make install

 

[root@DB2 php-5.6.2]# yum -y install libxml2

[root@DB2 php-5.6.2]# yum install libxml2-devel -y

 

PHP 的安装:

[root@DB2 ~]# wget http://cn2.php.net/distributions/php-5.6.2.tar.gz

[root@DB2 ~]# tar zxf php-5.6.2.tar.gz

[root@DB2 ~]# cd php-5.6.2

[root@DB2 php-5.6.2]# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs

 

Generating files

configure: creating ./config.status

creating main/internal_functions.c

creating main/internal_functions_cli.c

+——————————————————————–+

| License:                                                          |

| This software is subject to the PHP License, available in this    |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.    |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+——————————————————————–+

 

Thank you for using PHP.

 

config.status: creating php5.spec

config.status: creating main/build-defs.h

config.status: creating scripts/phpize

config.status: creating scripts/man1/phpize.1

config.status: creating scripts/php-config

config.status: creating scripts/man1/php-config.1

config.status: creating sapi/cli/php.1

config.status: creating sapi/cgi/php-cgi.1

config.status: creating ext/phar/phar.1

config.status: creating ext/phar/phar.phar.1

config.status: creating main/php_config.h

config.status: executing default commands
 

[root@DB2 php-5.6.2]# make && make install

Build complete.

Don’t forget to run ‘make test’.

 

Installing PHP SAPI module:      apache2handler

/usr/local/apache2/build/instdso.sh SH_LIBTOOL=’/usr/local/apache2/build/libtool’ libphp5.la /usr/local/apache2/modules

/usr/local/apache2/build/libtool –mode=install cp libphp5.la /usr/local/apache2/modules/

cp .libs/libphp5.so /usr/local/apache2/modules/libphp5.so

cp .libs/libphp5.lai /usr/local/apache2/modules/libphp5.la

libtool: install: warning: remember to run `libtool –finish /root/php-5.6.2/libs’

chmod 755 /usr/local/apache2/modules/libphp5.so

[activating module `php5′ in /usr/local/apache2/conf/httpd.conf]

Installing shared extensions:    /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

Installing PHP CLI binary:        /usr/local/php/bin/

Installing PHP CLI man page:      /usr/local/php/php/man/man1/

Installing PHP CGI binary:        /usr/local/php/bin/

Installing PHP CGI man page:      /usr/local/php/php/man/man1/

Installing build environment:    /usr/local/php/lib/php/build/

Installing header files:          /usr/local/php/include/php/

Installing helper programs:      /usr/local/php/bin/

  program: phpize

  program: php-config

Installing man pages:            /usr/local/php/php/man/man1/

  page: phpize.1

  page: php-config.1

Installing PEAR environment:      /usr/local/php/lib/php/

[PEAR] Archive_Tar    – installed: 1.3.12

[PEAR] Console_Getopt – installed: 1.3.1

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util      – installed: 1.2.3

[PEAR] PEAR          – installed: 1.9.5

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf

You may want to add: /usr/local/php/lib/php to your php.ini include_path

/root/php-5.6.2/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin

ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar

Installing PDO headers:          /usr/local/php/include/php/ext/pdo/

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2015-01/111554p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计33678字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中