Learn how to install Nagios on CentOS 7 with this step-by-step guide. Set up this powerful monitoring tool to keep your systems and networks running smoothly. #centlinux #linux #nagios
Table of Contents
What is Nagios?
Nagios Core is a free and open source software application that provides monitoring and alerting services for servers, switches, applications and services. It monitors targets (i.e. hosts and services) and alerts users when something go wrong and alerts them a second time when the problem has been resolved. Nagios Core is primary application and monitoring and alerting engine, around that hundred of Nagios Projects are built.
In this article, we will install Nagios on CentOS 7. But before moving forward, it is required to have basic concepts of Nagios Core 4. Therefore, it is highly recommended that you should have Learning Nagios – Third Edition (PAID LINK). It will be really helpful for you during your Nagios journey.
System Specification
We have configured a CentOS 7 virtual machine with following specifications:
- Operating System – CentOS 7.6
- Nagios Core – 4.4.2
- Hostname – nagios-01.example.com
- IP Address: – 192.168.116.130/24
Install Nagios on CentOS 7
Connect to nagios-01.example.com using ssh.
Install prerequisite packages using yum command.
# yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
Currently, Nagios Core does not compliance with SELinux, therefore we have to disable SELinux.
# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config # setenforce 0
Create a directory for downloading Nagios Core source.
# mkdir setup
Download Nagios Core from https://www.nagios.org/downloads/nagios-core/.
# cd ~/setup # wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz --2018-12-23 10:35:22-- https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz Resolving assets.nagios.com (assets.nagios.com)... 72.14.181.71, 2600:3c00::f03c:91ff:fedf:b821 Connecting to assets.nagios.com (assets.nagios.com)|72.14.181.71|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 11301454 (11M) [application/x-gzip] Saving to: ânagios-4.4.2.tar.gzâ 100%[======================================>] 11,301,454 1.16MB/s in 10s 2018-12-23 10:35:34 (1.03 MB/s) - ânagios-4.4.2.tar.gzâ saved [11301454/11301454]
Extract downloaded source of Nagios Core.
# tar xf nagios-4.4.2.tar.gz
Compile and install Nagios Core from extracted source.
# cd ~/setup/nagios-4.4.2 # ./configure config.status: creating t/Makefile config.status: creating t-tap/Makefile config.status: creating include/config.h config.status: creating lib/snprintf.h config.status: creating lib/iobroker.h Creating sample config files in sample-config/ ... *** Configuration summary for nagios 4.4.2 2018-08-16 ***: General Options: ------------------------- Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagios Event Broker: yes Install ${prefix}: /usr/local/nagios Install ${includedir}: /usr/local/nagios/include/nagios Lock file: /run/nagios.lock Check result directory: /usr/local/nagios/var/spool/checkresults Init directory: /lib/systemd/system Apache conf.d directory: /etc/httpd/conf.d Mail program: /usr/sbin/sendmail Host OS: linux-gnu IOBroker Method: epoll Web Interface Options: ------------------------ HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): Review the options above for accuracy. If they look okay, type 'make all' to compile the main program and CGIs. # make all ... make[1]: Entering directory `/root/setup/nagios-4.4.2/worker' cd ./ping && make all make[2]: Entering directory `/root/setup/nagios-4.4.2/worker/ping' gcc -I.. -I ../../include -I ../.. -g -O2 -DHAVE_CONFIG_H -o worker-ping worker-ping.c -L ../../lib -l nagios make[2]: Leaving directory `/root/setup/nagios-4.4.2/worker/ping' make[1]: Leaving directory `/root/setup/nagios-4.4.2/worker' *** Compile finished *** If the main program and CGIs compiled without any errors, you can continue with testing or installing Nagios as follows (type 'make' without any arguments for a list of all possible options): make test - This runs the test suite make install - This installs the main program, CGIs, and HTML files make install-init - This installs the init script in /lib/systemd/system make install-daemoninit - This will initialize the init script in /lib/systemd/system make install-groups-users - This adds the users and groups if they do not exist make install-commandmode - This installs and configures permissions on the directory for holding the external command file make install-config - This installs *SAMPLE* config files in /usr/local/nagios/etc You'll have to modify these sample files before you can use Nagios. Read the HTML documentation for more info on doing this. Pay particular attention to the docs on object configuration files, as they determine what/how things get monitored! make install-webconf - This installs the Apache config file for the Nagios web interface make install-exfoliation - This installs the Exfoliation theme for the Nagios web interface make install-classicui - This installs the classic theme for the Nagios web interface *** Support Notes ******************************************* If you have questions about configuring or running Nagios, please make sure that you: - Look at the sample config files - Read the documentation on the Nagios Library at:Nagios Librarybefore you post a question to one of the mailing lists. Also make sure to include pertinent information that could help others help you. This might include: - What version of Nagios you are using - What version of the plugins you are using - Relevant snippets from your config files - Relevant error messages from the Nagios log file For more information on obtaining support for Nagios, visit:Nagios Support Home************************************************************* Enjoy.
Create OS user and groups for Nagios Core.
# make install-groups-users groupadd -r nagios useradd -g nagios nagios # usermod -a -G nagios apache
Install Nagios on CentOS 7 now.
# make install /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/spool/checkresults chmod g+s /usr/local/nagios/var/spool/checkresults *** Main program, CGIs and HTML files installed *** You can continue with installing Nagios as follows (type 'make' without any arguments for a list of all possible options): make install-init - This installs the init script in /lib/systemd/system make install-commandmode - This installs and configures permissions on the directory for holding the external command file make install-config - This installs sample config files in /usr/local/nagios/etc make[1]: Leaving directory `/root/setup/nagios-4.4.2'
Install Nagios Core service.
# make install-daemoninit /usr/bin/install -c -m 755 -d -o root -g root /lib/systemd/system /usr/bin/install -c -m 755 -o root -g root startup/default-service /lib/systemd/system/nagios.service Created symlink from /etc/systemd/system/multi-user.target.wants/nagios.service to /usr/lib/systemd/system/nagios.service. *** Init script installed ***
Enable httpd service.
# systemctl enable httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Install and configure external command file.
# make install-commandmode /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw chmod g+s /usr/local/nagios/var/rw *** External command directory configured ***
Install Sample configuration files for Nagios Core.
# make install-config /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg *** Config files installed *** Remember, these are *SAMPLE* config files. You'll need to read the documentation for more information on how to actually define services, hosts, etc. to fit your particular needs.
Add Nagios Core configurations to Apache Web Server.
# make install-webconf /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf if [ 0 -eq 1 ]; then ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; fi *** Nagios/Apache conf file installed ***
Configure Linux Firewall
Configure Linux Firewall to allow http service.
# firewall-cmd --permanent --add-service=http success # firewall-cmd --reload success
Setup Basic HTTP Authentication
Nagios does not have integrated user authentication, therefore, we have to use Basic HTTP authentication for this purpose.
Create an admin user for Nagios Core Web UI.
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin
Start httpd & nagios services.
# systemctl start httpd.service # systemctl start nagios.service Warning: nagios.service changed on disk. Run 'systemctl daemon-reload' to reload units. # systemctl daemon-reload
Access Nagios Web Interface
Browse URL http://192.168.116.130/nagios to connect with Nagios Core Web UI.
Login using nagiosadmin user.
Go to services page.
You can see that all the services are unavailable. It is because we don’t have installed Nagios Plugins on our CentOS 7 server.
Install Nagios Plugins on CentOS 7
Install prerequisite packages for Nagios Plugins using yum command.
# yum install -y perl-Net-SNMP gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release
Download Nagios Plugins from https://www.nagios.org/downloads/nagios-plugins/.
# cd ~/setup # wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz --2018-12-23 10:37:19-- https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz Resolving nagios-plugins.org (nagios-plugins.org)... 72.14.186.43 Connecting to nagios-plugins.org (nagios-plugins.org)|72.14.186.43|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2728818 (2.6M) [application/x-gzip] Saving to: ânagios-plugins-2.2.1.tar.gzâ 100%[======================================>] 2,728,818 813KB/s in 3.3s 2018-12-23 10:37:24 (813 KB/s) - ânagios-plugins-2.2.1.tar.gzâ saved [2728818/2728818]
Extract downloaded source of Nagios Plugins.
# cd ~/setup # tar xf nagios-plugins-2.2.1.tar.gz
Compile Nagios Plugins source.
# cd ~/setup/nagios-plugins-2.2.1 # ./configure ... config.status: executing libtool commands config.status: executing po-directories commands config.status: creating po/POTFILES config.status: creating po/Makefile
Install Nagios Plugins by executing following command.
# make ... make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/root/setup/nagios-plugins-2.2.1/po' make[2]: Entering directory `/root/setup/nagios-plugins-2.2.1' make[2]: Leaving directory `/root/setup/nagios-plugins-2.2.1' make[1]: Leaving directory `/root/setup/nagios-plugins-2.2.1' # make install ... make[2]: Entering directory `/root/setup/nagios-plugins-2.2.1' make[2]: Nothing to be done for `install-exec-am'. make[2]: Nothing to be done for `install-data-am'. make[2]: Leaving directory `/root/setup/nagios-plugins-2.2.1' make[1]: Leaving directory `/root/setup/nagios-plugins-2.2.1'
Go to Nagios Web UI and open services page.
You can see that, now all the services are in OK state now. (Note: Keep patience, Nagios Core takes a while to collect data for each service)
Recommended Training for You: Network Monitoring Using Nagios
Final Thoughts
Installing Nagios on CentOS 7 ensures you have a robust monitoring solution for your systems and networks. By following this guide, you should now have Nagios up and running efficiently.
If you need further assistance or professional support with your Nagios installation or other technical tasks, feel free to check out my services on Fiverr. I offer expert solutions to meet your monitoring and IT needs.
Hire me on Fiverr for professional help and quality service.
I Like your work highly appreciate
Thanks
Thank you.
Hi Ahmer,
Thank you for the configuration. I wanted to monitor backup job status from veritas backup exec but I am getting unknown error which is "unknown command check_backupexec".
Details of Nagios: Nagios 4.4.2 in CentOS 7. Veritas backup verion 20, 2018.
Hi,
Thanks for liking this article.
Make sure you have defined the command check_backupexec in command.cfg file.
It looks like you are using BackupExec plugin. Please refer to BackupExec – Nagios Exchange for complete configuration.
Hi Ahmer,
I am faceing the following issue while following your blog:
systemctl start nagios.service
Failed to start nagios.service: Unit not found.
Can you please guide. How to start nagios service.
It looks like nagios service is not correctly installed.
Please ensure that you have installed nagios daemon using (as mentioned in above article).
# make install-daemoninit
how to configure snmp for nagios to monitor hard disk, cpu and etc.
There are some templates available in Nagios default configurations for capturing SNMP traps from network devices. Just configure SNMP traps on that device and configure a service on you Nagios Core server to capture that SNMP trap.
Hi Ahmer,
Brilliant peace thank you for that!
Somehow follwing your instructions i must have missed a step, because i am able to start en reload the nagios service and i am also able te see the test appache webpage, but
When i put in the ipaddress/nagios into the url of my webbrowser it can't find anything 🙁
The webpage cannot be found
Could you please guide my into the right direction of the step i might have missed?
thanks you!
Hi, Thanks for appreciating my work.
– For Nagios Service, use following command to verify and troubleshoot errors in Nagios configurations.
– For Apache Service, refer to /var/log/messages for any possible errors.
how to install ndoutil on nagios ?
Hi, I will add an article on this topic very soon.
Your required article is available at Install NDOUtils for Nagios Core on CentOS 7.
Can I add China skyline gateway for monitoring in nagios ???
If yes how can I add ?
Yes, you can.
You have to enable SNMP Traps, and allow Nagios Server to access the router SNMP traps.
Thanks or the reply.
Can you guide me through ???
Sure.
thanks you ,
i have a question please , i wan't to add supervisor can you show me what i should i do ?
Nagios Core uses HTTP basic authentication and Nagios Core's default password file is /usr/local/nagios/etc/htpasswd.users.
You can use htpasswd command to add a supervisor user therein.
Thanks you MR Ahmed,
What about NRPE,apache, postgress ?
I want to connect Nagios with server in my vmwork .
Hi, NRPE installation is already mentioned here.
You need to create services in Nagios to monitor services like Apache, Postgres, etc.
If you are working on a DIY strategy than, I suggest you to please read Learning Nagios – Third Edition.
Thanks a lot MR Ahmer.
pls provide the proper steps to install NSclient in windows
Hi Ahmer,
can u help me to configure the SMTP for email notifications
Sure. Please discuss it on our Facebook Page.
You can find the required information here.
Hi Ahmer,
Can you share the post for Naemon thruk installation and configurationd
Hi, I didn't work on it. But consider your request and will write on it soon.