1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head xmlns="http://www.w3.org/1999/xhtml">
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title xmlns="">Nagios</title>
7
<link rel="stylesheet" href="../../libs/ubuntu-book.css" type="text/css" />
8
<link rel="home" href="index.html" title="Ubuntu Server Guide" />
9
<link rel="up" href="monitoring.html" title="Chapter 9. Monitoring" />
10
<link rel="prev" href="monitoring-overview.html" title="Overview" />
11
<link rel="next" href="munin.html" title="Munin" />
12
<link rel="copyright" href="legal.html" title="Credits and License" />
16
<img id="topcap" alt="" src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-top.png" />
17
<div id="layout" class="container clear-block">
18
<script xmlns="" src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script>
19
<script xmlns="" type="text/javascript">
20
_uacct = "UA-1018242-8";
24
<div id="logo-floater">
26
<a href="https://help.ubuntu.com" title="Ubuntu Documentation">
27
<img alt="Ubuntu" id="logo" src="https://help.ubuntu.com/htdocs/ubuntunew/img/logo.png" />
32
<form action="http://www.google.com/cse" id="cse-search-box">
34
<input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />
35
<input type="hidden" name="ie" value="UTF-8" />
36
<input type="text" name="q" size="27" />
37
<input type="submit" name="sa" value="Search" />
42
document.write('<form action="https://help.ubuntu.com/search.html" id="cse-search-box">');
43
document.write(' <div>');
44
document.write(' <input type="hidden" name="cof" value="FORID:9" />');
45
document.write(' <input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />');
46
document.write(' <input type="hidden" name="ie" value="UTF-8" />');
47
document.write(' <input type="text" name="q" size="27" />');
48
document.write(' <input type="submit" name="sa" value="Search" />');
49
document.write(' </div>');
50
document.write('</form>');
53
<a href="https://help.ubuntu.com/">
54
<img alt="Official Documentation" src="https://help.ubuntu.com/htdocs/ubuntunew/img/help-about.png" />
55
<span>Official Documentation</span>
61
<div class="breadcrumbs"><a href="https://help.ubuntu.com/">Ubuntu Documentation</a> > <a href="https://help.ubuntu.com/11.04">Ubuntu 11.04</a> > <span class="breadcrumb-link"><a href="index.html">Ubuntu Server Guide</a></span> > <span class="breadcrumb-link"><a href="monitoring.html">Monitoring</a></span> > <span class="breadcrumb-node">Nagios</span></div>
62
<div xmlns="http://www.w3.org/1999/xhtml" class="sect1" title="Nagios">
63
<div class="titlepage">
66
<h2 class="title" style="clear: both"><a id="nagios"></a>Nagios</h2>
70
<div class="sect2" title="Installation">
71
<div class="titlepage">
74
<h3 class="title"><a id="nagios-installation"></a>Installation</h3>
79
First, on <span class="emphasis"><em>server01</em></span> install the <span class="application"><strong>nagios</strong></span> package. In a terminal
83
<span class="command"><strong>sudo apt-get install nagios3 nagios-nrpe-plugin</strong></span>
86
You will be asked to enter a password for the <span class="emphasis"><em>nagiosadmin</em></span> user. The user's credentials are
87
stored in <code class="filename">/etc/nagios3/htpasswd.users</code>. To change the <span class="emphasis"><em>nagiosadmin</em></span> password, or
88
add additional users to the Nagios CGI scripts, use the <span class="application"><strong>htpasswd</strong></span> that is part of the
89
<span class="application"><strong>apache2-utils</strong></span> package.
92
For example, to change the password for the <span class="emphasis"><em>nagiosadmin</em></span> user enter:
95
<span class="command"><strong>sudo htpasswd /etc/nagios3/htpasswd.users nagiosadmin</strong></span>
101
<span class="command"><strong>sudo htpasswd /etc/nagios3/htpasswd.users steve</strong></span>
104
Next, on <span class="emphasis"><em>server02</em></span> install the <span class="application"><strong>nagios-nrpe-server</strong></span> package. From a terminal on
108
<span class="command"><strong>sudo apt-get install nagios-nrpe-server</strong></span>
110
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
111
<table border="0" summary="Note">
113
<td rowspan="2" align="center" valign="top" width="25">
114
<img alt="[Note]" src="../../libs/admon/note.png" />
116
<th align="left"></th>
119
<td align="left" valign="top">
121
<span class="application"><strong>NRPE</strong></span> allows you to execute local checks on remote hosts. There are other ways of accomplishing
122
this through other Nagios plugins as well as other checks.
129
<div class="sect2" title="Configuration Overview">
130
<div class="titlepage">
133
<h3 class="title"><a id="nagios-configuration-overview"></a>Configuration Overview</h3>
138
There are a couple of directories containing <span class="application"><strong>Nagios</strong></span> configuration and check files.
140
<div class="itemizedlist">
141
<ul class="itemizedlist" type="disc">
142
<li class="listitem">
144
<code class="filename">/etc/nagios3</code>: contains configuration files for the operation of the <span class="application"><strong>nagios</strong></span>
145
daemon, CGI files, hosts, etc.
148
<li class="listitem">
150
<code class="filename">/etc/nagios-plugins</code>: houses configuration files for the service checks.
153
<li class="listitem">
155
<code class="filename">/etc/nagios</code>: on the remote host contains the <span class="application"><strong>nagios-nrpe-server</strong></span> configuration files.
158
<li class="listitem">
160
<code class="filename">/usr/lib/nagios/plugins/</code>: where the check binaries are stored. To see the options of a check use the
161
<span class="emphasis"><em>-h</em></span> option.
164
For example: <span class="command"><strong>/usr/lib/nagios/plugins/check_dhcp -h</strong></span>
170
There are a plethora of checks <span class="application"><strong>Nagios</strong></span> can be configured to execute for any given host. For this example Nagios
171
will be configured to check disk space, DNS, and a MySQL hostgroup. The DNS check will be on <span class="emphasis"><em>server02</em></span>, and the
172
MySQL hostgroup will include both <span class="emphasis"><em>server01</em></span> and <span class="emphasis"><em>server02</em></span>.
174
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
175
<table border="0" summary="Note">
177
<td rowspan="2" align="center" valign="top" width="25">
178
<img alt="[Note]" src="../../libs/admon/note.png" />
180
<th align="left"></th>
183
<td align="left" valign="top">
185
See <a class="xref" href="httpd.html" title="HTTPD - Apache2 Web Server">the section called “HTTPD - Apache2 Web Server”</a> for details on setting up Apache, <a class="xref" href="dns.html" title="Chapter 7. Domain Name Service (DNS)">Chapter 7, <i>Domain Name Service (DNS)</i></a> for DNS, and <a class="xref" href="mysql.html" title="MySQL">the section called “MySQL”</a> for MySQL.
192
Additionally, there are some terms that once explained will hopefully make understanding Nagios configuration easier:
194
<div class="itemizedlist">
195
<ul class="itemizedlist" type="disc">
196
<li class="listitem">
198
<span class="emphasis"><em>Host</em></span>: a server, workstation, network device, etc that is being monitored.
201
<li class="listitem">
203
<span class="emphasis"><em>Host Group</em></span>: a group of similar hosts. For example, you could group all web servers, file server, etc.
206
<li class="listitem">
208
<span class="emphasis"><em>Service</em></span>: the service being monitored on the host. Such as HTTP, DNS, NFS, etc.
211
<li class="listitem">
213
<span class="emphasis"><em>Service Group</em></span>: allows you to group multiple services together. This is useful for grouping multiple HTTP
217
<li class="listitem">
219
<span class="emphasis"><em>Contact</em></span>: person to be notified when an event takes place. Nagios can be configured to send emails, SMS messages, etc.
225
By default Nagios is configured to check HTTP, disk space, SSH, current users, processes, and load on the <span class="emphasis"><em>localhost</em></span>.
226
Nagios will also <span class="application"><strong>ping</strong></span> check the <span class="emphasis"><em>gateway</em></span>.
229
Large Nagios installations can be quite complex to configure. It is usually best to start small, one or two hosts, get things configured the way you like
233
<div class="sect2" title="Configuration">
234
<div class="titlepage">
237
<h3 class="title"><a id="nagios-configuration"></a>Configuration</h3>
241
<div class="itemizedlist">
242
<ul class="itemizedlist" type="disc">
243
<li class="listitem">
244
<div class="procedure">
245
<ol class="procedure" type="1">
246
<li class="step" title="Step 1">
248
First, create a <span class="emphasis"><em>host</em></span> configuration file for <span class="emphasis"><em>server02</em></span>.
249
Unless otherwise specified, run all these commands on <span class="emphasis"><em>server01</em></span>.
253
<span class="command"><strong>sudo cp /etc/nagios3/conf.d/localhost_nagios2.cfg /etc/nagios3/conf.d/server02.cfg</strong></span>
255
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
256
<table border="0" summary="Note">
258
<td rowspan="2" align="center" valign="top" width="25">
259
<img alt="[Note]" src="../../libs/admon/note.png" />
261
<th align="left"></th>
264
<td align="left" valign="top">
266
In the above and following command examples, replace <span class="emphasis"><em>"server01"</em></span>, <span class="emphasis"><em>"server02"</em></span>
267
<span class="emphasis"><em>172.18.100.100</em></span>, and <span class="emphasis"><em>172.18.100.101</em></span> with the host names and IP addresses
275
<li class="step" title="Step 2">
277
Next, edit <code class="filename">/etc/nagios3/conf.d/server02.cfg</code>:
279
<pre class="programlisting">
281
use generic-host ; Name of host template to use
284
address 172.18.100.101
291
service_description DNS
292
check_command check_dns!172.18.100.101
296
<li class="step" title="Step 3">
298
Restart the <span class="application"><strong>nagios</strong></span> daemon to enable the new configuration:
301
<span class="command"><strong>sudo /etc/init.d/nagios3 restart</strong></span>
307
<li class="listitem">
308
<div class="procedure">
309
<ol class="procedure" type="1">
310
<li class="step" title="Step 1">
312
Now add a service definition for the MySQL check by adding the following to <code class="filename">/etc/nagios3/conf.d/services_nagios2.cfg</code>:
314
<pre class="programlisting">
315
# check MySQL servers.
317
hostgroup_name mysql-servers
318
service_description MySQL
319
check_command check_mysql_cmdlinecred!nagios!secret!$HOSTADDRESS
321
notification_interval 0 ; set > 0 if you want to be renotified
325
<li class="step" title="Step 2">
327
A <span class="emphasis"><em>mysql-servers</em></span> hostgroup now needs to be defined. Edit
328
<code class="filename">/etc/nagios3/conf.d/hostgroups_nagios2.cfg</code> adding:
330
<pre class="programlisting">
333
hostgroup_name mysql-servers
335
members localhost, server02
339
<li class="step" title="Step 3">
341
The Nagios check needs to authenticate to MySQL. To add a <span class="emphasis"><em>nagios</em></span> user to MySQL enter:
344
<span class="command"><strong>mysql -u root -p -e "create user nagios identified by 'secret';"</strong></span>
346
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
347
<table border="0" summary="Note">
349
<td rowspan="2" align="center" valign="top" width="25">
350
<img alt="[Note]" src="../../libs/admon/note.png" />
352
<th align="left"></th>
355
<td align="left" valign="top">
357
The <span class="emphasis"><em>nagios</em></span> user will need to be added all hosts in the <span class="emphasis"><em>mysql-servers</em></span> hostgroup.
364
<li class="step" title="Step 4">
366
Restart <span class="application"><strong>nagios</strong></span> to start checking the MySQL servers.
369
<span class="command"><strong>sudo /etc/init.d/nagios3 restart</strong></span>
375
<li class="listitem">
376
<div class="procedure">
377
<ol class="procedure" type="1">
378
<li class="step" title="Step 1">
380
Lastly configure NRPE to check the disk space on <span class="emphasis"><em>server02</em></span>.
383
On <span class="emphasis"><em>server01</em></span> add the
384
service check to <code class="filename">/etc/nagios3/conf.d/server02.cfg</code>:
386
<pre class="programlisting">
391
service_description nrpe-disk
392
check_command check_nrpe_1arg!check_all_disks!172.18.100.101
396
<li class="step" title="Step 2">
398
Now on <span class="emphasis"><em>server02</em></span> edit <code class="filename">/etc/nagios/nrpe.cfg</code> changing:
400
<pre class="programlisting">
401
allowed_hosts=172.18.100.100
404
And below in the command definition area add:
406
<pre class="programlisting">
407
command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -e
410
<li class="step" title="Step 3">
412
Finally, restart <span class="application"><strong>nagios-nrpe-server</strong></span>:
415
<span class="command"><strong>sudo /etc/init.d/nagios-nrpe-server restart</strong></span>
418
<li class="step" title="Step 4">
420
Also, on <span class="emphasis"><em>server01</em></span> restart <span class="application"><strong>nagios</strong></span>:
423
<span class="command"><strong>sudo /etc/init.d/nagios3 restart</strong></span>
432
You should now be able to see the host and service checks in the Nagios CGI files. To access them point a
433
browser to http://server01/nagios3. You will then be prompted for the <span class="emphasis"><em>nagiosadmin</em></span> username
437
<div class="sect2" title="References">
438
<div class="titlepage">
441
<h3 class="title"><a id="nagios-references"></a>References</h3>
446
This section has just scratched the surface of Nagios' features. The <span class="application"><strong>nagios-plugins-extra</strong></span> and
447
<span class="application"><strong>nagios-snmp-plugins</strong></span> contain many more service checks.
449
<div class="itemizedlist">
450
<ul class="itemizedlist" type="disc">
451
<li class="listitem">
453
For more information see <a class="ulink" href="http://www.nagios.org/" target="_top">Nagios</a> website.
456
<li class="listitem">
458
Specifically the <a class="ulink" href="http://nagios.sourceforge.net/docs/3_0/" target="_top">Online Documentation</a> site.
461
<li class="listitem">
463
There is also a list of <a class="ulink" href="http://www.nagios.org/propaganda/books/" target="_top">books</a> related to Nagios
464
and network monitoring:
467
<li class="listitem">
469
The <a class="ulink" href="https://help.ubuntu.com/community/Nagios" target="_top">Nagios Ubuntu Wiki</a> page also has more details.
477
<div xmlns="http://www.w3.org/1999/xhtml" class="navfooter">
479
<table width="100%" summary="Navigation footer">
481
<td width="40%" align="left"><a accesskey="p" href="monitoring-overview.html"><img src="../../libs/navig/prev.png" alt="Prev" /></a> </td>
482
<td width="20%" align="center">
483
<a accesskey="u" href="monitoring.html">
484
<img src="../../libs/navig/up.png" alt="Up" />
487
<td width="40%" align="right"> <a accesskey="n" href="munin.html"><img src="../../libs/navig/next.png" alt="Next" /></a></td>
490
<td width="40%" align="left" valign="top">Overview </td>
491
<td width="20%" align="center">
492
<a accesskey="h" href="index.html">
493
<img src="../../libs/navig/home.png" alt="Home" />
496
<td width="40%" align="right" valign="top"> Munin</td>
502
<div id="ubuntulinks">
503
<p>The material in this document is available under a free license, see <a href="/legal.html">Legal</a> for details<br />
504
For information on contributing see the <a href="https://wiki.ubuntu.com/DocumentationTeam">Ubuntu Documentation Team wiki page</a>. To report a problem, visit the <a href="https://bugs.launchpad.net/ubuntu/+source/ubuntu-docs">bug page for Ubuntu Documentation</a></p>
508
<img src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-bottom.png" alt="" />