---
title: "实战ubuntu安装nagios"
author: "xiaolin0199"
date: "2014-11-14T14:00:11Z"
tags: []
categories: ["Web前端"]
slug: "ubuntu-nagios"
draft: false
lastmod: "2014-11-20T11:39:32Z"
id: 2155864
url: "https://xiaolin0199.iteye.com/blog/2155864"
---

\**  使用nagios的前提是你已经正常的安装了apache

 

1\. 安装nagios

写道

sudo apt-get install nagios3

    \**  安装过程中需要你输入一个邮箱地址，同时设置 nagios web 的登录密码 (初始帐号: nagiosadmin)

 

2\. 查看安装版本

  

写道

 

xiaofei@xiaofei-O-E-M:~$ nagios3 --version

Nagios Core 3.5.1  
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors  
Copyright (c) 1999-2009 Ethan Galstad  
Last Modified: 08-30-2013  
License: GPL

Website: http://www.nagios.org  
This program is free software; you can redistribute it and/or modify  
it under the terms of the GNU General Public License version 2 as  
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,  
but WITHOUT ANY WARRANTY; without even the implied warranty of  
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
GNU General Public License for more details.

You should have received a copy of the GNU General Public License  
along with this program; if not, write to the Free Software  
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 3. 启动nagios

 

写道

 

xiaofei@xiaofei-O-E-M:~$ sudo /etc/init.d/nagios3 start  
\* Starting nagios3 monitoring daemon nagios3  
\* already running! \[ OK ]

4\.  进入

 

写道

 

http://localhost/nagios3  (nagiosadmin/第一步中设置的密码)

 

5\.  为nagios添加一些有用的插件 （参考 ）

[http://www.williamsang.com/archives/2060.html](http://www.williamsang.com/archives/2060.html) 

\**  上面链接在添加 pnp4nagios插件时，使用时会出现404错误 ，我这里需要 手动添加其apache.conf到/etc/apache2/conf-\*下面去

 

写道

 

cd /etc/apache2/conf-available  
sudo ln -sf ../../pnp4nagios/apache.conf pnp4nagios.conf

cd /etc/apache2/conf-enabled  
sudo ln -sf ../conf-available/pnp4nagios.conf pnp4nagios.conf

 

6\.  查看 localhost信息

![](http://dl2.iteye.com/upload/attachment/0103/4173/2a848f40-f6aa-39e7-a844-c0cb5c1a59b3.png)  
 7.  如何查看 使用 check\_http 来监控 （本机地址（监控机）: 10.10.10.145 ,  被监控机 : 10.10.10.146 , 10.10.10.147）

 

首先 我们重定义一个 bbt\_check\_http 

 

写道

 

cd /etc/nagios3/

\** 在最后加上下面这段

define command{  
        command\_name    bbt\_check\_http  
        command\_line       $USER1$/check\_http -H $HOSTNAME$ -I $HOSTADDRESS$ -p $ARG1$ -u $ARG2$ -w $ARG3$ -c $ARG4$ -t $ARG5$  
}

\** USER1 是预定义宏变量 ， 其定义在 resource.cfg 中

 

接着我们开始定义对146,147机器的监控代码 

 

写道

cd /etc/nagios3/conf.d/

sudo touch u146.cfg

sudo vim u146.cfg

 

```
define host{
        use                     generic-host            ; Name of host template to use
        host_name         10.10.10.146
        alias                    u146
        address               10.10.10.146
        }


define service{
        use                                generic-service
        host_name                    10.10.10.146
        service_description       http://10.10.10.146:8000/
        check_command           bbt_check_http!8000!'/'!10!20!30
        }
```

 

 \**  147 的定义同 上面 146  ,  在这里曾经走了不少弯路，开始一直在 bbt\_check\_http 这里加上 被控机器 的IP，结果一直不成功, 后来才知道 宏定义的变量 只需要在 define host里定义后此处就不需要了

 

参考 ：  [http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26660567&id=3810304](http://blog.chinaunix.net/xmlrpc.php?r=blog%2Farticle&uid=26660567&id=3810304)

   
![](http://dl2.iteye.com/upload/attachment/0103/4180/6bdbeaf6-ecba-37b6-9ec8-aa5738adb9bb.png)