| 1 | NAGIOS MONITORING |
|---|
| 2 | ----------------- |
|---|
| 3 | |
|---|
| 4 | On Master server |
|---|
| 5 | |
|---|
| 6 | 1. Go to Nagios working directory |
|---|
| 7 | |
|---|
| 8 | $ cd /usr/local/etc/nagios |
|---|
| 9 | |
|---|
| 10 | 2. Copy Nagios sample files |
|---|
| 11 | |
|---|
| 12 | To do this, make sure you are in Nagios working directory from the first step |
|---|
| 13 | There are Nagios's sample files in the directory, which we need to copy them |
|---|
| 14 | as working copies. The easiest is to become temporarily root, and rename |
|---|
| 15 | the files: |
|---|
| 16 | |
|---|
| 17 | $ sudo -s |
|---|
| 18 | |
|---|
| 19 | You can then copy the commands below: |
|---|
| 20 | |
|---|
| 21 | cp cgi.cfg-sample cgi.cfg |
|---|
| 22 | cp nagios.cfg-sample nagios.cfg |
|---|
| 23 | cp resource.cfg-sample resource.cfg |
|---|
| 24 | cp objects/commands.cfg-sample objects/commands.cfg |
|---|
| 25 | cp objects/contacts.cfg-sample objects/contacts.cfg |
|---|
| 26 | cp objects/localhost.cfg-sample objects/localhost.cfg |
|---|
| 27 | cp objects/templates.cfg-sample objects/templates.cfg |
|---|
| 28 | cp objects/timeperiods.cfg-sample objects/timeperiods.cfg |
|---|
| 29 | |
|---|
| 30 | # exit |
|---|
| 31 | $ |
|---|
| 32 | |
|---|
| 33 | 3. Create monitoring configuration files for DNS Servers |
|---|
| 34 | |
|---|
| 35 | While are you still in Nagios working directory, create a new file for DNS servers monitoring |
|---|
| 36 | |
|---|
| 37 | Change the following below: |
|---|
| 38 | xx: your group number |
|---|
| 39 | yy: group number of your slave server |
|---|
| 40 | MYTLD: your zone name |
|---|
| 41 | |
|---|
| 42 | $ sudo vi objects/dns-servers.cfg |
|---|
| 43 | |
|---|
| 44 | - - - - - - - - - - - - - - - - - cut below - - - - - - - - - - - - - - - |
|---|
| 45 | |
|---|
| 46 | ### Define the host server |
|---|
| 47 | |
|---|
| 48 | define host{ |
|---|
| 49 | use freebsd-server |
|---|
| 50 | host_name master |
|---|
| 51 | alias master |
|---|
| 52 | address 10.10.xx.1 |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | define host{ |
|---|
| 56 | use freebsd-server |
|---|
| 57 | host_name cache |
|---|
| 58 | alias cache |
|---|
| 59 | address 10.10.xx.2 |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | define host{ |
|---|
| 63 | use freebsd-server |
|---|
| 64 | host_name slave |
|---|
| 65 | alias slave |
|---|
| 66 | address 10.10.yy.1 |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | ### Define the group |
|---|
| 70 | |
|---|
| 71 | define hostgroup{ |
|---|
| 72 | hostgroup_name dns-servers |
|---|
| 73 | alias DNS Servers |
|---|
| 74 | members cache,master,slave |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | ### Define Services |
|---|
| 78 | |
|---|
| 79 | define service { |
|---|
| 80 | use generic-service ; Name of service template to use |
|---|
| 81 | hostgroup_name dns-servers |
|---|
| 82 | service_description PING |
|---|
| 83 | check_command check_ping!100.0,20%!500.0,60% |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | define service { |
|---|
| 87 | use generic-service ; Name of service template to use |
|---|
| 88 | hostgroup_name dns-servers |
|---|
| 89 | service_description Check DNS |
|---|
| 90 | check_command check_dns!www.MYTLD |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | - - - - - - - - - - - - - - - - - cut end - - - - - - - - - - - - - - - |
|---|
| 94 | |
|---|
| 95 | 4. Add check_dns service |
|---|
| 96 | |
|---|
| 97 | By default, Nagios doesn't configure check_dns service, we need to add line below into commands.cfg |
|---|
| 98 | |
|---|
| 99 | $ sudo vi objects/commands.cfg |
|---|
| 100 | |
|---|
| 101 | - Place this below the check_nt service check definition: |
|---|
| 102 | |
|---|
| 103 | - - - - - - - - - - - - - - - - - cut below - - - - - - - - - - - - - - - |
|---|
| 104 | |
|---|
| 105 | define command{ |
|---|
| 106 | command_name check_dns |
|---|
| 107 | command_line $USER1$/check_dns -s $HOSTADDRESS$ -H $ARG1$ |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | - - - - - - - - - - - - - - - - - cut end - - - - - - - - - - - - - - - |
|---|
| 111 | |
|---|
| 112 | 5. Enable DNS monitoring group in Nagios configuration files |
|---|
| 113 | |
|---|
| 114 | Now you have DNS Server monitoring files (dns-server.cfg) created. We need to enable on nagios.cfg file for monitoring |
|---|
| 115 | |
|---|
| 116 | $ sudo vi /usr/local/etc/nagios/nagios.cfg |
|---|
| 117 | |
|---|
| 118 | Look for the line "cfg_file=/usr/local/etc/nagios/objects/localhost.cfg" and add below content |
|---|
| 119 | |
|---|
| 120 | - - - - - - - - - - - - - - - - - cut below - - - - - - - - - - - - - - - |
|---|
| 121 | |
|---|
| 122 | # Definition for DNS servers |
|---|
| 123 | cfg_file=/usr/local/etc/nagios/objects/dns-servers.cfg |
|---|
| 124 | |
|---|
| 125 | - - - - - - - - - - - - - - - - - cut end - - - - - - - - - - - - - - - |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | 6. Enable Nagios service |
|---|
| 129 | |
|---|
| 130 | To enable nagios service add the line below in /etc/rc.conf |
|---|
| 131 | |
|---|
| 132 | nagios_enable="YES" |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | 7. Start Nagios service |
|---|
| 136 | |
|---|
| 137 | To start nagios service |
|---|
| 138 | |
|---|
| 139 | $ sudo service nagios start |
|---|
| 140 | |
|---|
| 141 | Nagios should be running right now without any error report. |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | 8. Create Apache password authentication file for Nagios |
|---|
| 145 | |
|---|
| 146 | Nagios required authentication via http to gain admin access to it web interface. |
|---|
| 147 | Let's create the password file |
|---|
| 148 | |
|---|
| 149 | $ sudo -s |
|---|
| 150 | # htpasswd -c /usr/local/etc/apache22/nagios.auth nagiosadmin |
|---|
| 151 | # exit |
|---|
| 152 | $ |
|---|
| 153 | |
|---|
| 154 | Set your desire password (perhaps, use the class password) |
|---|
| 155 | |
|---|
| 156 | Password file is now created |
|---|
| 157 | |
|---|
| 158 | 9. Create Nagios' Apache configuration for web interface access |
|---|
| 159 | |
|---|
| 160 | Go to Apache Includes directory |
|---|
| 161 | |
|---|
| 162 | $ cd /usr/local/etc/apache22/Includes |
|---|
| 163 | |
|---|
| 164 | If there already is a nagios.conf file in the directory, we wil |
|---|
| 165 | remove and rebuild it. Our new configuration is significantly different. |
|---|
| 166 | To do this do: |
|---|
| 167 | |
|---|
| 168 | $ sudo rm nagios.conf |
|---|
| 169 | |
|---|
| 170 | Then edit the file: |
|---|
| 171 | |
|---|
| 172 | $ sudo vi nagios.conf |
|---|
| 173 | |
|---|
| 174 | Add the lines below into the file: |
|---|
| 175 | |
|---|
| 176 | - - - - - - - - - - - - - - - - - cut below - - - - - - - - - - - - - - - |
|---|
| 177 | |
|---|
| 178 | AddType application/x-httpd-php .php |
|---|
| 179 | AddType application/x-httpd-php-source .phps |
|---|
| 180 | |
|---|
| 181 | ScriptAlias /nagios/cgi-bin/ /usr/local/www/nagios/cgi-bin/ |
|---|
| 182 | Alias /nagios/ /usr/local/www/nagios/ |
|---|
| 183 | |
|---|
| 184 | <Directory "/usr/local/www/nagios/cgi-bin"> |
|---|
| 185 | Options ExecCGI |
|---|
| 186 | AllowOverride None |
|---|
| 187 | Order allow,deny |
|---|
| 188 | Allow from all |
|---|
| 189 | AuthName "Nagios Access" |
|---|
| 190 | AuthType Basic |
|---|
| 191 | Require valid-user |
|---|
| 192 | AuthUserFile /usr/local/etc/apache22/nagios.auth |
|---|
| 193 | </Directory> |
|---|
| 194 | |
|---|
| 195 | <Directory "/usr/local/www/nagios"> |
|---|
| 196 | AllowOverride None |
|---|
| 197 | Order allow,deny |
|---|
| 198 | Allow from all |
|---|
| 199 | AuthName "Nagios Access" |
|---|
| 200 | AuthType Basic |
|---|
| 201 | Require valid-user |
|---|
| 202 | AuthUserFile /usr/local/etc/apache22/nagios.auth |
|---|
| 203 | </Directory> |
|---|
| 204 | |
|---|
| 205 | - - - - - - - - - - - - - - - - - cut end - - - - - - - - - - - - - - - |
|---|
| 206 | |
|---|
| 207 | 10. Now, edit the main apache config. |
|---|
| 208 | |
|---|
| 209 | $ sudo vi /usr/local/etc/apache22/httpd.conf |
|---|
| 210 | |
|---|
| 211 | Find the line: |
|---|
| 212 | |
|---|
| 213 | DirectoryIndex index.html |
|---|
| 214 | |
|---|
| 215 | And change it to: |
|---|
| 216 | |
|---|
| 217 | DirectoryIndex index.html index.php |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | 11. Enable and start Apache web service if required, by adding this |
|---|
| 221 | to /etc/rc.conf |
|---|
| 222 | |
|---|
| 223 | $ sudo vi /etc/rc.conf |
|---|
| 224 | |
|---|
| 225 | apache22_enable="YES" |
|---|
| 226 | |
|---|
| 227 | (Save file and exit) |
|---|
| 228 | |
|---|
| 229 | $ sudo service apache22 restart |
|---|
| 230 | |
|---|
| 231 | 12. Access to Nagios web page via http://10.10.xxx.1/nagios/ |
|---|
| 232 | |
|---|
| 233 | You will need to user "nagiosadmin" as the user and the password you |
|---|
| 234 | specified previously using the "htpasswd" command. |
|---|
| 235 | |
|---|
| 236 | Take a looking around the Nagios interface to see what is being |
|---|
| 237 | reported. |
|---|
| 238 | |
|---|