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

Nagios服务器端安装部署详解

176次阅读
没有评论

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

下载地址如下:http://sourceforge.net/projects/nagios/files/

具体详细下载地址:http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.6.tar.gz

相关阅读

网络监控器 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

1 开始下载:
wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.0.6/nagios-4.0.6.tar.gz/download?use_mirror=jaist
如下图所示,下载 free 版本的。
Nagios 服务器端安装部署详解

安装 前准备工作,安装一些 lib 包

[root@cache-2 root]# yum -y install httpd gcc glibc glibc-common

# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel 

2 进行 selinux 设置,或者关闭 selinux

查看 SELinux 状态:

(1)/usr/sbin/sestatus -v ## 如果 SELinux status 参数为 enabled 即为开启状态

SELinux status: enabled

(2)getenforce ## 也可以用这个命令检查

关闭 SELinux:

(3)临时关闭(不用重启机器):

setenforce 0 ## 设置 SELinux 成为 permissive 模式

##setenforce 1 设置 SELinux 成为 enforcing 模式

(4)修改配置文件需要重启机器:

修改 /etc/selinux/config 文件

将 SELINUX=enforcing 改为 SELINUX=disabled

重启机器即可 

3 开始准备 nagios 安装环境

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

groupadd nagcmd

useradd -m nagios

usermod -a -G nagcmd nagios 

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

# usermod -a -G nagcmd apache 

4 编译安装准备

./configure withcommandgroup=nagios prefix=/opt/app/nagios enableembeddedperl withhttpdconf=/usr/local/apache2/conf

  1. [root@cache-2 nagios-4.0.6]# ./configure —with-command-group=nagios –prefix=/opt/app/nagios –enable-embedded-perl —with-httpd-conf=/usr/local/apache2/conf
  2. checking for a BSD-compatible install… /usr/bin/install -c
  3. checking build system type… x86_64-unknown-linux-gnu
  4. checking host system type… x86_64-unknown-linux-gnu
  5. checking for gcc… gcc
  6. checking for C compiler default output file name… a.out
  7. checking whether the C compiler works… yes
  8. checking whether we are cross compiling… no
  9. ………………………..
  10. HTML URL: http://localhost/nagios/
  11. CGI URL: http://localhost/nagios/cgi-bin/
  12. Traceroute (used by WAP): /bin/traceroute
  13. Review the options above for accuracy. If they look okay,
  14. type ‘make all’ to compile the main program and CGIs.

5 开始 make 安装
5.1 make all

[root@cache-2 nagios-4.0.6]# make all

  1. cd ./base && make
  2. make[1]: Entering directory `/root/nagios-4.0.6/base’
  3. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.c
  4. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o broker.o broker.c
  5. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nebmods.o nebmods
  6. …………………….
  7. For more information on obtaining support for Nagios, visit:
  8. http://support.nagios.com
  9. *************************************************************
  10. Enjoy.

 

5.2 make install
[root@cache-2 nagios-4.0.6]# make install

  1. cd ./base && make install
  2. make[1]: Entering directory `/root/nagios-4.0.6/base’
  3. make install-basic
  4. make[2]: Entering directory `/root/nagios-4.0.6/base’
  5. ……………………………………………..
  6. make[2]: Entering directory `/root/nagios-4.0.6/cgi’
  7. for file in *.cgi; do \
  8. /usr/bin/strip /usr/local/nagios/sbin/$file; \
  9. done

5.3 make install-config

  1. [root@cache-2 nagios-4.0.6]# make install-config
  2. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
  3. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
  4. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
  5. …………………………………………….
  6. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
  7. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
  8. *** Config files installed ***

5.4 make install-commandmode

  1. [root@cache-2 nagios-4.0.6]# make install-commandmode
  2. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
  3. chmod g+s /usr/local/nagios/var/rw
  4. *** External command directory configured ***
  5. Remember, these are *SAMPLE* config files. You’ll need to read
  6. the documentation for more information on how to actually define
  7. services, hosts, etc. to fit your particular needs.

5.5 make install-init

  1. [root@cache-2 nagios-4.0.6]# make install-init
  2. /usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
  3. /usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
  4. *** Init script installed ***

[root@cache-2 nagios-4.0.6]#

加到启动项里面去:

# chkconfig –add nagios

# chkconfig –level 35 nagios on

# chkconfig –list nagios

Nagios 服务器端安装部署详解

检查主机配置文件是否正确:

/var/www/nagios/bin/nagios -v /var/www/nagios/etc/nagios.cfg

5.6 Check 安装是否正确:

5.6.1 说明:

切换目录到安装路径(这里是 /usr/local/nagios),看是否存在 etc、bin、sbin、share、var 这五个目录,如果存在则可以表明程序被正确的安装到系统了。Nagios 各个目录用途说明如下:

bin Nagios 可执行程序所在目录

etc Nagios 配置文件所在目录

sbin Nagios CGI 文件所在目录,也就是执行外部命令所需文件所在的目录

share Nagios 网页文件所在的目录

libexec Nagios 外部插件所在目录

var Nagios 日志文件、lock 等文件所在的目录

var/archives Nagios 日志自动归档目录

var/rw 用来存放外部命令文件的目录

5.6.2 check
cd /usr/local/nagios
ll

  1. [root@cache-2 nagios-4.0.6]# cd /usr/local/nagios
  2. [root@cache-2 nagios]# ll
  3. 总用量 24
  4. drwxrwxr-x. 2 nagios nagios 4096 5 月 5 15:31 bin
  5. drwxrwxr-x. 3 nagios nagios 4096 5 月 5 15:32 etc
  6. drwxrwxr-x. 2 nagios nagios 4096 5 月 5 15:31 libexec
  7. drwxrwxr-x. 2 nagios nagios 4096 5 月 5 15:31 sbin
  8. drwxrwxr-x. 10 nagios nagios 4096 5 月 5 15:31 share
  9. drwxrwxr-x. 5 nagios nagios 4096 5 月 5 15:32 var

5.7 安装 nagios 插件
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

  1. [root@cache-2 ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
  2. –2014-05-05 15:52:52– http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
  3. 正在解析主机 nagios-plugins.org… 72.14.186.43
  4. 正在连接 nagios-plugins.org|72.14.186.43|:80… 已连接。
  5. 已发出 HTTP 请求,正在等待回应 … 200 OK
  6. ……………………………………..
  7. 2014-05-05 15:53:00 (373 KB/s) – 已保存“nagios-plugins-2.0.tar.gz”[2501847/2501847])
  8. [root@cache-2 ~]# tar -xvf nagios-plugins-2.0.tar.gz
  9. [root@cache-2 ~]# cd nagios-plugins-2.0
  10. [root@cache-2 ~]#./configure —with-nagios-user=nagios —with-nagios-group=nagios –prefix=/usr/local/nagios —with-mysql
  11. [root@cache-2 ~]# make && make install

5.8 安装配置 apache 和 php
(1)安装 apache
下载 wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz

  1. [root@cache-2 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  2. –2014-05-05 16:15:48– http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  3. 正在解析主机 archive.apache.org… 192.87.106.229, 140.211.11.131, 2001:610:1:80bc:192:87:106:229
  4. 正在连接 archive.apache.org|192.87.106.229|:80… 已连接。
  5. 已发出 HTTP 请求,正在等待回应 … 200 OK
  6. 长度:6747087 (6.4M) [application/x-gzip]
  7. 正在保存至:“httpd-2.4.7.tar.gz”
  8. 1% [=> ……………………………………………………..
  9. 2014-05-05 16:16:01 (574 KB/s) – 已保存“httpd-2.4.7.tar.gz”[6747087/6747087])

始安装:
tar -xvf httpd-2.4.7.tar.gz
cd httpd-2.4.7
./configure –prefix=/usr/local/apache2
make && make install

  1. [root@cache-2 ~]# tar -xvf httpd-2.4.7.tar.gz
  2. [root@cache-2 ~]# cd httpd-2.4.7
  3. [root@cache-2 httpd-2.4.7]# ./configure –prefix=/usr/local/apache2
  4. checking for chosen layout… Apache
  5. checking for working mkdir -p… yes
  6. checking for grep that handles long lines and -e… /bin/grep
  7. checking for egrep… /bin/grep -E
  8. checking build system type… x86_64-unknown-linux-gnu
  9. checking host system type… x86_64-unknown-linux-gnu
  10. checking target system type… x86_64-unknown-linux-gnu
  11. configure:
  12. configure: Configuring Apache Portable Runtime library…
  13. configure:
  14. checking for APR… no
  15. configure: error: APR not found. Please read the documentation.
  16. Google 之后,发现可能是 gcc 版本太低了,可能是 apache 版本太高,换低点的 2.2.23 版本吧。
  17. wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz
  18. tar -xvf httpd-2.2.23.tar.gz
  19. cd httpd-2.2.23
  20. ./configure –prefix=/usr/local/apache2
  21. make && make install

 (2) 安装 php 版本

wget http://cn2.php.net/distributions/php-5.4.26.tar.gz

tar -xvf php-5.4.26.tar.gz

cd php-5.4.26

./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs

有报错信息:

Configuring extensions

checking size of long… (cached) 8

checking size of int… (cached) 4

checking for int32_t… yes

checking for uint32_t… yes

checking for sys/types.h… (cached) yes

checking for inttypes.h… (cached) yes

checking for stdint.h… (cached) yes

checking for string.h… (cached) yes

checking for stdlib.h… (cached) yes

checking for strtoll… yes

checking for atoll… yes

checking for strftime… (cached) yes

checking which regex library to use… php

checking whether to enable LIBXML support… yes

checking libxml2 install dir… no

checking for xml2-config path…

configure: error: xml2-config not found. Please check your libxml2 installation.

 

需要重新安装 lib 包

yum install libxml2 –y

yum install libxml2-devel –y

 

之后继续 make,成功了:

Make && make install

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

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.11

[PEAR] Console_Getopt – installed: 1.3.1

warning: pear/PEAR requires package “pear/Structures_Graph” (recommended version 1.0.4)

warning: pear/PEAR requires package “pear/XML_Util” (recommended version 1.2.1)

[PEAR] PEAR – installed: 1.9.4

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

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util – installed: 1.2.1

/root/php/php-5.4.26/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/

 

(3) 配置 apache

Apache 的配置文件在 /usr/local/apache2/conf/httpd.conf,vim 打开

User daemon

Group daemon

修改成:

User nagios

Group nagios

 

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

修改成:

<IfModule dir_module>

DirectoryIndex index.html index.php

AddType application/x-httpd-php .php

</IfModule>

 

为了安全起见:nagios 的 web 监控页面需要经过授权才能访问,这需要增加验证配置,即在 httpd.conf 文件最后添加如下信息:

#setting for nagios

ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”

<Directory “/usr/local/nagios/sbin”>

AuthType Basic

Options ExecCGI

AllowOverride None

Order allow,deny

Allow from all

AuthName “Nagios Access”

AuthUserFile /usr/local/nagios/etc/htpasswd // 用于此目录访问身份验证的文件

Require valid-user

</Directory>

Alias /nagios “/usr/local/nagios/share”

<Directory “/usr/local/nagios/share”>

AuthType Basic

Options None

AllowOverride None

Order allow,deny

Allow from all

AuthName “nagios Access”

AuthUserFile /usr/local/nagios/etc/htpasswd

Require valid-user

</Directory>

 

(4) 创建 apache 目录验证文件

在上面的配置中,指定了目录验证文件 htpasswd,下面要创建这个文件:

/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david

[root@cache-2 php-5.4.26]# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david

New password:

Re-type new password:

Adding password for user david

查看认证文件的内容:

[root@cache-2 php-5.4.26]# cat /usr/local/nagios/etc/htpasswd

david:$apr1$Pf9XIJjd$m5hR2vw70MlqwrChgN7zc/

[root@cache-2 php-5.4.26]#

 

启动 apache 服务:

/usr/local/apache2/bin/apachectl start

 

[root@cache-2 php-5.4.26]# /usr/local/apache2/bin/apachectl start

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

(98)Address already in use: make_sock: could not bind to address [::]:80

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

修改 ServerName 以及 Port

vi /usr/local/apache2/conf/httpd.conf

ServerName 改成 10.xx.3.x1

Listen 80 改成 Listen 81

http://10.xx.3.x1:81/nagios/,可以打开了,如下所示:

Nagios 服务器端安装部署详解

 

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

6 配置 nagios

Nagios 主要用于监控一台或者多台本地主机及远程的各种信息,包括本机资源及对外的服务等。默认的 Nagios 配置没有任何监控内容,仅是一些模板文件。若要让 Nagios 提供服务,就必须修改配置文件,增加要监控的主机和服务,下面将详细介绍。

6.1 默认配置文件介绍

Nagios 安装完毕后,默认的配置文件在 /usr/local/nagios/etc 目录下。

[root@cache-2 etc]# cd /usr/local/nagios/etc

[root@cache-2 etc]# ls

cgi.cfg htpasswd nagios.cfg objects resource.cfg

[root@cache-2 etc]#

[root@cache-2 etc]# cd objects

[root@cache-2 objects]# ls

commands.cfg contacts.cfg localhost.cfg printer.cfg switch.cfg templates.cfg timeperiods.cfg windows.cfg

[root@cache-2 objects]#

 

每个文件或目录含义如下表所示:

文件名或目录名 用途

cgi.cfg 控制 CGI 访问的配置文件

nagios.cfg Nagios 主配置文件

resource.cfg 变量定义文件,又称为资源文件,在些文件中定义变量,以便由其他配置文件引用,如 $USER1$

objects objects 是一个目录,在此目录下有很多配置文件模板,用于定义 Nagios 对象

objects/commands.cfg 命令定义配置文件,其中定义的命令可以被其他配置文件引用

objects/contacts.cfg 定义联系人和联系人组的配置文件

objects/localhost.cfg 定义监控本地主机的配置文件

objects/printer.cfg 定义监控打印机的一个配置文件模板,默认没有启用此文件

objects/switch.cfg 定义监控路由器的一个配置文件模板,默认没有启用此文件

objects/templates.cfg 定义主机和服务的一个模板配置文件,可以在其他配置文件中引用

objects/timeperiods.cfg 定义 Nagios 监控时间段的配置文件

objects/windows.cfg 监控 Windows 主机的一个配置文件模板,默认没有启用此文件

 

 

6.2 配置文件之间的关系

 

在 nagios 的配置过程中涉及到的几个定义有:主机、主机组,服务、服务组,联系人、联系人组,监控时间,监控命令等,从这些定义可以看出,nagios 各个配置文件之间是互为关联,彼此引用的。

 

成功配置出一台 nagios 监控系统,必须要弄清楚每个配置文件之间依赖与被依赖的关系,最重要的有四点:

 

第一:定义监控哪些主机、主机组、服务和服务组;

第二:定义这个监控要用什么命令实现;

第三:定义监控的时间段;

第四:定义主机或服务出现问题时要通知的联系人和联系人组。

 

6.3 配置Nagios

为了能更清楚的说明问题,同时也为了维护方便,建议将 nagios 各个定义对象创建独立的配置文件:

· 创建 hosts.cfg 文件来定义主机和主机组

· 创建 services.cfg 文件来定义服务

· 用默认的 contacts.cfg 文件来定义联系人和联系人组

· 用默认的 commands.cfg 文件来定义命令

· 用默认的 timeperiods.cfg 来定义监控时间段

· 用默认的 templates.cfg 文件作为资源引用文件

 

 

a. timeperiods.cfg文件

  1. define contact{
  2. name generic-contact ; 联系人名称
  3. service_notification_period 24×7 ; 当服务出现异常时,发送通知的时间段,这个时间段 “24×7” 在 timeperiods.cfg 文件中定义
  4. host_notification_period 24×7 ; 当主机出现异常时,发送通知的时间段,这个时间段 “24×7” 在 timeperiods.cfg 文件中定义
  5. service_notification_options w,u,c,r ; 这个定义的是“通知可以被发出的情况”。w 即 warn,表示警告状态,u 即 unknown,表示不明状态;
  6. ; c 即 criticle,表示紧急状态,r 即 recover,表示恢复状态;
  7. ; 也就是在服务出现警告状态、未知状态、紧急状态和重新恢复状态时都发送通知给使用者。
  8. host_notification_options d,u,r ; 定义主机在什么状态下需要发送通知给使用者,d 即 down,表示宕机状态;
  9. ; u 即 unreachable,表示不可到达状态,r 即 recovery,表示重新恢复状态。
  10. service_notification_commands notify-service-by-email ; 服务故障时,发送通知的方式,可以是邮件和短信,这里发送的方式是邮件;
  11. ; 其中“notify-service-by-email”在 commands.cfg 文件中定义。
  12. host_notification_commands notify-host-by-email ; 主机故障时,发送通知的方式,可以是邮件和短信,这里发送的方式是邮件;
  13. ; 其中“notify-host-by-email”在 commands.cfg 文件中定义。
  14. register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL CONTACT, JUST A TEMPLATE!
  15. }
  16. define host{
  17. name generic-host ; 主机名称,这里的主机名,并不是直接对应到真正机器的主机名;
  18. ; 乃是对应到在主机配置文件里所设定的主机名。
  19. notifications_enabled 1 ; Host notifications are enabled
  20. event_handler_enabled 1 ; Host event handler is enabled
  21. flap_detection_enabled 1 ; Flap detection is enabled
  22. failure_prediction_enabled 1 ; Failure prediction is enabled
  23. process_perf_data 1 ; 其值可以为 0 或 1,其作用为是否启用 Nagios 的数据输出功能;
  24. ; 如果将此项赋值为 1,那么 Nagios 就会将收集的数据写入某个文件中,以备提取。
  25. retain_status_information 1 ; Retain status information across program restarts
  26. retain_nonstatus_information 1 ; Retain non-status information across program restarts
  27. notification_period 24×7 ; 指定“发送通知”的时间段,也就是可以在什么时候发送通知给使用者。
  28. register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL HOST, JUST A TEMPLATE!
  29. }
  30. define service{
  31. name generic-service ; 定义一个服务名称
  32. active_checks_enabled 1 ; Active service checks are enabled
  33. passive_checks_enabled 1 ; Passive service checks are enabled/accepted
  34. parallelize_check 1 ; Active service checks should be parallelized;
  35. ; (disabling this can lead to major performance problems)
  36. obsess_over_service 1 ; We should obsess over this service (if necessary)
  37. check_freshness 0 ; Default is to NOT check service ‘freshness’
  38. notifications_enabled 1 ; Service notifications are enabled
  39. event_handler_enabled 1 ; Service event handler is enabled
  40. flap_detection_enabled 1 ; Flap detection is enabled
  41. failure_prediction_enabled 1 ; Failure prediction is enabled
  42. process_perf_data 1 ; Process performance data
  43. retain_status_information 1 ; Retain status information across program restarts
  44. retain_nonstatus_information 1 ; Retain non-status information across program restarts
  45. is_volatile 0 ; The service is not volatile
  46. check_period 24×7 ; 这里的 check_period 告诉 nagios 检查服务的时间段。
  47. max_check_attempts 3 ; nagios 对服务的最大检查次数。
  48. normal_check_interval 5 ; 此选项是用来设置服务检查时间间隔,也就是说,nagios 这一次检查和下一次检查之间所隔的时间;
  49. ; 这里是 5 分钟。
  50. retry_check_interval 2 ; 重试检查时间间隔,单位是分钟。
  51. contact_groups ts ; 指定联系人组
  52. notification_options w,u,c,r ; 这个定义的是“通知可以被发出的情况”。w 即 warn,表示警告状态;
  53. ; u 即 unknown,表示不明状态;
  54. ; c 即 criticle,表示紧急状态,r 即 recover,表示恢复状态;
  55. ; 也就是在服务出现警告状态、未知状态、紧急状态和重新恢复后都发送通知给使用者。
  56. notification_interval 10 ; Re-notify about service problems every hour
  57. notification_period 24×7 ; 指定“发送通知”的时间段,也就是可以在什么时候发送通知给使用者。
  58. register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL SERVICE, JUST A TEMPLATE!
  59. }
  60. define service{
  61. name local-service ; The name of this service template
  62. use generic-service ; Inherit default values from the generic-service definition
  63. max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state
  64. normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
  65. retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined
  66. register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL SERVICE, JUST A TEMPLATE!
  67. }
b. resource.cfg文件

resource.cfgnagios 的变量定义文件,文件内容只有一行:

$USER1$=/usr/local/nagios/libexec

其中,变量 $USER1$ 指定了安装 nagios 插件的路径,如果把插件安装在了其它路径,只需在这里进行修改即可。需要注意的是,变量必须先定义,然后才能在其它配置文件中进行引用。

 

c. commands.cfg文件

此文件默认是存在的,无需修改即可使用,当然如果有新的命令需要加入时,在此文件进行添加即可。

  1. #notify-host-by-email 命令的定义
  2. define command{
  3. command_name notify-host-by-email #命令名称,即定义了一个主机异常时发送邮件的命令。
  4. 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$ #命令具体的执行方式。
  5. }
  6. #notify-service-by-email 命令的定义
  7. define command{
  8. command_name notify-service-by-email #命令名称,即定义了一个服务异常时发送邮件的命令
  9. 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$
  10. }
  11. define command{
  12. command_name check_local_disk
  13. command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ #$ARG1$ 是指在调用这个命令的时候,命令后面的第一个参数。
  14. }
  15. define command{
  16. command_name check_local_load
  17. command_line $USER1$/check_load -w $ARG1$ -c $ARG2$
  18. }
  19. define command{
  20. command_name check_local_procs
  21. command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
  22. }
  23. define command{
  24. command_name check_local_users
  25. command_line $USER1$/check_users -w $ARG1$ -c $ARG2$
  26. }

 

 

d. hosts.cfg文件

此文件默认不存在,需要手动创建,hosts.cfg主要用来指定被监控的主机地址以及相关属性信息,根据实验目标配置如下:

  1. define host{
  2. use linux-server #引用主机 linux-server 的属性信息,linux-server 主机在 templates.cfg 文件中进行了定义。
  3. host_name Nagios-Linux #主机名
  4. alias Nagios-Linux #主机别名
  5. address 192.168.1.111 #被监控的主机地址,这个地址可以是 ip,也可以是域名。
  6. }
  7. # 定义一个主机组
  8. define hostgroup{
  9. hostgroup_name bsmart-servers #主机组名称,可以随意指定。
  10. alias bsmart servers #主机组别名
  11. members Nagios-Linux #主机组成员,其中“Nagios-Linux”就是上面定义的主机。
  12. }

注意:在 /usr/local/nagios/etc/objects 下默认有 localhost.cfg 和 windows.cfg 这两个配置文件,localhost.cfg 文件是定义监控主机本身的,windows.cfg 文件是定义 windows 主机的,其中包括了对 host 和相关 services 的定义。所以在本次实验中,将直接在 localhost.cfg 中定义监控主机(Nagios-Server),在 windows.cfg 中定义 windows 主机(Nagios-Windows)。根据自己的需要修改其中的相关配置,详细如下:

localhost.cfg

  1. define host{
  2. use linux-server ; Name of host template to use
  3. ; This host definition will inherit all variables that are defined
  4. ; in (or inherited by) the linux-server host template definition.
  5. host_name Nagios-Server
  6. alias Nagios-Server
  7. address 127.0.0.1
  8. }
  9. define hostgroup{
  10. hostgroup_name linux-servers ; The name of the hostgroup
  11. alias Linux Servers ; Long name of the group
  12. members Nagios-Server ; Comma separated list of hosts that belong to this group
  13. }
  14. define service{
  15. use local-service ; Name of service template to use
  16. host_name Nagios-Server
  17. service_description PING
  18. check_command check_ping!100.0,20%!500.0,60%
  19. }
  20. define service{
  21. use local-service ; Name of service template to use
  22. host_name Nagios-Server
  23. service_description Root Partition
  24. check_command check_local_disk!20%!10%!/
  25. }
  26. define service{
  27. use local-service ; Name of service template to use
  28. host_name Nagios-Server
  29. service_description Current Users
  30. check_command check_local_users!20!50
  31. }
  32. define service{
  33. use local-service ; Name of service template to use
  34. host_name Nagios-Server
  35. service_description Total Processes
  36. check_command check_local_procs!250!400!RSZDT
  37. }
  38. define service{
  39. use local-service ; Name of service template to use
  40. host_name Nagios-Server
  41. service_description Current Load
  42. check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
  43. }
  44. define service{
  45. use local-service ; Name of service template to use
  46. host_name Nagios-Server
  47. service_description Swap Usage
  48. check_command check_local_swap!20!10
  49. }
  50. define service{
  51. use local-service ; Name of service template to use
  52. host_name Nagios-Server
  53. service_description SSH
  54. check_command check_ssh
  55. notifications_enabled 0
  56. }
  57. define service{
  58. use local-service ; Name of service template to use
  59. host_name Nagios-Server
  60. service_description HTTP
  61. check_command check_http
  62. notifications_enabled 0
  63. }

 

e. services.cfg文件

此文件默认也不存在,需要手动创建,services.cfg文件主要用于定义监控的服务和主机资源,例如监控 http 服务、ftp服务、主机磁盘空间、主机系统负载等等。Nagios-Server Nagios-Windows 相关服务已在相应的配置文件中定义,所以这里只需要定义 Nagios-Linux 相关服务即可,这里只定义一个检测是否存活的服务来验证配置文件的正确性,其他服务的定义将在后面讲到。

  1. define service{
  2. use local-service #引用 local-service 服务的属性值,local-service 在 templates.cfg 文件中进行了定义。
  3. host_name Nagios-Linux #指定要监控哪个主机上的服务,“Nagios-Server”在 hosts.cfg 文件中进行了定义。
  4. service_description check-host-alive #对监控服务内容的描述,以供维护人员参考。
  5. check_command check-host-alive #指定检查的命令。
  6. }

 

f. contacts.cfg文件

contacts.cfg是一个定义联系人和联系人组的配置文件,当监控的主机或者服务出现故障,nagios会通过指定的通知方式(邮件或者短信)将信息发给这里指定的联系人或者使用者。

  1. define contact{
  2. contact_name David #联系人的名称, 这个地方不要有空格
  3. use generic-contact #引用 generic-contact 的属性信息,其中“generic-contact”在 templates.cfg 文件中进行定义
  4. alias Nagios Admin
  5. email david.tang@bsmart.cn
  6. }
  7. define contactgroup{
  8. contactgroup_name ts #联系人组的名称, 同样不能空格
  9. alias Technical Support #联系人组描述
  10. members David #联系人组成员,其中“david”就是上面定义的联系人,如果有多个联系人则以逗号相隔
  11. }

 

g. timeperiods.cfg文件

此文件只要用于定义监控的时间段,下面是一个配置好的实例:

  1. # 下面是定义一个名为 24×7 的时间段,即监控所有时间段
  2. define timeperiod{
  3. timeperiod_name 24×7 #时间段的名称, 这个地方不要有空格
  4. alias 24 Hours A Day, 7 Days A Week
  5. sunday 00:00-24:00
  6. monday 00:00-24:00
  7. tuesday 00:00-24:00
  8. wednesday 00:00-24:00
  9. thursday 00:00-24:00
  10. friday 00:00-24:00
  11. saturday 00:00-24:00
  12. }
  13. # 下面是定义一个名为 workhours 的时间段,即工作时间段。
  14. define timeperiod{
  15. timeperiod_name workhours
  16. alias Normal Work Hours
  17. monday 09:00-17:00
  18. tuesday 09:00-17:00
  19. wednesday 09:00-17:00
  20. thursday 09:00-17:00
  21. friday 09:00-17:00
  22. }

 

h. cgi.cfg文件

此文件用来控制相关 cgi 脚本,如果想在 nagiosweb监控界面执行 cgi 脚本,例如重启 nagios 进程、关闭 nagios 通知、停止 nagios 主机检测等,这时就需要配置 cgi.cfg 文件了。
由于 nagiosweb监控界面验证用户为 david,所以只需在cgi.cfg 文件中添加此用户的执行权限就可以了,需要修改的配置信息如下:

  1. default_user_name=david
  2. authorized_for_system_information=nagiosadmin,david
  3. authorized_for_configuration_information=nagiosadmin,david
  4. authorized_for_system_commands=david
  5. authorized_for_all_services=nagiosadmin,david
  6. authorized_for_all_hosts=nagiosadmin,david
  7. authorized_for_all_service_commands=nagiosadmin,david
  8. authorized_for_all_host_commands=nagiosadmin,david

 

i. nagios.cfg文件

nagios.cfg默认的路径为 /usr/local/nagios/etc/nagios.cfg,是nagios 的核心配置文件,所有的对象配置文件都必须在这个文件中进行定义才能发挥其作用,这里只需将对象配置文件在 Nagios.cfg 文件中进行引用即可。

  1. log_file=/usr/local/nagios/var/nagios.log # 定义 nagios 日志文件的路径
  2. cfg_file=/usr/local/nagios/etc/objects/commands.cfg #“cfg_file”变量用来引用对象配置文件,如果有更多的对象配置文件,在这里依次添加即可。
  3. cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
  4. cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
  5. cfg_file=/usr/local/nagios/etc/objects/services.cfg
  6. cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
  7. cfg_file=/usr/local/nagios/etc/objects/templates.cfg
  8. cfg_file=/usr/local/nagios/etc/objects/localhost.cfg # 本机配置文件
  9. cfg_file=/usr/local/nagios/etc/objects/windows.cfg # windows 主机配置文件
  10. object_cache_file=/usr/local/nagios/var/objects.cache # 该变量用于指定一个“所有对象配置文件”的副本文件,或者叫对象缓冲文件
  11. precached_object_file=/usr/local/nagios/var/objects.precache
  12. resource_file=/usr/local/nagios/etc/resource.cfg # 该变量用于指定 nagios 资源文件的路径,可以在 nagios.cfg 中定义多个资源文件。
  13. status_file=/usr/local/nagios/var/status.dat # 该变量用于定义一个状态文件,此文件用于保存 nagios 的当前状态、注释和宕机信息等。
  14. status_update_interval=10 # 该变量用于定义状态文件(即 status.dat)的更新时间间隔,单位是秒,最小更新间隔是 1 秒。
  15. nagios_user=nagios # 该变量指定了 Nagios 进程使用哪个用户运行。
  16. nagios_group=nagios # 该变量用于指定 Nagios 使用哪个用户组运行。
  17. check_external_commands=1 # 该变量用于设置是否允许 nagios 在 web 监控界面运行 cgi 命令;
  18. # 也就是是否允许 nagios 在 web 界面下执行重启 nagios、停止主机 / 服务检查等操作;
  19. #“1”为运行,“0”为不允许。
  20. command_check_interval=10s # 该变量用于设置 nagios 对外部命令检测的时间间隔,如果指定了一个数字加一个“s”(如 10s);
  21. # 那么外部检测命令的间隔是这个数值以秒为单位的时间间隔;
  22. # 如果没有用 ”s”,那么外部检测命令的间隔是以这个数值的“时间单位”的时间间隔。
  23. interval_length=60 # 该变量指定了 nagios 的时间单位,默认值是 60 秒,也就是 1 分钟;
  24. # 即在 nagios 配置中所有的时间单位都是分钟。

6.4 验证 Nagios 配置文件的正确性

Nagios 在验证配置文件方面做的非常到位,只需通过一个命令即可完成:

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  1. [root@cache-2 etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  2. Nagios Core 4.0.6
  3. Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
  4. Copyright (c) 1999-2009 Ethan Galstad
  5. Last Modified: 04-29-2014
  6. License: GPL
  7. Website: http://www.nagios.org
  8. Reading configuration data…
  9. Read main config file okay…
  10. Read object config files okay…
  11. Running pre-flight check on configuration data…
  12. Checking objects…
  13. Checked 29 services.
  14. Checked 4 hosts.
  15. Checked 2 host groups.
  16. Checked 0 service groups.
  17. Checked 4 contacts.
  18. Checked 2 contact groups.
  19. Checked 26 commands.
  20. Checked 5 time periods.
  21. Checked 0 host escalations.
  22. Checked 0 service escalations.
  23. Checking for circular paths…
  24. Checked 4 hosts
  25. Checked 0 service dependencies
  26. Checked 0 host dependencies
  27. Checked 5 timeperiods
  28. Checking global event handlers…
  29. Checking obsessive compulsive processor commands…
  30. Checking misc settings…
  31. Total Warnings: 0
  32. Total Errors: 0
  33. Things look okay – No serious problems were detected during the pre-flight check
  34. [root@cache-2 etc]#

Nagios提供的这个验证功能非常有用,在错误信息中通常会打印出错误的配置文件以及文件中的哪一行,这使得 nagios 的配置变得非常容易,报警信息通常是可以忽略的,因为一般那些只是建议性的。

看到上面这些信息就说明没问题了,然后启动 Nagios 服务。

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

下载地址如下:http://sourceforge.net/projects/nagios/files/

具体详细下载地址:http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.6.tar.gz

相关阅读

网络监控器 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

1 开始下载:
wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.0.6/nagios-4.0.6.tar.gz/download?use_mirror=jaist
如下图所示,下载 free 版本的。
Nagios 服务器端安装部署详解

安装 前准备工作,安装一些 lib 包

[root@cache-2 root]# yum -y install httpd gcc glibc glibc-common

# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel 

2 进行 selinux 设置,或者关闭 selinux

查看 SELinux 状态:

(1)/usr/sbin/sestatus -v ## 如果 SELinux status 参数为 enabled 即为开启状态

SELinux status: enabled

(2)getenforce ## 也可以用这个命令检查

关闭 SELinux:

(3)临时关闭(不用重启机器):

setenforce 0 ## 设置 SELinux 成为 permissive 模式

##setenforce 1 设置 SELinux 成为 enforcing 模式

(4)修改配置文件需要重启机器:

修改 /etc/selinux/config 文件

将 SELINUX=enforcing 改为 SELINUX=disabled

重启机器即可 

3 开始准备 nagios 安装环境

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

groupadd nagcmd

useradd -m nagios

usermod -a -G nagcmd nagios 

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

# usermod -a -G nagcmd apache 

4 编译安装准备

./configure withcommandgroup=nagios prefix=/opt/app/nagios enableembeddedperl withhttpdconf=/usr/local/apache2/conf

  1. [root@cache-2 nagios-4.0.6]# ./configure —with-command-group=nagios –prefix=/opt/app/nagios –enable-embedded-perl —with-httpd-conf=/usr/local/apache2/conf
  2. checking for a BSD-compatible install… /usr/bin/install -c
  3. checking build system type… x86_64-unknown-linux-gnu
  4. checking host system type… x86_64-unknown-linux-gnu
  5. checking for gcc… gcc
  6. checking for C compiler default output file name… a.out
  7. checking whether the C compiler works… yes
  8. checking whether we are cross compiling… no
  9. ………………………..
  10. HTML URL: http://localhost/nagios/
  11. CGI URL: http://localhost/nagios/cgi-bin/
  12. Traceroute (used by WAP): /bin/traceroute
  13. Review the options above for accuracy. If they look okay,
  14. type ‘make all’ to compile the main program and CGIs.

5 开始 make 安装
5.1 make all

[root@cache-2 nagios-4.0.6]# make all

  1. cd ./base && make
  2. make[1]: Entering directory `/root/nagios-4.0.6/base’
  3. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.c
  4. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o broker.o broker.c
  5. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nebmods.o nebmods
  6. …………………….
  7. For more information on obtaining support for Nagios, visit:
  8. http://support.nagios.com
  9. *************************************************************
  10. Enjoy.

 

5.2 make install
[root@cache-2 nagios-4.0.6]# make install

  1. cd ./base && make install
  2. make[1]: Entering directory `/root/nagios-4.0.6/base’
  3. make install-basic
  4. make[2]: Entering directory `/root/nagios-4.0.6/base’
  5. ……………………………………………..
  6. make[2]: Entering directory `/root/nagios-4.0.6/cgi’
  7. for file in *.cgi; do \
  8. /usr/bin/strip /usr/local/nagios/sbin/$file; \
  9. done

5.3 make install-config

  1. [root@cache-2 nagios-4.0.6]# make install-config
  2. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
  3. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
  4. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
  5. …………………………………………….
  6. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
  7. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
  8. *** Config files installed ***

5.4 make install-commandmode

  1. [root@cache-2 nagios-4.0.6]# make install-commandmode
  2. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
  3. chmod g+s /usr/local/nagios/var/rw
  4. *** External command directory configured ***
  5. Remember, these are *SAMPLE* config files. You’ll need to read
  6. the documentation for more information on how to actually define
  7. services, hosts, etc. to fit your particular needs.

5.5 make install-init

  1. [root@cache-2 nagios-4.0.6]# make install-init
  2. /usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
  3. /usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
  4. *** Init script installed ***

[root@cache-2 nagios-4.0.6]#

加到启动项里面去:

# chkconfig –add nagios

# chkconfig –level 35 nagios on

# chkconfig –list nagios

Nagios 服务器端安装部署详解

检查主机配置文件是否正确:

/var/www/nagios/bin/nagios -v /var/www/nagios/etc/nagios.cfg

5.6 Check 安装是否正确:

5.6.1 说明:

切换目录到安装路径(这里是 /usr/local/nagios),看是否存在 etc、bin、sbin、share、var 这五个目录,如果存在则可以表明程序被正确的安装到系统了。Nagios 各个目录用途说明如下:

bin Nagios 可执行程序所在目录

etc Nagios 配置文件所在目录

sbin Nagios CGI 文件所在目录,也就是执行外部命令所需文件所在的目录

share Nagios 网页文件所在的目录

libexec Nagios 外部插件所在目录

var Nagios 日志文件、lock 等文件所在的目录

var/archives Nagios 日志自动归档目录

var/rw 用来存放外部命令文件的目录

5.6.2 check
cd /usr/local/nagios
ll

  1. [root@cache-2 nagios-4.0.6]# cd /usr/local/nagios
  2. [root@cache-2 nagios]# ll
  3. 总用量 24
  4. drwxrwxr-x. 2 nagios nagios 4096 5 月 5 15:31 bin
  5. drwxrwxr-x. 3 nagios nagios 4096 5 月 5 15:32 etc
  6. drwxrwxr-x. 2 nagios nagios 4096 5 月 5 15:31 libexec
  7. drwxrwxr-x. 2 nagios nagios 4096 5 月 5 15:31 sbin
  8. drwxrwxr-x. 10 nagios nagios 4096 5 月 5 15:31 share
  9. drwxrwxr-x. 5 nagios nagios 4096 5 月 5 15:32 var

5.7 安装 nagios 插件
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

  1. [root@cache-2 ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
  2. –2014-05-05 15:52:52– http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
  3. 正在解析主机 nagios-plugins.org… 72.14.186.43
  4. 正在连接 nagios-plugins.org|72.14.186.43|:80… 已连接。
  5. 已发出 HTTP 请求,正在等待回应 … 200 OK
  6. ……………………………………..
  7. 2014-05-05 15:53:00 (373 KB/s) – 已保存“nagios-plugins-2.0.tar.gz”[2501847/2501847])
  8. [root@cache-2 ~]# tar -xvf nagios-plugins-2.0.tar.gz
  9. [root@cache-2 ~]# cd nagios-plugins-2.0
  10. [root@cache-2 ~]#./configure —with-nagios-user=nagios —with-nagios-group=nagios –prefix=/usr/local/nagios —with-mysql
  11. [root@cache-2 ~]# make && make install

5.8 安装配置 apache 和 php
(1)安装 apache
下载 wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz

  1. [root@cache-2 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  2. –2014-05-05 16:15:48– http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  3. 正在解析主机 archive.apache.org… 192.87.106.229, 140.211.11.131, 2001:610:1:80bc:192:87:106:229
  4. 正在连接 archive.apache.org|192.87.106.229|:80… 已连接。
  5. 已发出 HTTP 请求,正在等待回应 … 200 OK
  6. 长度:6747087 (6.4M) [application/x-gzip]
  7. 正在保存至:“httpd-2.4.7.tar.gz”
  8. 1% [=> ……………………………………………………..
  9. 2014-05-05 16:16:01 (574 KB/s) – 已保存“httpd-2.4.7.tar.gz”[6747087/6747087])

始安装:
tar -xvf httpd-2.4.7.tar.gz
cd httpd-2.4.7
./configure –prefix=/usr/local/apache2
make && make install

  1. [root@cache-2 ~]# tar -xvf httpd-2.4.7.tar.gz
  2. [root@cache-2 ~]# cd httpd-2.4.7
  3. [root@cache-2 httpd-2.4.7]# ./configure –prefix=/usr/local/apache2
  4. checking for chosen layout… Apache
  5. checking for working mkdir -p… yes
  6. checking for grep that handles long lines and -e… /bin/grep
  7. checking for egrep… /bin/grep -E
  8. checking build system type… x86_64-unknown-linux-gnu
  9. checking host system type… x86_64-unknown-linux-gnu
  10. checking target system type… x86_64-unknown-linux-gnu
  11. configure:
  12. configure: Configuring Apache Portable Runtime library…
  13. configure:
  14. checking for APR… no
  15. configure: error: APR not found. Please read the documentation.
  16. Google 之后,发现可能是 gcc 版本太低了,可能是 apache 版本太高,换低点的 2.2.23 版本吧。
  17. wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz
  18. tar -xvf httpd-2.2.23.tar.gz
  19. cd httpd-2.2.23
  20. ./configure –prefix=/usr/local/apache2
  21. make && make install

 (2) 安装 php 版本

wget http://cn2.php.net/distributions/php-5.4.26.tar.gz

tar -xvf php-5.4.26.tar.gz

cd php-5.4.26

./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs

有报错信息:

Configuring extensions

checking size of long… (cached) 8

checking size of int… (cached) 4

checking for int32_t… yes

checking for uint32_t… yes

checking for sys/types.h… (cached) yes

checking for inttypes.h… (cached) yes

checking for stdint.h… (cached) yes

checking for string.h… (cached) yes

checking for stdlib.h… (cached) yes

checking for strtoll… yes

checking for atoll… yes

checking for strftime… (cached) yes

checking which regex library to use… php

checking whether to enable LIBXML support… yes

checking libxml2 install dir… no

checking for xml2-config path…

configure: error: xml2-config not found. Please check your libxml2 installation.

 

需要重新安装 lib 包

yum install libxml2 –y

yum install libxml2-devel –y

 

之后继续 make,成功了:

Make && make install

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

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.11

[PEAR] Console_Getopt – installed: 1.3.1

warning: pear/PEAR requires package “pear/Structures_Graph” (recommended version 1.0.4)

warning: pear/PEAR requires package “pear/XML_Util” (recommended version 1.2.1)

[PEAR] PEAR – installed: 1.9.4

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

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util – installed: 1.2.1

/root/php/php-5.4.26/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/

 

(3) 配置 apache

Apache 的配置文件在 /usr/local/apache2/conf/httpd.conf,vim 打开

User daemon

Group daemon

修改成:

User nagios

Group nagios

 

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

修改成:

<IfModule dir_module>

DirectoryIndex index.html index.php

AddType application/x-httpd-php .php

</IfModule>

 

为了安全起见:nagios 的 web 监控页面需要经过授权才能访问,这需要增加验证配置,即在 httpd.conf 文件最后添加如下信息:

#setting for nagios

ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”

<Directory “/usr/local/nagios/sbin”>

AuthType Basic

Options ExecCGI

AllowOverride None

Order allow,deny

Allow from all

AuthName “Nagios Access”

AuthUserFile /usr/local/nagios/etc/htpasswd // 用于此目录访问身份验证的文件

Require valid-user

</Directory>

Alias /nagios “/usr/local/nagios/share”

<Directory “/usr/local/nagios/share”>

AuthType Basic

Options None

AllowOverride None

Order allow,deny

Allow from all

AuthName “nagios Access”

AuthUserFile /usr/local/nagios/etc/htpasswd

Require valid-user

</Directory>

 

(4) 创建 apache 目录验证文件

在上面的配置中,指定了目录验证文件 htpasswd,下面要创建这个文件:

/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david

[root@cache-2 php-5.4.26]# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david

New password:

Re-type new password:

Adding password for user david

查看认证文件的内容:

[root@cache-2 php-5.4.26]# cat /usr/local/nagios/etc/htpasswd

david:$apr1$Pf9XIJjd$m5hR2vw70MlqwrChgN7zc/

[root@cache-2 php-5.4.26]#

 

启动 apache 服务:

/usr/local/apache2/bin/apachectl start

 

[root@cache-2 php-5.4.26]# /usr/local/apache2/bin/apachectl start

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

(98)Address already in use: make_sock: could not bind to address [::]:80

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

修改 ServerName 以及 Port

vi /usr/local/apache2/conf/httpd.conf

ServerName 改成 10.xx.3.x1

Listen 80 改成 Listen 81

http://10.xx.3.x1:81/nagios/,可以打开了,如下所示:

Nagios 服务器端安装部署详解

 

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

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