centos6.5部署nagios

一、nagios服务端
1、依赖包安装
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel perl perl-Module-Pluggable perl-Pod-Escapes perl-libs perl-version httpd php php-xml php-bcmath php-gd php-common ph p-deve
2、创建nagios用户和用户组
# useradd -s /sbin/nologin nagios
# mkdir /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios

3、
编译安装Nagios
可以到网站上下载新的,我用最新的版本configure时会提示unzip错误,后面换了版本好了。

# tar zxvf nagios-3.4.3.tar.gz

# cd nagios

# ./configure --prefix=/usr/local/nagios

make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf    # 这一步就自动添加了httpd关于nagios的配置(位置:/etc/httpd/conf.d/nagios.conf)

# chkconfig --add nagios

# chkconfig --level 35 nagios on

# chkconfig --list nagios


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、安装Nagios 插件

# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

# tar zxvf nagios-plugins-1.4.16.tar.gz

# cd nagios-plugins-1.4.16

# ./configure --prefix=/usr/local/nagios

# make && make install

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

# wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz

# tar zxvf httpd-2.2.23.tar.gz

# cd httpd-2.2.23

# ./configure --prefix=/usr/local/apache2  --with-included-apr  
问题1:如果提示缺少libxml2,就yum -y install libxml2 libxml2-devel重新configure
问题2:

今天换成Apache2.4.x版本,安装方法一样,在执行./configure命令时,却报如下错误:

configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

它的意思是说:需要下载apr和apr-utils并解压到 ./srclib/ 目录下, 再进行编译。

 
#重新执行 .configure 命令:
# make && make install

b. 安装Php

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

# tar zxvf php-5.4.10.tar.gz

# cd php-5.4.10

# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
# make && make install

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

User daemon 
Group daemon 

修改为 

User nagios 
Group nagios 

然后找到 

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

修改为 

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

接着增加如下内容: 

AddType application/x-httpd-php .php 

为了安全起见,一般情况下要让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> 
复制代码

d. 创建apache目录验证文件 

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

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

25 
这样就在/usr/local/nagios/etc 目录下创建了一个htpasswd 验证文件,当通过http://192.168.1.108/nagios/ 访问时就需要输入用户名和密码了。

e. 查看认证文件的内容

# cat /usr/local/nagios/etc/htpasswd

26

f. 启动apache 服务

# /usr/local/apache2/bin/apachectl start

到这里nagios 的安装也就基本完成了,你可以通过web来访问了。


问题1:如果登陆nagios,点击左边任意选项,右边都是乱码,那么要把httpd.conf里头的两行去掉,如下!
LoadModule cgid_module modules/mod_cgid.so
LoadModule actions_module modules/mod_actions.so
问题2:如果出现 The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
            那么是 apache用户权限跟nagios用户权限不对。
            chown nagios.nagios /usr/local/apache2 -R

监控页面出现
It appears as though you do not have permission to view information for any of the hosts you requested...


If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
and check the authorization options in your CGI configuration file.

修改/etc/cgi.cfg
vi    /usr/local/nagios/etc/cgi.cfg

use_authentication=1 #把1修改为0,保存
[email=root@nagios#/service]root@nagios#/service[/email] nagios restart
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值