Categories Menu

How to install the Free Nagios Core and use it to monitor your Windows Servers using CentOS 7

 

  1. Install CentOS 7.
  2. During the course of the installation, you will come across with the configuration screen. In this stage you will get to do the following:
  • Choose the drive, delete all the existing partitions if necessary and reclaim the drive by creating the partitions required by CentOS automatically
  • Choose what type of installation you would pick. For this particular exercise, we will pick the server with the XDE or GNOME GUI so we can play around with some GUI settings.
  • Turn on the network interface
  • Set the root password
  1. Proceed with the installation and let it complete. Upon the completion of the installation, you will be asked to define a non-root account with root privileges.  Define one.
  1. Set a static IP to the CentOS server.
  2. Install the latest updates by entering this command in a terminal

sudo yum update

* Almost every time you invoke the command “sudo” you will be asked for the password of the non-root account that you created in the previous step.

  1. Now we have to install the LAMP, or in this case just the AMP part since Linux for the L in LAMP has already been installed.  CentOS is a linux flavor.
  2. Start by installing Apache. To do it, invoke the command

sudo yum install httpd

  1. Start Apache and test if it is working by invoking the command

sudo service httpd start
sudo service mysqld start

Then open a browser on a client computer, enter the static IP address of the CentOS server on the browser’s address field.   You should see a response with the message “It Works” on the resulting page.

  1. Install MySQL/MariaDB by invoking the command

sudo yum install mysql-server

During the course of the MySQL installation, you will be prompted with several questions.  Just respond with a “Yes” on all of them.

Once the installation is done, you may set the root password by

sudo /usr/bin/mysql_secure_installation

Initially, there is no password so you will just have to press the enter key on the keyboard.  Afterwards, you will be given the chance to enter your own password.

  1. On the following prompts, just respond “Yes” until the whole setup completes.
  1. Once it is done, you will see the message “All done! If you’ve completed all of the above steps, your MySQL installation should now be secure.

Thanks for using MySQL!”

  1. Now install PHP by

sudo yum install php php-mysql

Again just answer “Yes” to all following prompts.

  1. Set Apache and MySQL to run automatically during bootup

sudo chkconfig httpd on
sudo chkconfig mysqld on

  1. Test PHP by creating the following file

sudo nano /var/www/html/info.php

and adding the following lines to it

<?php
phpinfo();
?>

Save the file and exit.

  1. Restart Apache by

sudo service httpd restart

  1. Test PHP by using a browser in a client station. On the browser’s address field, enter the server static IP address followed by “info.php” (i.e., http://192.168.100.100/info.php.
  1. Install the   perquisite packages

sudo yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd unzip

  1. Create the Nagios User and Group

sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios

  1. Install Nagios Core

The package that I got from the Nagios download site is 4.1.1, so it goes

cd ~
curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz

  1. Extract the package

tar xvf nagios-*.tar.gz

  1. Change to the newly created directory from tar and configure Nagios the package using

cd nagios-*
./configure –with-command-group=nagcmd

  1. Compile Nagios

make all

  1. Install Nagios

sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo make install-webconf

  1. Install Nagios Plugins

The plugin package that I got from the Nagios download site is 2.1.1, so it goes

cd ~
curl -L -O http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

  1. Extract the Nagios plugin package

tar xvf nagios-plugins-*.tar.gz

  1. Change to the newly created directory for the plugins from tar and configure the Nagios plugins package using

cd nagios-plugins-*
./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl

  1. Compile the plugin package

make

  1. Install the Nagios plugins

sudo make install

  1. Configure Nagios to monitor Windows Machines

sudo nano /usr/local/nagios/etc/nagios.cfg

Remove the leading pound (#) sign from the following line in the main configuration file:

#cfg_file=/usr/local/nagios/etc/objects/windows.cfg to cfg_file=/usr/local/nagios/etc/objects/windows.cfg

  1. Configure email alerts

sudo nano /usr/local/nagios/etc/objects/contacts.cfg

Find the email line, and replace its value with your own email address:

email               admin@contoso.com      ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

  1. Configure Apache for Nagios using a newly introduced user called “nagiosadmin”

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enter the password.  This will be the user that you will enter when going to Nagios

  1. Restart Nagios and Apache

sudo systemctl start nagios.service
sudo systemctl restart httpd.service

  1. To enable nagios to start during server boot

sudo chkconfig nagios on

  1. Install NSClient++ on the Windows server

Choose the TYPICAL install method.  During the course of the installation, you will be asked to specify the IP address of the Nagios server.  You do not need to specify a password unless the server is configured to require it.  Check the 1st 3 check boxes – Enable Common Check Plugins, Enable NSClient Server (check_nt) and Enable NRPE Server (check_nrpe)

For this particular excercise, we will just be using check_nt for monitoring.  But nonetheless, you have to check all those 3 checkboxes for future use.

  1. Configure Nagios to include entries for that Windows server

sudo nano /usr/local/nagios/etc/objects/windows.cfg

And modify the following lines

define host{
use                         windows-server               ; Inherit default values from a Windows server template (make sure you keep this line!)
host_name           mywinserver
alias                       My Windows Server
address                 192.168.100.100
}

Where host_name should be replaced by the host name of the windows server and the address should be replaced by the (static) IP of the Windows server.

  1. To monitor resources and services, just replace the host_name of the following lines by the host name of the Windows server.

define service{
use                                         generic-service
host_name                           mywinserver
service_description            NSClient++ Version
check_command                check_nt!CLIENTVERSION
}

define service{
use                                         generic-service
host_name                           mywinserver
service_description            Uptime
check_command                check_nt!UPTIME
}

define service{
use                                         generic-service
host_name                           mywinserver
service_description            CPU Load
check_command                check_nt!CPULOAD!-l 5,80,90
}

define service{
use                                         generic-service
host_name                           mywinserver
service_description            Memory Usage
check_command                check_nt!MEMUSE!-w 80 -c 90
}

define service{
use                                         generic-service
host_name                           mywinserver
service_description            C:\ Drive Space
check_command                check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}

define service{
use                                         generic-service
host_name                           mywinserver
service_description            W3SVC
check_command                check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}

define service{
use                                         generic-service
host_name                           mywinserver
service_description            Explorer
check_command                check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}

  1. Restart Nagios and Apache

sudo systemctl start nagios.service
sudo systemctl restart httpd.service

  1. On the Windows server, make sure the firewall isn’t blocking access to ICMP which Nagios uses. Enter the following line in an elevated windows command window.

netsh firewall set icmp 8

  1. Test Nagios by going to http://<NAGIOS SERVER IP ADDRESS>/Nagios. Enter the password.  Check if the host is being monitored.

NEXT STOP….  CONFIGURE NRPE WHICH HAS MORE FUNCTIONALITY IN MONITORING SERVERS AND DEVICES

Take me back to the Tech Tips list..

Post a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.