Agenda: exercises-nagios-I-III-basic.htm

File exercises-nagios-I-III-basic.htm, 18.2 KB (added by trac, 6 years ago)
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5  <meta http-equiv="Content-Style-Type" content="text/css" />
6  <meta name="generator" content="pandoc" />
7  <title>Nagios Installation and Configuration</title>
8  <link rel="stylesheet" href="../../style.css" type="text/css" />
9</head>
10<body>
11<div id="header">
12<h1 class="title">Nagios Installation and Configuration</h1>
13</div>
14<div id="TOC">
15<ul>
16<li><a href="#introduction"><span class="toc-section-number">1</span> Introduction</a><ul>
17<li><a href="#goals"><span class="toc-section-number">1.1</span> Goals</a></li>
18<li><a href="#notes"><span class="toc-section-number">1.2</span> Notes</a></li>
19</ul></li>
20<li><a href="#exercises"><span class="toc-section-number">2</span> Exercises</a></li>
21<li><a href="#part-i"><span class="toc-section-number">3</span> PART I</a><ul>
22<li><a href="#log-in-to-your-virtual-machine-as-the-sysadm-user."><span class="toc-section-number">3.1</span> 1. Log in to your virtual machine as the sysadm user.</a></li>
23<li><a href="#install-nagios-version-3"><span class="toc-section-number">3.2</span> 2. Install Nagios Version 3</a></li>
24<li><a href="#see-initial-nagios-configuration"><span class="toc-section-number">3.3</span> 3. See Initial Nagios Configuration</a></li>
25<li><a href="#add-routers-pcs-and-switches"><span class="toc-section-number">3.4</span> 4. Add Routers, PCs and Switches</a><ul>
26<li><a href="#a.-creating-the-switches.cfg-file"><span class="toc-section-number">3.4.1</span> 4a. Creating the switches.cfg file</a></li>
27<li><a href="#b.-creating-the-routers.cfg-file"><span class="toc-section-number">3.4.2</span> 4b. Creating the &quot;routers.cfg&quot; file</a></li>
28<li><a href="#c.-creating-the-pcs.cfg-file"><span class="toc-section-number">3.4.3</span> 4c. Creating the pcs.cfg File</a></li>
29</ul></li>
30<li><a href="#steps-5a---5c-should-be-repeated-whenever-you-update-the-configuration"><span class="toc-section-number">3.5</span> STEPS 5a - 5c SHOULD BE REPEATED WHENEVER YOU UPDATE THE CONFIGURATION!</a><ul>
31<li><a href="#a.-verify-that-your-configuration-files-are-ok"><span class="toc-section-number">3.5.1</span> 5a. Verify that your configuration files are OK</a></li>
32<li><a href="#b.-reloadrestart-nagios"><span class="toc-section-number">3.5.2</span> 5b. Reload/Restart Nagios</a></li>
33<li><a href="#c.-verify-via-the-web-interface"><span class="toc-section-number">3.5.3</span> 5c. Verify via the Web Interface</a></li>
34</ul></li>
35<li><a href="#view-status-map"><span class="toc-section-number">3.6</span> 6. View Status Map</a></li>
36</ul></li>
37<li><a href="#part-ii---configure-service-check-for-the-classroom-noc"><span class="toc-section-number">4</span> PART II - Configure Service check for the classroom NOC</a><ul>
38<li><a href="#configuring"><span class="toc-section-number">4.1</span> 0. Configuring</a></li>
39<li><a href="#associate-a-service-check-for-our-classroom-noc"><span class="toc-section-number">4.2</span> 1. Associate a service check for our classroom NOC</a></li>
40</ul></li>
41<li><a href="#part-iii---defining-services-for-all-pcs"><span class="toc-section-number">5</span> PART III - Defining Services for all PCs</a><ul>
42<li><a href="#determine-what-services-to-define-for-what-devices"><span class="toc-section-number">5.1</span> 1. Determine what services to define for what devices</a></li>
43<li><a href="#verify-that-ssh-is-running-on-the-routers-and-workshop-pcs-images"><span class="toc-section-number">5.2</span> 2. Verify that SSH is running on the routers and workshop PCs images</a></li>
44<li><a href="#check-that-http-is-running-on-all-the-classroom-pcs."><span class="toc-section-number">5.3</span> 3. Check that http is running on all the classroom PCs.</a></li>
45</ul></li>
46</ul>
47</div>
48<h1 id="introduction"><a href="#TOC"><span class="header-section-number">1</span> Introduction</a></h1>
49<h2 id="goals"><a href="#TOC"><span class="header-section-number">1.1</span> Goals</a></h2>
50<ul>
51<li>Install and configure Nagios</li>
52</ul>
53<h2 id="notes"><a href="#TOC"><span class="header-section-number">1.2</span> Notes</a></h2>
54<ul>
55<li>Commands preceded with &quot;$&quot; imply that you should execute the command as a general user - not as root.</li>
56<li>Commands preceded with &quot;#&quot; imply that you should be working as root.</li>
57<li>Commands with more specific command lines (e.g. &quot;rtrX&gt;&quot; or &quot;mysql&gt;&quot;) imply that you are executing commands on remote equipment, or within another program.</li>
58</ul>
59<h1 id="exercises"><a href="#TOC"><span class="header-section-number">2</span> Exercises</a></h1>
60<h1 id="part-i"><a href="#TOC"><span class="header-section-number">3</span> PART I</a></h1>
61<h2 id="log-in-to-your-virtual-machine-as-the-sysadm-user."><a href="#TOC"><span class="header-section-number">3.1</span> 1. Log in to your virtual machine as the sysadm user.</a></h2>
62<h2 id="install-nagios-version-3"><a href="#TOC"><span class="header-section-number">3.2</span> 2. Install Nagios Version 3</a></h2>
63<pre><code>$ sudo apt-get install nagios3 nagios3-doc</code></pre>
64<p>During installation you will be prompted for the &quot;Nagios web administration password:&quot; - This will be for the Nagios user &quot;nagiosadmin&quot;. When prompted enter in the password you are using your sysadm account.</p>
65<p>Note: if you have not already done so, you may be asked to configure the Postfix Mail Transport Agent during the Nagios installation process. Just accept the default &quot;Internet Site&quot;.</p>
66<h2 id="see-initial-nagios-configuration"><a href="#TOC"><span class="header-section-number">3.3</span> 3. See Initial Nagios Configuration</a></h2>
67<p>Open a browser, and go to your machine like this:</p>
68<pre><code>http://pcN.ws.nsrc.org/nagios3/</code></pre>
69<p>At the login prompt, login as:</p>
70<pre><code>        User Name: nagiosadmin
71        Password:  &lt;CLASS PASSWORD&gt;</code></pre>
72<p>Click on the &quot;Hosts&quot; link on the left of the initial Nagios page to see what has already been configured.</p>
73<h2 id="add-routers-pcs-and-switches"><a href="#TOC"><span class="header-section-number">3.4</span> 4. Add Routers, PCs and Switches</a></h2>
74<p>We will create three files, routers.cfg, switches.cfg and pcs.cfg and make entries for the hardware in our classroom.</p>
75<h3 id="a.-creating-the-switches.cfg-file"><a href="#TOC"><span class="header-section-number">3.4.1</span> 4a. Creating the switches.cfg file</a></h3>
76<pre><code>$ cd /etc/nagios3/conf.d                (just to be sure)
77$ sudo editor switches.cfg</code></pre>
78<p>In this file add the following entry (COPY and PASTE!):</p>
79<pre><code>define host {
80    use         generic-host
81    host_name   sw
82    alias       Backbone Switch
83    address     10.10.0.253
84}</code></pre>
85<p>Save the file and exit.</p>
86<h3 id="b.-creating-the-routers.cfg-file"><a href="#TOC"><span class="header-section-number">3.4.2</span> 4b. Creating the &quot;routers.cfg&quot; file</a></h3>
87<p>We have up to 10 total routers. These are rtr1-rtr9 and gw. And, we have 1 or 2 wireless Access Points (ap1, ap2). We will define entries for some of these. If any of these devices do not exist in your workshop, then do not include them. Remember, COPY and PASTE!</p>
88<pre><code>$ sudo editor routers.cfg</code></pre>
89<pre><code>define host {
90    use         generic-host
91    host_name   gw
92    alias       Classrooom Gateway Router
93    address     10.10.0.254
94}
95
96define host {
97    use         generic-host
98    host_name   rtr1
99    alias       Group 1 Gateway Router
100    address     10.10.1.254
101}
102
103define host {
104    use         generic-host
105    host_name   rtr2
106    alias       Group 2 Gateway Router
107    address     10.10.2.254
108}</code></pre>
109<p><em>*</em> Note: you do not need to add definitions for all routers now = you can always come back and add the rest later! <em>*</em></p>
110<pre><code>define host {
111    use         generic-host
112    host_name   ap1
113    alias       Wireless Access Point 1
114    address     10.10.0.251
115}
116
117define host {
118    use         generic-host
119    host_name   ap2
120    alias       Wireless Access Point 2
121    address     10.10.0.252
122}</code></pre>
123<p>Now save the file and exit the editor.</p>
124<h3 id="c.-creating-the-pcs.cfg-file"><a href="#TOC"><span class="header-section-number">3.4.3</span> 4c. Creating the pcs.cfg File</a></h3>
125<p>Now we will create entries for some of the Virtual Machines in our classroom Below we give you the first few entries. You should complete the file with as many PCs as you wish to add. We recommend that, at least, you add the 4 PCs that are members of your group as well as an entry for the classroom NOC, and at least one PC from another group (remember to COPY and PASTE!):</p>
126<pre><code>$ sudo editor pcs.cfg</code></pre>
127<pre><code>define host {
128    use         generic-host
129    host_name   noc
130    alias       Workshop NOC machine
131    address     10.10.0.250
132}
133
134#
135# Group 1
136#
137
138define host {
139    use         generic-host
140    host_name   pc1
141    alias       pc1
142    address     10.10.1.1
143}
144
145define host {
146    use         generic-host
147    host_name   pc2
148    alias       pc2
149    address     10.10.1.2
150}
151
152#
153# Another PC (example only!)
154#
155
156define host {
157    use         generic-host
158    host_name   pc20
159    alias       pc20
160    address     10.10.5.20
161}</code></pre>
162<p>You can save and exit from the file now. You can add more PC entries later.</p>
163<h2 id="steps-5a---5c-should-be-repeated-whenever-you-update-the-configuration"><a href="#TOC"><span class="header-section-number">3.5</span> STEPS 5a - 5c SHOULD BE REPEATED WHENEVER YOU UPDATE THE CONFIGURATION!</a></h2>
164<h3 id="a.-verify-that-your-configuration-files-are-ok"><a href="#TOC"><span class="header-section-number">3.5.1</span> 5a. Verify that your configuration files are OK</a></h3>
165<pre><code>$ sudo nagios3 -v /etc/nagios3/nagios.cfg </code></pre>
166<p>You will get some warnings like the ones below. You can ignore them for now.</p>
167<pre><code>Checking services...
168    Checked 7 services.
169Checking hosts...
170Warning: Host &#39;gw&#39; has no services associated with it!
171Warning: Host &#39;rtr1&#39; has no services associated with it!
172Warning: Host &#39;rtr2&#39; has no services associated with it!
173
174etc....
175...
176Total Warnings: N
177Total Errors:   0</code></pre>
178<p>Things look okay - No serious problems were detected during the check. Nagios is saying that it's unusual to monitor a device just for its existence on the network, without also monitoring some service.</p>
179<h3 id="b.-reloadrestart-nagios"><a href="#TOC"><span class="header-section-number">3.5.2</span> 5b. Reload/Restart Nagios</a></h3>
180<pre><code>$ sudo service nagios3 restart</code></pre>
181<p>HINT: You will be doing this a lot. If you do it all on one line, like this, then you can use arrow-up and call back the command:</p>
182<pre><code>$ sudo nagios3 -v /etc/nagios3/nagios.cfg &amp;&amp; sudo /etc/init.d/nagios3 restart</code></pre>
183<p>The '&amp;&amp;' ensures that the restart only happens if the config is valid.</p>
184<h3 id="c.-verify-via-the-web-interface"><a href="#TOC"><span class="header-section-number">3.5.3</span> 5c. Verify via the Web Interface</a></h3>
185<p>Go to the web interface (http://pcN.ws.nsrc.org/nagios3) and check that the hosts you just added are now visible in the interface. Click on the &quot;Hosts&quot; item on the left of the Nagios screen to see this. You may see it in &quot;PENDING&quot; status until the check is carried out.</p>
186<h2 id="view-status-map"><a href="#TOC"><span class="header-section-number">3.6</span> 6. View Status Map</a></h2>
187<p>Go to http://pcN.ws.nsrc.org/nagios3</p>
188<p>Click on the &quot;Map&quot; item on the left. You should see all your hosts with the Nagios process in the middle. The &quot;?&quot; are because we have not told Nagios what type of host each items is (router, switch, AP, PC running Linux, etc...)</p>
189<h1 id="part-ii---configure-service-check-for-the-classroom-noc"><a href="#TOC"><span class="header-section-number">4</span> PART II - Configure Service check for the classroom NOC</a></h1>
190<h2 id="configuring"><a href="#TOC"><span class="header-section-number">4.1</span> 0. Configuring</a></h2>
191<p>Now that we have our hardware configured we can start telling Nagios what services to monitor on the configured hardware, how to group the hardware in interesting ways, how to group services, etc.</p>
192<h2 id="associate-a-service-check-for-our-classroom-noc"><a href="#TOC"><span class="header-section-number">4.2</span> 1. Associate a service check for our classroom NOC</a></h2>
193<pre><code>$ sudo editor hostgroups_nagios2.cfg</code></pre>
194<ul>
195<li>Find the hostgroup named &quot;ssh-servers&quot;. In the members section of the defintion change the line:</li>
196</ul>
197<pre><code>members         localhost</code></pre>
198<p>to</p>
199<pre><code>members         localhost,noc</code></pre>
200<p>Exit and save the file.</p>
201<p>Verify that your changes are OK:</p>
202<pre><code>$ sudo nagios3 -v /etc/nagios3/nagios.cfg</code></pre>
203<p>Restart Nagios to see the new service assocation with your host:</p>
204<pre><code>$ sudo service nagios3 restart</code></pre>
205<p>In the Nagios web interface, find the &quot;Services&quot; link (left menu), and click on it.</p>
206<p>You should be able to find your recent change:</p>
207<pre><code>noc  SSH      PENDING ...</code></pre>
208<h1 id="part-iii---defining-services-for-all-pcs"><a href="#TOC"><span class="header-section-number">5</span> PART III - Defining Services for all PCs</a></h1>
209<p>Note: The default normal_check_interval is 5 (minutes) for checking services. This is defined in &quot;generic-service_nagios2.cfg&quot;. You may wish to change this to 1 (1 minute) to speed up how quickly service issues are detected, at least during this workshop.</p>
210<h2 id="determine-what-services-to-define-for-what-devices"><a href="#TOC"><span class="header-section-number">5.1</span> 1. Determine what services to define for what devices</a></h2>
211<p>This is a central concept in using Nagios and network monitoring tools in general. So far we are simply using ping to verify that physical hosts are up on our network and we have started monitoring a single service on a single host (your PC). The next step is to decide what services (web server, SSH, etc.) you wish to monitor for each host in the classroom.</p>
212<p>In this particular class we have:</p>
213<ul>
214<li>routers: running ssh and snmp</li>
215<li>switches: running telnet and possibly ssh as well as snmp</li>
216<li>pcs: All PCs are running ssh and http and should be running snmp The NOC is currently running an snmp daemon</li>
217</ul>
218<p>So, let's configure Nagios to check for these services on these devices.</p>
219<h2 id="verify-that-ssh-is-running-on-the-routers-and-workshop-pcs-images"><a href="#TOC"><span class="header-section-number">5.2</span> 2. Verify that SSH is running on the routers and workshop PCs images</a></h2>
220<p>In the file &quot;services_nagios2.cfg&quot; there is already an entry for the SSH service check, so you do not need to create this step. Instead, you simply need to re-define the &quot;ssh-servers&quot; entry in the file /etc/nagios3/conf.d/hostgroups_nagios2.cfg. The initial entry in the file looked like:</p>
221<pre><code># A list of your ssh-accessible servers
222define hostgroup {
223        hostgroup_name  ssh-servers
224                alias           SSH servers
225                members         localhost
226        }</code></pre>
227<p>What do you think you should change? Correct, the &quot;members&quot; line. You should add in entries for all the classroom pcs, routers and the switches that run ssh. With this information and the network diagram you should be able complete this entry.</p>
228<p>The entry will look something like this:</p>
229<pre><code>define hostgroup {
230        hostgroup_name  ssh-servers
231                alias           SSH servers
232                members         localhost,pc1,pc2,...,ap1,noc,rtr1,rtr2,...,gw
233        }</code></pre>
234<p>Note: do not remove &quot;localhost&quot; - This is your PC and represents Nagios' network point of view. So, for instance, if you are on &quot;pc3&quot; you would NOT list &quot;pc3&quot; in the list of all the classroom pcs as it is represented by the &quot;localhost&quot; entry.</p>
235<p>The &quot;members&quot; entry will be a long line and will likely wrap on the screen. If you want to start additional entries on newline then use &quot;&quot; to indicate a newline like this:</p>
236<p>Remember to include all the PCs and routers that you have defined in the files &quot;pcs.cfg&quot;, &quot;switches.cfg&quot; and &quot;routers.cfg&quot;. Only add entries from these files (i.e.: don't add &quot;pc8&quot; in your hostgroup list if &quot;pc8&quot; isn't defined in &quot;pcs.cfg&quot; as well).</p>
237<p>Once you are done, run the pre-flight check and restart Nagios:</p>
238<pre><code>$ sudo nagios3 -v /etc/nagios3/nagios.cfg &amp;&amp; sudo /etc/init.d/nagios3 restart</code></pre>
239<p>... and view your changes in the Nagios web interface.</p>
240<p>To continue with hostgroups you can add additional groups for later use, such as all our virtual routers. Go ahead and edit the file hostgroups_nagios2.cfg again:</p>
241<pre><code>$ sudo editor hostgroups_nagios2.cfg</code></pre>
242<p>and add the following to the end of the file (COPY and PASTE this):</p>
243<pre><code># A list of our virtual routers
244
245define hostgroup {
246        hostgroup_name  routers
247                alias           Cisco 7200 Routers
248                members         rtr1,rtr2,...
249        }</code></pre>
250<p>Only list the routers you have defined in the &quot;routers.cfg&quot;.</p>
251<p>Save and exit from the file. Verify that everything is OK:</p>
252<pre><code>$ sudo nagios3 -v /etc/nagios3/nagios.cfg</code></pre>
253<p>If everything looks good, then restart Nagios</p>
254<pre><code>$ sudo service nagios3 restart</code></pre>
255<h2 id="check-that-http-is-running-on-all-the-classroom-pcs."><a href="#TOC"><span class="header-section-number">5.3</span> 3. Check that http is running on all the classroom PCs.</a></h2>
256<p>This is almost identical to the previous exercise. Just make the change to the HTTP service adding in each PC (no routers or switches). Remember, you don't need to add your machine as it is already defined as &quot;localhost&quot;. Look for this hostgroup in the file hostgroups_nagios2.cfg and update the &quot;members&quot; line appropriately.</p>
257<p>If you have questions or are confused please ask an instructor for help.</p>
258</body>
259</html>