Hoe Nagios te installeren in RHEL, Rocky en AlmaLinux
Nagios is een geweldige Open Source-monitoringtool, die een uitgebreidere monitoringomgeving biedt waarmee u altijd al uw machines/netwerken in de gaten kunt houden, of u zich nu in uw datacenter bevindt of gewoon uw kleine laboratoria.
Met Nagios kunt u uw externe hosts en hun services op afstand monitoren in één enkel venster. Het toont waarschuwingen en geeft aan als er iets misgaat op uw servers, wat ons uiteindelijk helpt sommige problemen op te sporen voordat ze zich voordoen. Het helpt ons downtime en bedrijfsverliezen te verminderen.
Onlangs heeft Nagios de nieuwste versie Nagios Core 4.4.9 en de nieuwste stabiele release van Nagios plugins 2.3.3 uitgebracht op 4 oktober 2022 .
Dit artikel is bedoeld om u eenvoudige instructies te geven over het installeren en configureren van de nieuwste versie van Nagios Core vanaf de broncode (tarball) op RHEL en op RHEL gebaseerde distributies zoals CentOS Stream, Rocky Linux, AlmaLinux, en Fedora.
Binnen 30 minuten houdt u uw lokale machine in de gaten, geen geavanceerde installatieprocedure, alleen een basisinstallatie die 100% werkt op de meeste hedendaagse Linux-servers.
Let op: de hier getoonde installatie-instructies zijn geschreven op basis van de RHEL 9.0 Linux-distributie.
Nagios Core en Nagios Plugin installeren onder Linux
Als u deze instructies correct opvolgt, krijgt u de volgende informatie.
- Nagios en zijn plug-ins worden geïnstalleerd in de map /usr/local/nagios.
- Nagios wordt geconfigureerd om een aantal services van uw lokale machine te controleren (Schijfgebruik, CPU-belasting, Huidige gebruikers, Totale processen, enz.)
- De webinterface van Nagios zal beschikbaar zijn op http://localhost/nagios
Stap 1: Installeer Apache- en PHP-pakketten
We moeten Apache, PHP en enkele bibliotheken zoals gcc, glibc, glibc-common installeren , en GD bibliotheken en hun ontwikkelingsbibliotheken voordat Nagios met de broncode wordt geïnstalleerd. En om dit te doen, kunnen we het yum-pakketinstallatieprogramma gebruiken.
yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp
Stap 2: Maak een Nagios-gebruiker en -groep
Maak een nieuwe nagios gebruiker aan met behulp van de opdracht useradd en het nagcmd groepsaccount en stel een wachtwoord in.
[root@tecmint]# useradd nagios
[root@tecmint]# groupadd nagcmd
Voeg vervolgens zowel de nagios gebruiker als de apache gebruiker toe aan de nagcmd groep met behulp van het usermod commando.
[root@tecmint]# usermod -G nagcmd nagios
[root@tecmint]# usermod -G nagcmd apache
Stap 3: Download Nagios Core en Nagios Plugin
Maak een map voor uw Nagios-installatie en alle toekomstige downloads.
[root@tecmint]# mkdir /root/nagios
[root@tecmint]# cd /root/nagios
Download nu de nieuwste Nagios Core- en Nagios Plugins-pakketten met de opdracht wget.
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.9.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
Stap 4: Pak de Nagios Core- en Nagios-plug-ins uit
We moeten gedownloade pakketten als volgt uitpakken met de tar-opdracht.
tar -xf nagios-4.4.9.tar.gz
tar -xf nagios-plugins-2.3.3.tar.gz
Wanneer u deze tarballs uitpakt, verschijnen er twee nieuwe mappen in die map.
ls -l
total 13804
drwxrwxr-x 21 root root 4096 Nov 17 02:22 nagios-4.4.9
-rw-r--r-- 1 root root 11339450 Nov 17 03:08 nagios-4.4.9.tar.gz
drwxr-xr-x 15 root root 4096 Mar 11 2020 nagios-plugins-2.3.3
-rw-r--r-- 1 root root 2782610 Mar 11 2020 nagios-plugins-2.3.3.tar.gz
Stap 5: Nagios Core installeren en configureren
Nu gaan we eerst Nagios Core configureren en om dit te doen moeten we naar de map Nagios gaan en het configuratiebestand uitvoeren. Als alles goed gaat, wordt de uitvoer weergegeven in het einde als voorbeelduitvoer.
cd nagios-4.4.9/
./configure --with-command-group=nagcmd
Creating sample config files in sample-config/ ...
*** Configuration summary for nagios 4.4.9 2022-11-16 ***:
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: /run/nagios.lock
Check the result directory: /usr/local/nagios/var/spool/checkresults
Init directory: /lib/systemd/system
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /usr/bin/mail
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.
Na het configureren moeten we alle binaire bestanden compileren en installeren met de opdrachten make all en make install. zal alle benodigde bibliotheken op uw machine installeren en kunnen we verder gaan.
make all
make install
*** 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/nagios/nagios-4.4.9'
Met de volgende opdracht worden de init-scripts voor Nagios geïnstalleerd.
make install-init
Om Nagios vanaf de opdrachtregel te laten werken, moeten we command-mode installeren.
make install-commandmode
Installeer vervolgens voorbeeld-Nagios-bestanden en voer de volgende opdracht uit.
make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/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.
Stap 6: Nagios-configuratie aanpassen
Open het bestand “contacts.cfg” met de editor van uw keuze en stel het e-mailadres dat is gekoppeld aan de contactdefinitie van nagiosadmin in op het ontvangen van e-mailwaarschuwingen.
vi /usr/local/nagios/etc/objects/contacts.cfg
###############################################################################
#
CONTACTS
#
###############################################################################
Just one contact defined by default - the Nagios admin (that's you)
This contact definition inherits a lot of default values from the
'generic-contact' template which is defined elsewhere.
define contact {
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email [email ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
Stap 7: Installeer en configureer de webinterface voor Nagios
We zijn klaar met alle configuraties in de backend, nu zullen we de webinterface voor Nagios configureren met de volgende opdracht. Met het onderstaande commando wordt de webinterface voor Nagios geconfigureerd en wordt er een webbeheerder aangemaakt “nagiosadmin”.
make install-webconf
In deze stap maken we een wachtwoord aan voor “nagiosadmin”. Geef na het uitvoeren van deze opdracht een wachtwoord tweemaal op en bewaar dit, want dit wachtwoord wordt gebruikt wanneer u inlogt op de Nagios-webinterface.
htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
Start Apache opnieuw om de nieuwe instellingen van kracht te laten worden.
systemctl restart httpd
Stap 8: Compileer en installeer de Nagios-plug-in
ga daarheen en configureer en installeer het zoals hieronder aangegeven.
cd /root/nagios
cd nagios-plugins-2.3.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
Stap 9: Controleer de Nagios-configuratiebestanden
Nu zijn we allemaal klaar met de Nagios-configuratie en het is tijd om dit te verifiëren. Voer hiervoor de volgende opdracht in. Als alles soepel verloopt, zal het verschijnen zoals in de onderstaande uitvoer.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.4.9
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2022-11-16
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
Stap 10: Voeg Nagios Services toe aan het opstarten van het systeem
Om Nagios te laten werken bij opnieuw opstarten, moeten we nagios en httpd inschakelen bij het opstarten van het systeem met behulp van de systemctl-opdracht.
systemctl enable nagios
systemctl enable httpd
Start vervolgens Nagios opnieuw op om de nieuwe instellingen van kracht te laten worden.
systemctl restart nagios
Stap 11: Nagios Web toestaan in Firewall
Om toegang te krijgen tot de Nagios-webinterface, moet u de Apache-poorten openen door de volgende opdrachten uit te voeren:
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
Stap 12: Meld u aan bij de Nagios-webinterface
Uw Nagios is klaar voor gebruik. Open deze in uw browser met “http://Uw-server-IP-adres/nagios” of “http://FQDN/nagios ” en geef de gebruikersnaam “nagiosadmin ” en wachtwoord op.
Nagios-webdashboard
Hostweergave
Nagios-overzicht
Diensten bekijken
Procesweergave
Gefeliciteerd! U heeft Nagios en de Plug-ins met succes geïnstalleerd en geconfigureerd. U bent zojuist begonnen aan uw reis naar monitoring.
Nagios 3.x upgraden naar Nagios Core 4.x
Als u al een oudere versie van Nagios gebruikt, kunt u deze op elk gewenst moment upgraden. Om dit te doen, hoeft u alleen maar het nieuwste nagios-bron-tar-archief te downloaden en te configureren zoals hieronder weergegeven.
systemctl stop nagios
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.9.tar.gz
tar -zxvf nagios-4.4.9.tar.gz
cd nagios-4.4.9
./configure
make all
make install
systemctl start nagios
Conclusie
Dat was het voor nu. In mijn komende artikelen zal ik je laten zien hoe je Linux, Windows, Printers, Switches, <en Apparaten naar de Nagios-bewakingsserver.
Als u problemen ondervindt tijdens de installatie, neem dan contact met ons op via opmerkingen. Blijf tot die tijd op de hoogte en verbonden met Tecmint en vergeet niet ons te Liken en Delen om ons te verspreiden.
Lees ook:
- Hoe Linux Host toe te voegen aan Nagios Monitoring Server
- Hoe Windows Host toe te voegen aan Nagios Monitoring Server