CentOS-6.0-x86_64 平台上编译安装 Nagios

这里的 CentOS 6.0 x86_64 最小化安装,所以需要安装一些开发编译的套件:

# yum groupinstall "Development tools"

安装图形库,httpd,php:

# yum install gd gd-devel httpd php

建立 nagios 用户和组:

# useradd nagios
默认是 shell 是 /bin/bash,不要使用 -s /sbin/nologin,否则会出现下面的错误:

Starting nagios:This account is currently not available.

将其添加到 nagios 用户组中:

# usermod -a -G nagios nagios
# usermod -a -G nagios apache

下载安装 nagios core 包,并且设置登陆的用户名和密码:

# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
# ./configure –with-command-group=nagios –prefix=/usr/local/nagios –with-httpd-conf=/usr/local/apache2/conf
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# make install-webconf
# htpasswd -c /usr/local/nagios/etc/htpasswd.users jaseywang

安装 nagios plugins 包:

# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
# make
# make install

开启 nagios:

# chkconfig –add nagios
# chkconfig nagios on

测试配置是否有误,这个在以后的所有重启 nagios 之前都需要检查:

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

若没有错误,启动 nagios;若有错误可以根据提示信息排错:

# /etc/init.d/nagios start
# /etc/init.d/httpd start

注意防火墙及 selinux:

# iptable -F
# setenforece 0

打开 http://ip/nagios 访问 "Service Detail" 时,出现:

It appears as though you do not have permission to view information for any of the hosts you requested…

由于权限的问题:

# sed -i 's/use_authentication=1/use_authentication=0/g'    /usr/local/nagios/etc/cgi.cfg
# service nagios restart

还有一种比较安全的方式:

use_authentication 的值仍未 1,将之前创建的账号添加到 cgi.cfg 文件中的权限配置文件中去:

authorized_for_system_information=jaseywang
authorized_for_configuration_information=jaseywang
authorized_for_system_commands=jaseywang
authorized_for_all_services=jaseywang
authorized_for_all_hosts=jaseywang
authorized_for_all_service_commands=jaseywnag
authorized_for_all_host_commands=jaseywang

以上就完成了本机的 nagios 的监控功能。

  • Cynicholas

    ./configure –with-command-group=nagios –prefix=/usr/local/nagios –with-httpd-conf=/usr/local/apache2/conf
    少了三 “-” :)

  • Cynicholas

    = =。。怎么两个英文”-“合一起就变成一个长的了。。