In this post, you will learn how to install and configure Nagios on a Centos7 server. Nagios is a complex monitoring system that lets you monitor multiple servers.
Nagios is configured through the command line. To make the task easier, you will install NagiosQL, which lets you configure Nagios through the web.
Install LAMP
This article explains how to do it in detail. Here are the necessary commands:
# yum install wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp unzip
# systemctl start httpd.service
# systemctl enable httpd.service
# yum install mariadb-server mariadb
# systemctl start mariadb.service
# systemctl enable mariadb.service
# mysql_secure_installation
# yum install epel-release
# yum install php php-mysql php-cli php-pear php-develInstall Nagios
At the time of writing this article, the stable version of Nagios is 4.3.4. Please visit the Nagios website to check for a newer version and install the latest version.
To use Nagios, you will need to create a user and add it to the apache group:
# useradd nagios
# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagios,nagcmd apacheYou can now proceed to download and install Nagios:
# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz
# tar -xzvf nagios-4*
# cd nagios-*
# ./configure --with-command-group=nagcmd
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf
# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminIn this last step, you will have been prompted to assign a password to the “nagiosadmin” user, which you will use to access Nagios through the web.
Install Nagios plugins
Nagios requires plugins to perform service checks. At the time of writing this article, the latest version of the plugins is 2.2.1. Please visit the Nagios website to check for a newer version and install the latest version.
To install the Nagios plugins, run:
# cd ..
# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
# tar -xzvf nagios-plugins*
# cd nagios-plugins*
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make installNow that Nagios is installed, enable and start it:
# systemctl restart httpd
# systemctl enable nagios
# systemctl start nagiosNagiosQL installation
NagiosQL is a web interface that lets you configure Nagios without having to edit files over SSH.
# cd ..
# wget https://netcologne.dl.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.3.0/nagiosql_330.tar.gz
# tar -xzvf nagiosql_330.tar.gz
# chmod 777 nagiosql33/config
# mv nagiosql33 /usr/local/nagios/share/
# mkdir /etc/nagiosql
# chmod 777 /etc/nagiosqlUpdate the PHP configuration to set the correct time zone:
# vi /etc/php.inidate.timezone = “Europe/Madrid# systemctl restart httpdNow create a database, user, and password to use NagiosQL:
MariaDB [(none)]> create database nagios character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on nagios.* to nagios@localhost identified by 'nagiostest';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit;
ByeNagiosQL configuration
Now that Nagios and NagiosQL are installed, proceed to configure NagiosQL through the web interface. To do this, open http://IP-Publica/nagios/nagiosql33/install/index.php in your browser and fill in the requested information. Here are some screenshots of the process:
Configuring NagiosQL with Nagios
Now that you have NagiosQL, it is time to make it work with Nagios. To do this, edit:
# vi /usr/local/nagios/etc/nagios.cfgComment out all cfg_file entries up to routers and add the ones shown below:
# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.
# You can specify individual object config files as shown below:
#cfg_file=/usr/local/nagios/etc/objects/commands.cfg
#cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
#cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
#cfg_file=/usr/local/nagios/etc/objects/templates.cfg
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
# Definitions for monitoring a Windows machine
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg
# Definitions for monitoring a router/switch
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg
# Definitions for monitoring a network printer
#cfg_file=/usr/local/nagios/etc/objects/printer.cfg
# You can also tell Nagios to process all config files (with a .cfg
# extension) in a particular directory by using the cfg_dir
# directive as shown below:
#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
cfg_file=/etc/nagiosql/contacttemplates.cfg
cfg_file=/etc/nagiosql/contactgroups.cfg
cfg_file=/etc/nagiosql/contacts.cfg
cfg_file=/etc/nagiosql/timeperiods.cfg
cfg_file=/etc/nagiosql/commands.cfg
cfg_file=/etc/nagiosql/hostgroups.cfg
cfg_file=/etc/nagiosql/servicegroups.cfg
cfg_dir=/etc/nagiosql/hosts
cfg_dir=/etc/nagiosql/services
cfg_file=/etc/nagiosql/hosttemplates.cfg
cfg_file=/etc/nagiosql/servicetemplates.cfg
cfg_file=/etc/nagiosql/servicedependencies.cfg
cfg_file=/etc/nagiosql/serviceescalations.cfg
cfg_file=/etc/nagiosql/hostdependencies.cfg
cfg_file=/etc/nagiosql/hostescalations.cfg
cfg_file=/etc/nagiosql/hostextinfo.cfg
cfg_file=/etc/nagiosql/serviceextinfo.cfgNow open the NagiosQL web interface, go to “Administración > Config targets”, and edit localhost. Then go to “Herramientas > Control Nagios” and perform all the checks. Here are screenshots of this process.
You can now start using Nagios by configuring the servers from NagiosQL.
Remember, if you have questions about this or any other issue related to your servers on Clouding, feel free to write to soporte@clouding.io We are here for whatever you need. Just ask us!