Zabbix HTTPS-installatie op Ubuntu Linux

Deze tutorial zal je alle stappen tonen die nodig zijn om Zabbix 4 te installeren met behulp van HTTPS op Ubuntu Linux.

Deze tutorial gebruikt Let's Encrypt - Free SSL / TLS Certificates.

Deze tutorial is getest op Ubuntu 18.04.

1. Configureer de Datum en Tijd met NTP

Het is erg belangrijk om uw systeem op de juiste datum en tijd te houden.

Stel de juiste tijdzone in.

# dpkg-reconfigure tzdata

Installeer het Ntpdate-pakket en stel de juiste datum en tijd in.

# apt-get update
# apt-get install ntpdate
# ntpdate pool.ntp.br

Schakel de standaard NTP-client van Ubuntu uit.

Installeer de NTP-service om de datum en tijd van de computer bij te houden na een herstart.

# timedatectl set-ntp 0
# apt-get install ntp

Zorg ervoor dat de juiste datum en tijd op uw computer zijn ingesteld.

# date

2. Installeer MySQL op Ubuntu Linux

Zabbix heeft een databasesysteem nodig om alle configuratie op te slaan.

Gebruik de opdracht Ubuntu APT om de MySQL-server te installeren.

# apt-get update
# apt-get install mysql-server mysql-client

Gebruik de volgende opdracht om toegang te krijgen tot de MySQL-serviceconsole.

# mysql -u root -p

Op de MySQL-console moet u de volgende taken uitvoeren:

• Maak een database met de naam zabbix.
• Maak een MySQL-gebruikersaccount met de naam zabbix.
• Geef de zabbix-gebruiker volledige controle over de zabbix-database.

CREATE DATABASE zabbix CHARACTER SET UTF8 COLLATE UTF8_BIN;
CREATE USER 'zabbix'@'%' IDENTIFIED BY 'kamisama123';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%';
quit;

Download het Zabbix-installatiepakket om de databasesjablonen op te halen.

# mkdir /downloads
# cd /downloads
# wget https://ufpr.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz

Pak het Zabbix-installatiepakket uit.

Importeer de Zabbix-databasesjablonen in de MySQL-database.

Indien gevraagd, moet u het MySQL-wachtwoord invoeren voor de Zabbix-gebruiker.

# tar -zxvf zabbix-4.0.3.tar.gz
# cd zabbix-4.0.3/database/mysql/
# mysql -u zabbix -p zabbix < schema.sql
# mysql -u zabbix -p zabbix < images.sql
# mysql -u zabbix -p zabbix < data.sql

De Zabbix-database-installatie is voltooid.

3. Installeer Apache op Ubuntu Linux

Gebruik de opdracht Ubuntu APT om de Apache-server en de vereiste PHP-modules te installeren.

# apt-get install apache2 php7.2 php7.2-mysql libapache2-mod-php7.2
# apt-get install php7.2-mbstring php7.2-xml php7.2-gd
# apt-get install php7.2-curl php7.2-bcmath php7.2-ldap

Schakel Apache mod_ssl in.

Schakel Apache mod_rewrite in.

Bewerk het bestand apache2.conf.

# a2enmod ssl
# a2enmod rewrite
# vi /etc/apache2/apache2.conf

Voeg de volgende regels toe aan het einde van apache2.conf

<Directory /var/www/html>
AllowOverride All
</Directory>

Zoek de locatie van het PHP-configuratiebestand op uw systeem.

Bewerk het php.ini-configuratiebestand.

# updatedb
# locate php.ini
# vi /etc/php/7.2/apache2/php.ini

Uw PHP-versie is misschien niet hetzelfde als die van ons.

Uw PHP-configuratiebestandslocatie is mogelijk niet dezelfde als die van ons.

Wijzig de volgende items in het php.ini-configuratiebestand.

max_execution_time = 300
memory_limit = 256M
post_max_size = 32M
max_input_time = 300
date.timezone = America/Sao_Paulo

Uw tijdzone is mogelijk niet dezelfde als die van ons.

Start de Apache-webserver handmatig opnieuw.

# service apache2 restart
# service apache2 status

Controleer de status van de Apache-service.

● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Mon 2018-12-03 03:41:12 -02; 2 days ago

De installatie van de Apache-server is voltooid.

4. Configureren van Apache Virtual Hosts

Virtuele hosts als een functie waarmee één Apache-server meerdere websites kan aanbieden met hetzelfde IP-adres.

Hiermee wordt de benodigde infrastructuur gemaakt om de Apache VirtualHosts-functie te gebruiken.

# mkdir /websites/zabbix -p
# cd /websites/zabbix
# mkdir www logs
# chown www-data.www-data /websites -R

Onze website zal zabbix.mining-pool.ninja heten.

De webbestanden van zabbix.mining-pool.ninja moeten zich in de map / websites / zabbix / www bevinden.

De logboeken zabbix.mining-pool.ninja worden opgeslagen in de map / websites / zabbix / logs.

Alert!

Zabbix.mining-pool.ninja was used as an example!

You need to change the configuration files to reflect your Zabbix website name.

Maak een Apache Virtualhost-configuratiebestand naar uw Zabbix-website.

# vi /etc/apache2/sites-available/zabbix.conf

Hier is het bestand met onze configuratie.

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/zabbix/www
ServerName zabbix.mining-pool.ninja

<Directory /websites/zabbix/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/zabbix/logs/error.log
CustomLog /websites/zabbix/logs/access.log combined
LogLevel error
</VirtualHost>

Schakel uw Zabbix Virtualhost Website-configuratiebestand in.

Start de Apache-service opnieuw.

# a2ensite zabbix.conf
# service apache2 restart

U hebt de Apache VirtualHosts-configuratie voltooid.

5. Configureer het DNS-domeinregister

Toegang krijgen tot GODADDY en koop een DNS-domein.

In ons voorbeeld kopen we het domein met de naam MININGPOOL.NINJA.

U kunt elke website gebruiken om een DNS-domein aan te schaffen, GoDaddy is gewoon mijn persoonlijke keuze.

Maak een DNS-invoer die uw Zabbix-website naar de computer met Apache wijst.

In ons voorbeeld hebben we een DNS-vermelding gemaakt met de naam ZABBIX.MINING-POOL.NINJA aan het IP-adres 34.217.177.160.

Zabbix virtual host dns

Gebruik de opdracht NSLOOKUP om uw DNS-configuratie te testen

# apt-get update
# apt-get install dnsutils
# nslookup zabbix.mining-pool.ninja

Non-authoritative answer:
Name: zabbix.mining-pool.ninja
Address: 34.217.177.160

U hebt de DNS-domeinconfiguratie voltooid.

Open uw browser en probeer toegang te krijgen tot de HTTP-versie van uw website.

In ons voorbeeld is de volgende URL in de browser ingevoerd:

• http://zabbix.mining-pool.ninja

Zabbix HTTP Virtual Host

Nu moeten we het gratis HTTPS-certificaat installeren.

We moeten ook alle HTTP-verkeer automatisch omleiden naar de HTTPS-versie van onze Zabbix-website.

6. Configureer het Gratis HTTPS-certificaat op Apache

Installeer de vereiste pakketten om de LET'S ENCRYPT gratis SSL / TLS-certificaten op Ubuntu Linux te gebruiken.

# apt-get install software-properties-common
# add-apt-repository universe
# add-apt-repository ppa:certbot/certbot
# apt-get update
# apt-get install python-certbot-apache

Vraag en installeer het gratis Apache-HTTPS-certificaat.

# certbot --apache -d mining-pool.ninja

• Druk op (A) om akkoord te gaan met de servicevoorwaarden.
• Druk op (Y) om uw e-mail te delen en nieuwsbrieven te ontvangen.
• Druk op (2) om uw HTTP-website automatisch om te leiden naar de HTTPS-versies.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): techexpert.tips@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for zabbix.mining-pool.ninja
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/zabbix-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/zabbix-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/zabbix-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/zabbix.conf to ssl vhost in /etc/apache2/sites-available/zabbix-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://zabbix.mining-pool.ninja

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=zabbix.mining-pool.ninja
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/zabbix.mining-pool.ninja/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/zabbix.mining-pool.ninja/privkey.pem
Your cert will expire on 2019-04-09. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

Het systeem vraagt automatisch het gratis certificaat aan.

Het zal ook uw Apache-webserver configureren om alle HTTP-toegang naar de HTTPS-versie van uw website om te leiden.

In ons voorbeeld heeft het systeem een HTTPS Virtualhost-configuratiebestand gemaakt met de naam zabbix-le-ssl.conf.

Hier is de inhoud van het HTTPS Virtualhost-configuratiebestand zabbix-le-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin nobody@care.com
DocumentRoot /websites/zabbix/www
ServerName zabbix.mining-pool.ninja

<Directory /websites/zabbix/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/zabbix/logs/error.log
CustomLog /websites/zabbix/logs/access.log combined
LogLevel error

SSLCertificateFile /etc/letsencrypt/live/zabbix.mining-pool.ninja/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/zabbix.mining-pool.ninja/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Het KEY-bestand bevat uw privésleutel voor certificaten en moet altijd op een veilige plaats worden bewaard.

Het sleutelbestand voor mining-pool.ninja werd opgeslagen op /etc/letsencrypt/live/zabbix.mining-pool.ninja/privkey.pem.

Het systeem past automatisch het oorspronkelijke Apache Virtualhost-configuratiebestand aan.

Het stuurt alle HTTP-verzoeken automatisch door naar de HTTPS-versie van uw website.

Hier is de inhoud van het bijgewerkte oorspronkelijke HTTP Virtualhost-configuratiebestand, zabbix.conf:

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/zabbix/www
ServerName zabbix.mining-pool.ninja

<Directory /websites/zabbix/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/zabbix/logs/error.log
CustomLog /websites/zabbix/logs/access.log combined
LogLevel error
RewriteEngine on
RewriteCond %{SERVER_NAME} =zabbix.mining-pool.ninja
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

7. Het Testen van het Gratis HTTPS-certificaat op Apache

Alle benodigde configuratie is voltooid.

Het is tijd om uw configuratie te testen.

Open uw browser en probeer toegang te krijgen tot de HTTP-versie van uw website.

In ons voorbeeld is de volgende URL in de browser ingevoerd:

• http://zabbix.mining-pool.ninja

Apache zal het HTTP-verzoek automatisch doorsturen naar de HTTPS-versie van uw website.

Zabbix HTTPS Virtual Host

U hebt de Apache HTTPS-vrije certificaatconfiguratie voltooid.

8. Installeer Zabbix 4 op Ubuntu Linux

Nadat de MySQL- en de Apache-configuratie zijn voltooid, kunnen we de Zabbix-installatie starten.

Maak het vereiste gebruikersaccount voor de Zabbix-service.

# groupadd zabbix
# useradd -g zabbix -s /bin/bash zabbix

Gebruik de opdracht Ubuntu APT om de vereiste pakketten te installeren.

# apt-get install build-essential libmysqlclient-dev libssl-dev libsnmp-dev libevent-dev
# apt-get install libopenipmi-dev libcurl4-openssl-dev libxml2-dev libssh2-1-dev libpcre3-dev
# apt-get install libldap2-dev libiksemel-dev libcurl4-openssl-dev libgnutls28-dev

Toegang tot de map waar het Zabbix-installatiepakket is gedownload.

Compileer en installeer de Zabbix-servertoepassing.

# cd /downloads/zabbix-4.0.3/
# ./configure --enable-server --enable-agent --with-mysql --with-openssl --with-net-snmp --with-openipmi --with-libcurl --with-libxml2 --with-ssh2 --with-ldap
# make
# make install

Zoek de locatie van het Zabbix-serverconfiguratiebestand op uw systeem.

Bewerk het configuratiebestand zabbix_server.conf.

# updatedb
# locate zabbix_server.conf
# vi /usr/local/etc/zabbix_server.conf

Hier is het originele bestand, vóór onze configuratie.

LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
Timeout=4
LogSlowQueries=3000

Hier is het nieuwe bestand met onze configuratie.

LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=kamisama123
Timeout=4
LogSlowQueries=3000

Start de Zabbix-server met behulp van de volgende opdracht.

# /usr/local/sbin/zabbix_server

Start de Zabbix-agenttoepassing met behulp van de volgende opdracht.

# /usr/local/sbin/zabbix_agentd

Optioneel! Het installatiepakket van Zabbix biedt opstartscripts voor services.

Kopieer het opstartscript van Zabbix.

# cd /downloads/zabbix-4.0.3/
# cp misc/init.d/debian/* /etc/init.d/

U kunt nu de volgende opdrachten gebruiken om de Zabbix-serverservice te starten.

# /etc/init.d/zabbix-server start

U kunt nu de volgende opdrachten gebruiken om de Zabbix-serverservice te stoppen.

# /etc/init.d/zabbix-server stop

Verplaats de Zabbix-frontend-bestanden in de hoofdmap van uw Apache-hoofdmap.

Geef de gebruiker van www-data de volledige controle over de Zabbix-directory en de bijbehorende bestanden.

# cd /downloads/zabbix-4.0.3/frontends
# cp php/* /websites/zabbix/www/ -R
# chown www-data.www-data /websites/zabbix/www -R

Start de Apache-service opnieuw.

# service apache2 stop
# service apache2 start

9. Configureer Zabbix op Ubuntu Linux

Open uw browser en open de HTTPS-versie van uw Zabbix-website.

In ons voorbeeld is de volgende URL in de browser ingevoerd:

• https://zabbix.mining-pool.ninja

De Zabbix-installatiewizard wordt gepresenteerd.

Zabbix Installation

Controleer of aan alle Zabbix-vereisten is voldaan.

Zabbix Requirements

Voer de MySQL-inloggegevens in die vereist zijn om verbinding te maken met de Zabbix-database

Zabbix database connetion

Klik op de knop Volgende.

Zabbix Agent Connection

Controleer het Zabbix-installatiesamenvatting.

Zabbis Installation Summary

Klik op de knop Voltooien om toegang te krijgen tot het aanmeldscherm van Zabbix.

Zabbix installation finished

Voer de volgende informatie in op het aanmeldingsscherm van Zabbix.

• Zabbix standaard gebruikersnaam: Admin
• Zabbix standaard wachtwoord: zabbix

Zabbix Login

Na een succesvolle aanmelding wordt het Zabbix-dashboard weergegeven.

Zabbix Dashboard

Gefeliciteerd, Zabbix is op uw systeem geïnstalleerd.

10. Monitor de Zabbix-server

De Zabbix-server moet zichzelf kunnen controleren.

Ga op het Zabbix-dashboard naar het menu Configuratie en selecteer de optie Host.

Zabbix menu

Selecteer in de rechterbovenhoek van het scherm de optie met de naam: Zabbix-servers

Zabbix Server Group

Zoek de host met de naam Zabbix-server en klik op het woord DISABLED.

Hierdoor kan de Zabbix-server zichzelf controleren.

Zabbix server agent disabled

De Zabbix-serverstatus verandert van UITGESCHAKELD naar INGESCHAKELD.

Zabbix server agent enabled

De Zabbix-server controleert zichzelf nu.

11. Hoe het Gratis HTTPS-certificaat te Verlengen

De LET'S ENCRYPT Free SSL / TLS-certificaten zijn slechts 90 dagen geldig.

Het systeem maakt een geplande taak om elk certificaat automatisch te vernieuwen binnen dertig dagen na afloop.

De geplande taaknaam is certbot en deze bevindt zich in de directory /etc/cron.d.

Hier is de inhoud van het bestand /etc/cron.d/certbot:

# /etc/cron.d/certbot: crontab entries for the certbot package
#
# Upstream recommends attempting renewal twice a day
#
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
#
# Important Note! This cronjob will NOT be executed if you are
# running systemd as your init system. If you are running systemd,
# the cronjob.timer function takes precedence over this cronjob. For
# more details, see the systemd.timer manpage, or use systemctl show
# certbot.timer.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

Gebruik de volgende opdracht om het proces van certificaatvernieuwing te simuleren.

# certbot renew --dry-run

Je zou de volgende berichten moeten zien:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/zabbix.mining-pool.ninja.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for zabbix.mining-pool.ninja
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/zabbix.mining-pool.ninja/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/zabbix.mining-pool.ninja/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.