5.3 编译安装Nagios

  1. # wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.3.tar.gz  
  2. # tar zxvf nagios-3.4.3.tar.gz  
  3. # cd nagios  
  4. # ./configure --prefix=/usr/local/nagios 

9

10

# make all

11

12

# make install

13

# make install-init

14

# make install-commandmode

15

# make install-config

16

  1. # chkconfig --add nagios  
  2. # chkconfig --level 35 nagios on  
  3. # chkconfig --list nagios 

17

5.4 验证程序是否被正确安装

切换目录到安装路径这里是/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.5 安装Nagios 插件

  1. # wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz  
  2. # tar zxvf nagios-plugins-1.4.16.tar.gz  
  3. # cd nagios-plugins-1.4.16  
  4. # ./configure --prefix=/usr/local/nagios  
  5. # make && make install 

18

19

5.6 安装与配置Apache和Php

Apache 和Php 不是安装nagios 所必须的,但是nagios提供了web监控界面,通过web监控界面可以清晰的看到被监控主机、资源的运行状态,因此,安装一个web服务是很必要的。

需要注意的是,nagios在nagios3.1.x版本以后,配置web监控界面时需要php的支持。这里我们下载的nagios版本为nagios-3.4.3,因此在编译安装完成apache后,还需要编译php模块,这里选取的php版本为php5.4.10。

a. 安装Apache

  1. # wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz  
  2. # tar zxvf httpd-2.2.23.tar.gz  
  3. # cd httpd-2.2.23  
  4. # ./configure --prefix=/usr/local/apache2  
  5. # make && make install 

22

若出现错误:

则在编译时入加 --with-included-apr 即可解决。

b. 安装Php

  1. # wget http://cn2.php.net/distributions/php-5.4.10.tar.gz  
  2. # tar zxvf php-5.4.10.tar.gz  
  3. # cd php-5.4.10  
  4. # ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs 

23

# make && make install

24

c. 配置apache

找到apache 的配置文件/usr/local/apache2/conf/httpd.conf

找到:

  1. User daemon   
  2. Group daemon 

修改为

  1. User nagios   
  2. Group nagios  

然后找到

  1. <IfModule dir_module> DirectoryIndex index.html </IfModule>  

修改为

  1. <IfModule dir_module> DirectoryIndex index.html index.php </IfModule>  

接着增加如下内容:

  1. AddType application/x-httpd-php .php  

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

  1. #setting for nagios   
  2. ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" <Directory "/usr/local/nagios/sbin"> AuthType Basic   
  3.      Options ExecCGI   
  4.      AllowOverride None   
  5.      Order allow,deny   
  6.      Allow from all   
  7.      AuthName "Nagios Access"   
  8.      AuthUserFile /usr/local/nagios/etc/htpasswd             //用于此目录访问身份验证的文件   
  9.      Require valid-user </Directory> Alias /nagios "/usr/local/nagios/share" <Directory "/usr/local/nagios/share"> AuthType Basic   
  10.      Options None   
  11.      AllowOverride None   
  12.      Order allow,deny   
  13.      Allow from all   
  14.      AuthName "nagios Access"   
  15.      AuthUserFile /usr/local/nagios/etc/htpasswd   
  16.      Require valid-user </Directory>  


相关内容