Icinga 2 Monitoring Tool installeren op CentOS 8
Monitoring is een van de belangrijkste onderdelen van de server infrastructuur en het datacentrum. Het helpt je problemen op te sporen die zich op je servers voordoen, zodat je die problemen sneller kunt oplossen. Er zijn enkele open-source bewakingsprogramma’s beschikbaar, en een van de populairste is‘Icinga 2‘.
Icinga is ontstaan als een vork van het populaire Nagios bewakingsprogramma en is nu van de grond af herschreven in C++. Als vork van het Nagios project heeft Icinga extra gereedschappen en mogelijkheden gekregen, waaronder de icinga director, icinga modules, en icinga plugins. Ook heeft het ondersteuning voor gedistribueerde monitoring, waarmee je meerdere Icinga instances vanaf één dashboard kunt beheren.
In deze handleiding laten we je stap-voor-stap zien hoe je Icinga2 met Apache2 en MariaDB op CentOS 8 server installeert en configureert.
Vereisten
- Een CentOS 8 server. Zorg ervoor dat hij naar de nieuwste versie is bijgewerkt.
- Minstens 2 GB RAM en 2 cores. Als je er meer hebt, is het beter.
- Een gebruiker met Sudo rechten.
Opzetten van de repositories
Eerst moet je de epel, remi, en icinga repository aan het centos 8 systeem toevoegen. Dan moet je het dnf `config-manager` gereedschap installeren en met dat gereedschap de `PowerTools` repository inschakelen.
1. Voeg de epel en remi repository voor de centos 8 servers toe door de volgende commando’s uit te voeren.
sudo dnf install -y epel-release
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
2. Voer nu het onderstaande commando uit om de Icinga repository voor het centos 8 systeem te downloaden en toe te voegen.
sudo dnf install -y https://packages.icinga.com/epel/icinga-rpm-release-8-latest.noarch.rpm
3. Voer daarna de volgende commando’s uit om het gereedschap dnf config-manager te installeren en de PowerTools repository in te schakelen.
sudo dnf install -y 'dnf-command(config-manager)'
sudo dnf config-manager --set-enabled powertools
4. Als alle processen voltooid zijn, controleer dan alle ingeschakelde repository op je systeem met het onderstaande commando.
sudo dnf repolist
Je ziet uitvoer zoals hieronder, en controleer of de epel, remi, icinga-*, en powertools repositories op de lijst staan.
repo id repo name appstream CentOS Linux 8 - AppStream baseos CentOS Linux 8 - BaseOS epel Extra Packages for Enterprise Linux 8 - x86_64 epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64 extras CentOS Linux 8 - Extras icinga-stable-release ICINGA (stable release for epel) powertools CentOS Linux 8 - PowerTools remi-modular Remi's Modular repository for Enterprise Linux 8 - x86_64 remi-safe Safe Remi's RPM repository for Enterprise Linux 8 - x86_64
Installeren en instellen van de LAMP Stack
Het Icinga bewakingsprogramma heeft twee hoofdcomponenten,“icinga2” dat alle bewakingsopdrachten afhandelt, en de“icingaweb2” die een krachtige, schone en snelle web-applicatie op basis van PHP is waarmee je je Icinga stack vanuit een web browser kunt beheren. Nu ga je de basis LAMP Stack installeren en configureren op het centos 8 systeem.
1. Schakel de remi module voor PHP 7.4 in met het onderstaande commando.
sudo dnf module enable -y php:remi-7.4
Voer vervolgens het volgende commando uit om de basis LAMP Stack pakketten te installeren.
sudo dnf install -y httpd mariadb-server mariadb php php-cli php-devel php-pear make php-mysqlnd php-pecl-imagick php-pecl-imagick-devel
Start nu de diensten apache (httpd op centos) en mariadb en zet ze beide aan om te starten bij het opstarten van het systeem.
sudo systemctl enable --now httpd
sudo systemctl enable --now mariadb
En je ziet gelijkaardige uitvoer als volgt, de apache en mariadb diensten gestart en ingeschakeld.
# Apache started and enabled Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. # MariaDB started and enabled Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service. Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service. Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
2. Voer daarna het onderstaande commando uit om het mariadb root wachtwoord in te stellen en om veiligheidsredenen verwijder je de standaard database test en anonieme gebruiker, en schakel je ook de remote login voor de root gebruiker uit.
sudo mysql_secure_installation
Hieronder staat de gelijkaardige uitvoer die je krijgt, en let erop dat je een nieuw sterk wachtwoord voor de mariadb root gebruiker intypt en‘Y‘ intypt om alle acties te bevestigen.
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! To log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): PRESS ENTER OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: TYPE STRONG PASSWORD Re-enter new password: TYPE STRONG PASSWORD Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Installeren en instellen van Ieta2
Nu ga je de hoofdcomponent van Icinga zelf installeren en configureren. Deze fase omvat de installatie van icinga2 pakketten, het aanmaken van de nieuwe database en gebruiker, het importeren van het databaseschema, en het instellen van de Icinga REST API.
1. Voer het volgende commando uit om de pakketten van het Icinga bewakingshulpmiddel te installeren.
sudo dnf install -y icinga2 nagios-plugins-all
Start daarna de icinga2 service en schakel die in, controleer daarna de status van de Icinga service.
sudo systemctl enable --now icinga2
sudo systemctl status icinga2
Als je soortgelijke uitvoer ziet als de volgende, is de Icinga dienst in werking.
# Icinga2 started and enabled Created symlink /etc/systemd/system/multi-user.target.wants/icinga2.service → /usr/lib/systemd/system/icinga2.service. # Icinga2 status running ? icinga2.service - Icinga host/service/network monitoring system Loaded: loaded (/usr/lib/systemd/system/icinga2.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-07-18 02:38:19 UTC; 6s ago Process: 31290 ExecStartPre=/usr/lib/icinga2/prepare-dirs /etc/sysconfig/icinga2 (code=exited, status=0/SUCCESS) Main PID: 31298 (icinga2) Tasks: 13 (limit: 4964) Memory: 20.9M CGroup: /system.slice/icinga2.service ??31298 /usr/lib64/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log ??31319 /usr/lib64/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log ??31324 /usr/lib64/icinga2/sbin/icinga2 --no-stack-rlimit daemon --close-stdio -e /var/log/icinga2/error.log
2. Als je vervolgens de SELinux aan de praat hebt op het centos 8 systeem, dan moet je het‘icinga2-selinux‘ pakket installeren. Maar als de SELinux uitgeschakeld is, sla je dit deel over.
Voer het onderstaande commando uit om de SELinux status te controleren.
sudo sestatus
Krijg je soortgelijke uitvoer als de volgende, dan is je SELinux‘ingeschakeld‘. Zo niet, dan krijg je de uitvoer‘disabled‘, wat betekent dat je het SELinux gedeelte kunt overslaan.
SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: permissive Mode from config file: permissive Policy MLS status: enabled Policy deny_unknown status: allowed Memory protection checking: actual (secure) Max kernel policy version: 32
Installeer nu het pakket icinga2-selinux met het onderstaande commando.
sudo dnf install -y icinga2-selinux
Pas daarna de nieuwe configuratie toe door de icinga2 dienst opnieuw te starten en controleer of Icinga onder de SELinux context up and running is.
sudo systemctl restart icinga2
ps -eZ | grep icinga2
Hieronder staat de gelijkaardige uitvoer die je zult krijgen.
system_u:system_r:icinga2_t:s0 33479 ? 00:00:00 icinga2 system_u:system_r:icinga2_t:s0 33499 ? 00:00:00 icinga2 system_u:system_r:icinga2_t:s0 33504 ? 00:00:00 icinga2
3. Installeer vervolgens de IDO MySQL backend voor de icinga2 met het volgende commando.
sudo dnf install -y icinga2-ido-mysql
Voer nu het onderstaande commando uit om in te loggen in de MySQL shell en typ je root wachtwoord.
sudo mysql -u root -p
Maak een nieuwe database en gebruiker voor de icinga2 dienst met onderstaande mysql query’s.
MariaDB [(none)]> CREATE DATABASE icinga;
MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icingapassdb';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit
Voer nu het onderstaande mysql commando uit om het icinga2-ido-mysql databaseschema naar de icinga database te importeren, en typ het wachtwoord van je mariadb root wachtwoord.
sudo mysql -u root -p icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql
Schakel daarna de icinga2-ido-mysql functie in en herstart de icinga2 dienst om de nieuwe configuratie toe te passen met de onderstaande commando’s.
sudo icinga2 feature enable ido-mysql
sudo systemctl restart icinga2
En je zult soortgelijke uitvoer zien als in de afbeelding hieronder.
4. Vervolgens moet je de icinga2 REST API configuratie en certificaten genereren. Het icingaweb2 heeft de REST API nodig om acties te verzenden die te maken hebben met bewakingsopdrachten, zoals het opnieuw plannen van controles, query object details, enz.
Voer het onderstaande icinga2 commando uit om nieuwe API gebruikers-, configuratie-, en TLS certificaten te genereren.
sudo icinga2 api setup
En je ziet soortgelijke uitvoer als hieronder, de nieuwe gebruiker root met wachtwoord is beschikbaar in het configuratiebestand /etc/icinga2/conf.d/api-users.conf, en TLS certificaten zijn beschikbaar in de map /var/lib/icinga2/certs/.
information/cli: Generating new CA. information/base: Writing private key to '/var/lib/icinga2/ca//ca.key'. information/base: Writing X509 certificate to '/var/lib/icinga2/ca//ca.crt'. information/cli: Generating new CSR in '/var/lib/icinga2/certs//centos8.csr'. information/base: Writing private key to '/var/lib/icinga2/certs//centos8.key'. information/base: Writing certificate signing request to '/var/lib/icinga2/certs//centos8.csr'. information/cli: Signing CSR with CA and writing certificate to '/var/lib/icinga2/certs//centos8.crt'. information/pki: Writing certificate to file '/var/lib/icinga2/certs//centos8.crt'. information/cli: Copying CA certificate to '/var/lib/icinga2/certs//ca.crt'. information/cli: Adding new ApiUser 'root' in '/etc/icinga2/conf.d/api-users.conf'. information/cli: Reading '/etc/icinga2/icinga2.conf'. information/cli: Enabling the 'api' feature. Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect. information/cli: Updating 'NodeName' constant in '/etc/icinga2/constants.conf'. information/cli: Created backup file '/etc/icinga2/constants.conf.orig'. information/cli: Updating 'ZoneName' constant in '/etc/icinga2/constants.conf'. information/cli: Backup file '/etc/icinga2/constants.conf.orig' already exists. Skipping backup. Done. Now restart your Icinga 2 daemon to finish the installation!
Optioneel, om de nieuwe API gebruiker handmatig toe te voegen, bewerk je de configuratie /etc/icinga2/conf.d/api-users.conf met het nano editor commando zoals hieronder.
sudo nano /etc/icinga2/conf.d/api-users.conf
Plak de volgende voorbeeld configuratie zoals hieronder, en let erop dat je de API gebruiker, het wachtwoord, en de toestemming definieert zoals je nodig hebt.
object ApiUser "icingaweb2" { password = "Wijsn8Z9eRs5E25d" permissions = [ "status/query", "actions/*", "objects/modify/*", "objects/query/*" ] }
Pas ten slotte de nieuwe configuratie toe door de icinga2 dienst opnieuw te starten met het volgende commando.
sudo systemctl restart icinga2
Installeren en instellen van Icingaweb2
Voor deze stap installeer en configureer je de icingaweb2 webapplicatie, inclusief het opzetten van de database en het genereren van de installatietoken.
1. Voer het volgende commando uit om icingaweb2 pakketten te installeren.
sudo dnf install -y icingaweb2 icingacli
Tijdens de installatie wordt de nieuwe apache configuratie voor icingaweb2 gegenereerd. Verifieer de nieuwe configuratie met het volgende commando.
cat /etc/httpd/conf.d/icingaweb2.conf
Hieronder staat de configuratie die je te zien krijgt.
Alias /icingaweb2 "/usr/share/icingaweb2/public" # Remove comments if you want to use PHP FPM and your Apache version is older than 2.4 #<IfVersion < 2.4> # # Forward PHP requests to FPM # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 # <LocationMatch "^{urlPath}/(.*\.php)$"> # ProxyPassMatch "fcgi://127.0.0.1:9000/{documentRoot}/$1" # </LocationMatch> #</IfVersion> <Directory "/usr/share/icingaweb2/public"> Options SymLinksIfOwnerMatch AllowOverride None .......
Om de nieuwe configuratie toe te passen, herstart je de apache/httpd dienst met het onderstaande commando.
sudo systemctl restart httpd
2. Typ vervolgens het volgende commando om in te loggen in de mysql shell.
sudo mysql -u root -p
Voer hieronder enkele mysql query’s uit om een nieuwe database en gebruiker voor icingaweb2 te maken.
MariaDB [(none)]> CREATE DATABASE icingaweb2;
MariaDB [(none)]> GRANT ALL ON icingaweb2.* TO [email protected] IDENTIFIED BY 'icingaweb2passdb';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit
3. Genereer daarna het icingaweb2 setup token voor de installatie in de volgende fase met het volgende commando.
sudo icingacli setup token create
sudo icingacli setup token show
Je krijgt als de volgende uitvoer te zien. Zorg ervoor dat je het icinga2 installatietoken naar je notitie kopieert.
# Generated setup token The newly generated setup token is: 41e33db4cf0c5617 # Show generated token The current setup token is: 41e33db4cf0c5617
Iicinga Web 2 configureren via de webinterface
Open nu je web browser en de URL http://SERVER-IP/icingaweb2/setup, en je krijgt de icinga2 installatie pagina.
1. Plak het icingaweb2 installatie-token in het vakje en klik op Volgende.
2. Laat hier de Icinga modules als standaard staan en klik op Volgende.
3. Zorg nu dat alle icingaweb2 systeemeisen `groene` kleuren hebben, en klik dan op de knop Volgende.
4. Laat de backend authenticatie als standaard‘Database‘ staan en klik op Volgende.
5. Typ de databasenaam, gebruikersnaam en wachtwoord voor de icingaweb2 en klik weer op Volgende.
6. Laat de naam van de authenticatie backend als standaard‘icingaweb2‘ staan en klik op Volgende.
7. Typ nu de nieuwe gebruikers- en wachtwoordadministratie, en klik dan op Volgende.
8. Laat de toepassing en log configuratie als standaard staan, en klik dan op Volgende.
9. Dubbelcheck al je configuraties, klik dan op Next om verder te gaan.
10. Klik nu op Next om de icinga2 bewakingsmodules te configureren.
11. Typ de databasenaam, gebruikersnaam en wachtwoord voor de icinga2-ido-mysql, en klik dan op de knop Validate Configuration.
Als je een fout krijgt als‘Er is momenteel geen icinga instantie die naar de IDO schrijft. Zorg ervoor dat een icinga instantie geconfigureerd is en in staat is naar de IDO te schrijven‘, ga dan terug naar je terminal en bewerk de configuratie handmatig.
Voer het volgende commando uit om de IDO configuratie te bewerken.
sudo nano /etc/icinga2/features-available/ido-mysql.conf
Kopieer en plak de ido mysql configuratie zoals hieronder.
object IdoMysqlConnection "ido-mysql" {
user = "icinga", password = "icingapassdb", host = "localhost", database = "icinga" }
Druk nu op Ctrl+x dan op y en dan op enter om het bestand op te slaan.
Start vervolgens de Icinga2 dienst opnieuw met het volgende commando.
sudo systemctl restart icinga2
Ga nu terug naar de webbrowser en schakel de optie Skip Validation in en klik dan weer op Next.
12. Kies nu het transporttype‘Local Command File‘ en klik op Next.
13. Laat de bewakingsbeveiligingsconfiguratie als standaard staan en klik op Volgende.
14. Dubbel-check je Icinga installatie configuratie en klik op Finish om verder te gaan.
15. Als de installatie geslaagd is, krijg je de uitvoer als de afbeelding hieronder. Klik dan op de knop Login to Icinga Web 2.
Controleer de installatie van Icinga 2 en Icinga Web 2
1. Typ je Icinga administrator gebruiker en wachtwoord, en klik dan op de Login knop.
2. Nu krijg je een gelijkaardige pagina als hieronder.
Zoals je op het dashboard kunt zien, zijn er enkele diensten die automatisch door het icinga2 bewakingstool worden gedetecteerd. Diensten met de kleur groen betekenen gezondheid, en de diensten met de kleur geel betekenen dat je een waarschuwing moet controleren. En foutdiensten hebben rode kleuren.
Conclusie
Als de tutorial voltooid is, heb je geleerd over de installatie en configuratie van het icinga2 bewakingstool op de nieuwste CentOS 8 server met LAMP Stack. De installatie van icinga2 vereist dat je je op elke stap concentreert, en het belangrijkste is dat je weet wat je doet en niet blindelings commando’s uitvoert.