Nagios 3.2 安装记录

作者:Hily 原始链接:http://hily.me/blog/2010/01/nagios-3-2-install/
版权声明:可以转载,转载时务必以超链接形式标明文章原始出处作者信息版权声明

工作比较忙,日志不能再像以前那样系统地整理了,简要记录下安装过程。

什么是 Nagios?

Nagios 是一个系统和网络监控程序,它可以监控你指定的主机或服务,并能在主机或服务出现故障时提醒你。

它有以下特性:

  • 网络服务监控(包括 SMTP, POP3, HTTP, NNTP, PING 等)
  • 服务器资源监控(CPU负载, 磁盘使用率等)
  • 可以很容易地定制开发自己需要的服务监测插件
  • 并行的服务监测
  • 支持父主机规则,支持分布式
  • 主机或服务故障时,支持使用邮件、短信等方式提醒管理员
  • 支持故障时的事件定义,可以先行解决一些问题
  • 自动的日志回滚
  • 支持冗余监控主机
  • 可以通过 Web 界面查看当前网络状态、通知和故障日志等信息

Nagios

Nagios 项目首页:http://www.nagios.org/

安装 Nagios 主要是两部分,Nagios Core 和 Nagios Plugins。Nagios Core 只是个 Daemon,负责调度,真正的检测操作还是通过 Nagios Plugins 来实现的。

安装 Nagios Core

* 下载解压

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz

tar zxf nagios-3.2.0.tar.gz

cd nagios-3.2.0

* 添加 nagios 用户和组

useradd -m -s /bin/bash nagios

groupadd nagios

usermod -G nagios nagios

因为要用到 CGI 的 Web 监控面板,所以这里我们还要添加一个 nagcmd 组,用于 CGI 执行相关指令。

groupadd nagcmd

usermod -a -G nagcmd nagios

usermod -a -G nagcmd www

* 配置编译安装

./configure --with-command-group=nagcmd --with-htmurl=/ --with-cgiurl=/cgi-bin

make all

make install-init

make install-commandmode

make install-config

* 添加启动服务

rc-update add nagios default

* 启动 Nagios

/etc/init.d/nagios start

安装 Nagios Plugins

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

tar zxf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --with-cgiurl=/cgi-bin
make && make install

配置 Web 监控面板

我是纯 Nginx 族,要托管监控面板的 CGI 当然还是选择用 Nginx。

如何配置 Nginx 支持 CGI 呢?请看我的上一篇:《配置 Nginx 支持 CGI》

新建站点配置文件:

server {
    listen       80;
    server_name  nagios.local;

    access_log  /work/www/logs/nagios.access.log  main;
    error_log  /work/www/logs/nagios.error.log;

    location / {
        root   /usr/local/nagios/share;
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        root           /usr/local/nagios/share;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_pass   unix:/tmp/php-fpm.sock;
    }

    location /cgi-bin/images {
        alias /usr/local/nagios/share/images;
    }

    location /cgi-bin/stylesheets {
        alias /usr/local/nagios/share/stylesheets;
    }

    location /cgi-bin {
        alias /usr/local/nagios/sbin;
    }

    location ~ \.cgi$ {
        root           /usr/local/nagios/sbin;
        rewrite ^/cgi-bin/(.*)\.cgi /$1.cgi break;
        fastcgi_index  index.cgi;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        include        nginx_fcgi_params;
        fastcgi_read_timeout    5m;
        fastcgi_pass   unix:/var/run/nginx-fcgi.sock;
    }
}

* 修改配置文件

打开 /usr/local/nagios/etc/cgi.cfg,修改 use_authentication 为:

use_authentication=0

即去除用户验证,然后重启 nagios。

打开 /usr/local/nagios/share/config.inc.php,把:

$cfg['cgi_base_url']='/nagios/cgi-bin';

改为(根据自己的实际情况修改):

$cfg['cgi_base_url']='/cgi-bin';

* 访问监控面板

http://nagios.local/

搭建完成!

-- EOF --

发表一下您的高见

If you have any question, or for the language problem, please fell free to leave a comment or just contact me with email: hilyjiang [At] Gmail.