3826gelesen
In diesem Artikel möchte ich dir zeigen, wie du die beiden VTS Module in nginx installierst. Aber zuerst einmal – was machen die beiden Module?
nginx VTS Modul
VTS ist ein Modul für nginx mit dem man sich den Status des Netzwerkverkehrs anzeigen lassen kann.
Link zum Source-Code: github.com/vozlt/nginx-module-vts
nginx VTS Exporter
der VTS Exporter wird verwendet um die Ausgabe des VTS Moduls mit einem Prometheus-Server auszuwerten.
Link zum Source-Code: github.com/hnlq715/nginx-vts-exporter
Installation
Wichtig für die Installation ist, dass nginx selbst kompiliert werden muss. Dazu sind ein paar Vorbereitungen notwendig. Zuerst benötigen wir ein paar Pakete:
user@system: sudo apt install build-essential git curl
Benötigte Applikationen bereitstellen
PCRE herunterladen und entpacken
user@system: cd ~ user@system: curl -O https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz user@system: tar xzf pcre-8.43.tar.gz
Zlib herunterladen und entpacken
user@system: cd ~ user@system: curl -O https://www.zlib.net/zlib-1.2.11.tar.gz user@system: tar xzf zlib-1.2.11.tar.gz
OpenSSL herunterladen und entpacken
user@system: cd ~ user@system: curl -O https://www.openssl.org/source/openssl-1.1.1b.tar.gz user@system: tar xzf openssl-1.1.1b.tar.gz
nginx VTS Modul herunterladen
user@system: cd ~ user@system: git clone git://github.com/vozlt/nginx-module-vts.git
Jetzt können wir noch ein paar hilfreiche Erweiterungen installieren (dieser Schritt ist optional)
user@system: sudo add-apt-repository -y ppa:maxmind/ppa user@system: sudo apt update user@system: sudo apt install -y perl libperl-dev libgd3 libgd-dev libgeoip1 libgeoip-dev geoip-bin libxml2 libxml2-dev libxslt1.1 libxslt1-dev
nginx kompilieren und installieren
Jetzt wird nginx heruntergeladen und installiert. Dazu verwende ich hier die Version 1.15.12. Andere Versionen können auf nginx.com/download.html geprüft und geladen werden.
user@system: cd ~ user@system: curl -O http://nginx.org/download/nginx-1.15.12.tar.gz user@system: tar xzf nginx-1.15.12.tar.gz
Jetzt starten wir die Konfiguration und kompilieren nginx und installieren es in die richtigen Pfade.
user@system: cd ~/nginx-1.15.12
user@system: ./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx \
--group=nginx \
--build=Ubuntu \
--builddir=nginx-1.15.12 \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_perl_module=dynamic \
--with-perl_modules_path=/usr/share/perl/5.26.1 \
--with-perl=/usr/bin/perl \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre=../pcre-8.43 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.1.1b \
--with-openssl-opt=no-nextprotoneg \
--add-module=../nginx-module-vts \
--with-debuguser@system: cd ~/nginx-1.15.12
checking for OS
+ Linux 4.15.0-50-generic x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04)
.........
adding module in ../nginx-module-vts
+ ngx_http_vhost_traffic_status_module was configured
checking for libxslt ... found
checking for libexslt ... found
checking for GD library ... found
checking for GD WebP support ... found
checking for perl
+ perl version: This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi
+ perl interpreter multiplicity found
checking for GeoIP library ... found
checking for GeoIP IPv6 support ... found
creating nginx-1.15.12/Makefile
Configuration summary
+ using threads
+ using PCRE library: ../pcre-8.43
+ using OpenSSL library: ../openssl-1.1.1b
+ using zlib library: ../zlib-1.2.11
nginx path prefix: "/etc/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx modules path: "/usr/lib/nginx/modules"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/cache/nginx/client_temp"
nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"
user@system: make
user@system: make install
user@system: sudo ln -s /usr/lib/nginx/modules /etc/nginx/modulesJetzt können wir überprüfen, ob alles richtig installiert ist.
user@system: nginx -V nginx version: nginx/1.15.12 (Ubuntu) built by gcc 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04) built with OpenSSL 1.1.1b 26 Feb 2019 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --build=Ubuntu --builddir=nginx-1.15.12 --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-perl_modules_path=/usr/share/perl/5.26.1 --with-perl=/usr/bin/perl --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-compat --with-pcre=../pcre-8.43 --with-pcre-jit --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.1b --with-openssl-opt=no-nextprotoneg --add-module=../nginx-module-vts --with-debug
Jetzt müssen wir den richtigen Benutzer in die Konfiguration /etc/nginx/nginx.conf eintragen: user www-data; Anschließend erstellen wir die benötigten Ordner für nginx und überprüfen die Konfiguration.
user@system: sudo mkdir -p /var/cache/nginx/client_temp /var/cache/nginx/fastcgi_temp /var/cache/nginx/proxy_temp /var/cache/nginx/scgi_temp /var/cache/nginx/uwsgi_temp user@system: sudo chmod -R 700 /var/cache/nginx/* user@system: sudo chown www-data.www-data /var/cache/nginx user@system: sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Jetzt erstellen wir den Service, dazu legen wir die Datei /etc/systemd/system/nginx.service an und beschreiben diese mit folgendem Inhalt:
[Unit] Description=nginx - high performance web server Documentation=https://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target
Jetzt wird der Service aktiviert und gestartet. Mit dem dritten Befehl aktivieren wir nginx beim Booten des Systems.
user@system: sudo systemctl enable nginx.service user@system: sudo systemctl start nginx.service user@system: sudo systemctl is-enabled nginx.service
Erledigt: VTS Module in nginx installiert
Hat alles funktioniert kann mit dem Aufruf der IP im Browser folgende Seite angezeigt werden.

Tipp: Falls du dich für HTTP Umleitungen für nginx interessierst, habe ich hier einen Artikel dazu geschrieben.