Home 0P3N Blog Building a Linux Monitoring Infrastructure II
Ready to Start Your Career?
Create Free Account
By: Abayomi Ayoola
January 27, 2017

Building a Linux Monitoring Infrastructure II

By: Abayomi Ayoola
January 27, 2017
By: Abayomi Ayoola
January 27, 2017

globe-1015311_1280

Estimated reading time: 2.5 minutes

[Continued from Building a Monitoring Infrastructure I]

Install binaries, init script, sample config files and set permissions on the external command directory.

root@Nagios:~/Downloads/nagios-3.0.5#make installroot@Nagios:~/Downloads/nagios-3.0.5#make install-initroot@Nagios:~/Downloads/nagios-3.0.5#make install-configroot@Nagios:~/Downloads/nagios-3.0.5#make install-commandmode

4. Customize ConfigurationEdit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

root@Nagios:~#emacs /usr/local/nagios/etc/objects/contacts.cfg

By the way, emacs is like notepad in Windows and there are other ones that you can use instead. It depends on your expertise on using them. Other such applications include vim, nano, joe, pico etc

5. Configure the Web InterfaceInstall the Nagios web config file in the Apache conf.d directory.root@Nagios:~/Downloads/nagios-3.0.5# make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface.root@Nagios:~/Downloads/nagios-3.0.5#make htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache to make the new settings take effect.root@Nagios:~/Downloads/nagios-3.0.5# /etc/init.d/apache2 reload

6. Compile and Install the Nagios PluginsExtract the Nagios plugins source code tarball.root@Nagios:~#cd Downloadsroot@Nagios:~#tar xzf nagios-plugins-1.4.11.tar.gzroot@Nagios:~#cd nagios-plugins-1.4.11

Compile and install the plugins.root@Nagios:~/Downloads/nagios-plugins-1.4.11#./configure —with-nagios-user=nagios —with-nagios-group=nagiosroot@Nagios:~/Downloads/nagios-plugins-1.4.11#makeroot@Nagios:~/Downloads/nagios-plugins-1.4.11#make install

7. Start NagiosConfigure Nagios to automatically start when the system boots.root@Nagios:~/Downloads# ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the sample Nagios configuration files.root@Nagios:~# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start Nagios.root@Nagios:~#/etc/init.d/nagios start

8. Login to the Web InterfaceYou should now be able to access the Nagios web interface at the URL below.http://localhost/nagios/

NOTIFICATIONSIf you want to receive email notifications for Nagios alerts, you need to install the mailx (Postfix) package.

Any other Mail Transfer Agent (MTA) can be used to send email notifications. Postfix was used here because it’s much more easier to configure for use.

aayoola@Nagios:~$ sudo apt-get install mailx

You’ll have to edit the Nagios email notification commands found in /usr/local/nagios/etc/objects/commands.cfg and change any ‘/bin/mail’ references to ‘/usr/bin/mailx’. Once you do that you’ll need to restart Nagios to make the configuration changes live.

aayoola@Nagios:~$ sudo /etc/init.d/nagios restart

INSTALL & CONFIGURE POSTFIX

To install postfix, run the following command:aayoola@Nagios:~$ sudo apt-get install postfix

To configure postfix, run the following command:aayoola@Nagios:~$ sudo dpkg-reconfigure postfix

The file /etc/postfix/main.cf should look like this

myhostname = Nagios.Linuxlab.comalias_maps = hash:/etc/aliasesalias_database = hash:/etc/aliasesmyorigin = /etc/mailnamemydestination = Nagios.Linuxlab.com, localhost.Linuxlab.com, localhostrelayhost = miranda.dc.turkuamk.fimynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128mailbox_size_limit = 0recipient_delimiter = +inet_interfaces = allinet_protocols = ipv4

The relay host was what I changed as the host miranda.dc.turkuamk.fi is a relay server within a known network and so you might want to set up one for yourself in order that notification gets into your inbox.

Now the postfix initial configuration is complete. Run the following command to start postfix daemon:

aayoola@Nagios:~$ sudo /etc/init.d/postfix start

Object Configuration OverviewObjects are all the elements that are involved in the monitoring and notification logic and can be found in /usr/local/nagios/etc/objects.

Types of objects include:ServicesService GroupsHostsHost GroupsContactsContact GroupsCommandsTime PeriodsNotification EscalationsNotification and Execution Dependencies

Main Configuration FileAt installation a sample main configuration file /usr/local/nagios/etc/nagios.cfg is installed. The main configuration file is usually named nagios.cfg and located in the /usr/local/nagios/etc/ directory.

Request Demo

Build your Cybersecurity or IT Career

Accelerate in your role, earn new certifications, and develop cutting-edge skills using the fastest growing catalog in the industry