# Track4Agenda: 3.3.1.exercises-nagios-I-III-basic.htm

File 3.3.1.exercises-nagios-I-III-basic.htm, 36.8 KB (added by trac, 3 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">
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  <style type="text/css">code{white-space: pre;}</style>
11<body>
13<h1 class="title">Nagios Installation and Configuration</h1>
14</div>
15<div id="TOC">
16<ul>
17<li><a href="#introduction"><span class="toc-section-number">1</span> Introduction</a><ul>
18<li><a href="#goals"><span class="toc-section-number">1.1</span> Goals</a></li>
19<li><a href="#notes"><span class="toc-section-number">1.2</span> Notes</a></li>
20</ul></li>
21<li><a href="#exercises"><span class="toc-section-number">2</span> Exercises</a></li>
22<li><a href="#part-i"><span class="toc-section-number">3</span> PART I</a><ul>
24<li><a href="#install-nagios-version-3"><span class="toc-section-number">3.2</span> 2. Install Nagios Version 3</a></li>
25<li><a href="#see-initial-nagios-configuration"><span class="toc-section-number">3.3</span> 3. See Initial Nagios Configuration</a></li>
27<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>
28<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>
29<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>
30</ul></li>
31<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>
32<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>
34<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>
35</ul></li>
36<li><a href="#view-status-map"><span class="toc-section-number">3.6</span> 6. View Status Map</a></li>
37</ul></li>
38<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>
39<li><a href="#configuring"><span class="toc-section-number">4.1</span> 0. Configuring</a></li>
40<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>
41</ul></li>
42<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>
43<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>
44<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>
45<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>
46</ul></li>
47</ul>
48</div>
51<ul>
52<li>Install and configure Nagios</li>
53</ul>
55<ul>
56<li>Commands preceded with &quot;$&quot; imply that you should execute the command as a general user - not as root.</li> 57<li>Commands preceded with &quot;#&quot; imply that you should be working as root.</li> 58<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> 59</ul> 60<h1 id="exercises"><span class="header-section-number">2</span> Exercises</h1> 61<h1 id="part-i"><span class="header-section-number">3</span> PART I</h1> 62<h2 id="log-in-to-your-virtual-machine-as-the-sysadm-user."><span class="header-section-number">3.1</span> 1. Log in to your virtual machine as the sysadm user.</h2> 63<h2 id="install-nagios-version-3"><span class="header-section-number">3.2</span> 2. Install Nagios Version 3</h2> 64<pre><code>$ sudo apt-get install nagios3 nagios3-doc</code></pre>
66<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>
67<h2 id="see-initial-nagios-configuration"><span class="header-section-number">3.3</span> 3. See Initial Nagios Configuration</h2>
68<p>Open a browser, and go to your machine like this:</p>
69<pre><code>http://pcN.ws.nsrc.org/nagios3/</code></pre>
73<p>Click on the &quot;Hosts&quot; link on the left of the initial Nagios page to see what has already been configured.</p>
75<p>We will create three files, routers.cfg, switches.cfg and pcs.cfg and make entries for the hardware in our classroom.</p>
76<h3 id="a.-creating-the-switches.cfg-file"><span class="header-section-number">3.4.1</span> 4a. Creating the switches.cfg file</h3>
77<pre><code>$cd /etc/nagios3/conf.d (just to be sure) 78$ sudo editor switches.cfg</code></pre>
79<p>In this file add the following entry (COPY and PASTE!):</p>
80<pre><code>define host {
81    use         generic-host
82    host_name   sw
83    alias       Backbone Switch
85}</code></pre>
86<p>Save the file and exit.</p>
87<h3 id="b.-creating-the-routers.cfg-file"><span class="header-section-number">3.4.2</span> 4b. Creating the &quot;routers.cfg&quot; file</h3>
88<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>
89<pre><code>$sudo editor routers.cfg</code></pre> 90<pre><code>define host { 91 use generic-host 92 host_name gw 93 alias Classrooom Gateway Router 94 address 10.10.0.254 95} 96 97define host { 98 use generic-host 99 host_name rtr1 100 alias Group 1 Gateway Router 101 address 10.10.1.254 102} 103 104define host { 105 use generic-host 106 host_name rtr2 107 alias Group 2 Gateway Router 108 address 10.10.2.254 109}</code></pre> 110<p>*** Note: you do not need to add definitions for all routers now = you can always come back and add the rest later! ***</p> 111<pre><code>define host { 112 use generic-host 113 host_name ap1 114 alias Wireless Access Point 1 115 address 10.10.0.251 116} 117 118define host { 119 use generic-host 120 host_name ap2 121 alias Wireless Access Point 2 122 address 10.10.0.252 123}</code></pre> 124<p>Now save the file and exit the editor.</p> 125<h3 id="c.-creating-the-pcs.cfg-file"><span class="header-section-number">3.4.3</span> 4c. Creating the pcs.cfg File</h3> 126<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> 127<pre><code>$ sudo editor pcs.cfg</code></pre>
128<pre><code>define host {
129    use         generic-host
130    host_name   noc
131    alias       Workshop NOC machine
133}
134
135#
136# Group 1
137#
138
139define host {
140    use         generic-host
141    host_name   pc1
142    alias       pc1
144}
145
146define host {
147    use         generic-host
148    host_name   pc2
149    alias       pc2
151}
152
153#
154# Another PC (example only!)
155#
156
157define host {
158    use         generic-host
159    host_name   pc20
160    alias       pc20
162}</code></pre>
163<p>You can save and exit from the file now. You can add more PC entries later.</p>
164<h2 id="steps-5a---5c-should-be-repeated-whenever-you-update-the-configuration"><span class="header-section-number">3.5</span> STEPS 5a - 5c SHOULD BE REPEATED WHENEVER YOU UPDATE THE CONFIGURATION!</h2>
166<pre><code>$sudo nagios3 -v /etc/nagios3/nagios.cfg </code></pre> 167<p>You will get some warnings like the ones below. You can ignore them for now.</p> 168<pre><code>Checking services... 169 Checked 7 services. 170Checking hosts... 171Warning: Host 'gw' has no services associated with it! 172Warning: Host 'rtr1' has no services associated with it! 173Warning: Host 'rtr2' has no services associated with it! 174 175etc.... 176... 177Total Warnings: N 178Total Errors: 0</code></pre> 179<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> 180<h3 id="b.-reloadrestart-nagios"><span class="header-section-number">3.5.2</span> 5b. Reload/Restart Nagios</h3> 181<pre><code>$ sudo service nagios3 restart</code></pre>
182<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>
183<pre><code>$sudo nagios3 -v /etc/nagios3/nagios.cfg &amp;&amp; sudo service nagios3 restart</code></pre> 184<p>The '&amp;&amp;' ensures that the restart only happens if the config is valid.</p> 185<h3 id="c.-verify-via-the-web-interface"><span class="header-section-number">3.5.3</span> 5c. Verify via the Web Interface</h3> 186<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> 187<h2 id="view-status-map"><span class="header-section-number">3.6</span> 6. View Status Map</h2> 188<p>Go to http://pcN.ws.nsrc.org/nagios3</p> 189<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> 190<h1 id="part-ii---configure-service-check-for-the-classroom-noc"><span class="header-section-number">4</span> PART II - Configure Service check for the classroom NOC</h1> 191<h2 id="configuring"><span class="header-section-number">4.1</span> 0. Configuring</h2> 192<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> 193<h2 id="associate-a-service-check-for-our-classroom-noc"><span class="header-section-number">4.2</span> 1. Associate a service check for our classroom NOC</h2> 194<pre><code>$ sudo editor hostgroups_nagios2.cfg</code></pre>
195<ul>
196<li>Find the hostgroup named &quot;ssh-servers&quot;. In the members section of the defintion change the line:</li>
197</ul>
198<pre><code>members         localhost</code></pre>
199<p>to</p>
200<pre><code>members         localhost,noc</code></pre>
201<p>Exit and save the file.</p>
202<p>Verify that your changes are OK:</p>
203<pre><code>$sudo nagios3 -v /etc/nagios3/nagios.cfg</code></pre> 204<p>Restart Nagios to see the new service assocation with your host:</p> 205<pre><code>$ sudo service nagios3 restart</code></pre>
206<p>In the Nagios web interface, find the &quot;Services&quot; link (left menu), and click on it.</p>
207<p>You should be able to find your recent change:</p>
208<pre><code>noc  SSH      PENDING ...</code></pre>
209<h1 id="part-iii---defining-services-for-all-pcs"><span class="header-section-number">5</span> PART III - Defining Services for all PCs</h1>
210<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>
211<h2 id="determine-what-services-to-define-for-what-devices"><span class="header-section-number">5.1</span> 1. Determine what services to define for what devices</h2>
212<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>
213<p>In this particular class we have:</p>
214<ul>
215<li>routers: running ssh and snmp</li>
216<li>switches: running telnet and possibly ssh as well as snmp</li>
217<li>pcs: All PCs are running ssh and http and should be running snmp The NOC is currently running an snmp daemon</li>
218</ul>
219<p>So, let's configure Nagios to check for these services on these devices.</p>
220<h2 id="verify-that-ssh-is-running-on-the-routers-and-workshop-pcs-images"><span class="header-section-number">5.2</span> 2. Verify that SSH is running on the routers and workshop PCs images</h2>
221<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. We have just changed this file, and added the <code>noc</code> host, so it looked like:</p>
222<pre><code># A list of your ssh-accessible servers
223define hostgroup {
224        hostgroup_name  ssh-servers
225                alias           SSH servers
226                members         localhost,noc
227        }</code></pre>
228<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>
229<p>The entry will look something like this:</p>
230<pre><code>define hostgroup {
231        hostgroup_name  ssh-servers
232                alias           SSH servers
233                members         localhost,noc,pc1,pc2,...,ap1,rtr1,rtr2,...,gw
234        }</code></pre>
235<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>
236<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>
237<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>
238<p>Once you are done, run the pre-flight check and restart Nagios:</p>
239<pre><code>$sudo nagios3 -v /etc/nagios3/nagios.cfg &amp;&amp; sudo service nagios3 restart</code></pre> 240<p>... and view your changes in the Nagios web interface.</p> 241<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> 242<pre><code>$ sudo editor hostgroups_nagios2.cfg</code></pre>
243<p>and add the following to the end of the file (COPY and PASTE this):</p>
244<pre><code># A list of our virtual routers
245
246define hostgroup {
247        hostgroup_name  routers
248                alias           Cisco 7200 Routers
249                members         rtr1,rtr2,...
250        }</code></pre>
251<p>Only list the routers you have defined in the &quot;routers.cfg&quot;.</p>
252<p>Save and exit from the file. Verify that everything is OK:</p>
253<pre><code>$sudo nagios3 -v /etc/nagios3/nagios.cfg</code></pre> 254<p>If everything looks good, then restart Nagios</p> 255<pre><code>$ sudo service nagios3 restart</code></pre>
256<h2 id="check-that-http-is-running-on-all-the-classroom-pcs."><span class="header-section-number">5.3</span> 3. Check that http is running on all the classroom PCs.</h2>
257<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>
258<p>If you have questions or are confused please ask an instructor for help.</p>
259</body>
260</html>