Pour le FUN, La machine sera une AlmaLinux 8 fork de RedHAT (Installation Minimale)
1°) Prérequis
Un site Apache (ici VPS WordPress)
- Site Coffebreak.en-images.info
- Ouvrir le Port 9901 sur votre routeur
2°) Spécification machine
Machine Grafana03
IP : 192.168.1.5 (vSwitch vmbr0)
Host : grafanaw.house.cpb
Disque 1 – Système 20Go
RAM 2G
3°) Installation de Middleware
[root@grafana03 ~]# dnf -y update [root@grafana03 ~]# dnf -y install vim nmap net-tools wget
4°) Suppression du selinux
[root@grafana03 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config [root@grafana03 ~]# reboot
5°) Désactivation IPv6
[root@grafana03 ~]# vi /etc/sysctl.conf net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.all.autoconf = 0 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.default.autoconf = 0
[root@grafana03 ~]# sysctl -p
6°) Installation Promotheus
Création User Promotheus
[root@grafana03 chris]# useradd --no-create-home --shell /bin/false prometheus
Récupération de promotheus
[root@grafana03 ~]# cd /tmp [root@grafana03 tmp]# wget https://github.com/prometheus/prometheus/releases/download/v2.8.1/prometheus-2.8.1.linux-amd64.tar.gz [root@grafana03 tmp]# yum install tar [root@grafana03 tmp]# tar xzvf prometheus-2.8.1.linux-amd64.tar.gz [root@grafana03 tmp]# mv prometheus-2.8.1.linux-amd64 prometheuspackage
Création structure Promotheus
[root@grafana03 tmp]# mkdir /etc/prometheus [root@grafana03 tmp]# mkdir /var/lib/prometheus [root@grafana03 tmp]# chown prometheus:prometheus /etc/prometheus [root@grafana03 tmp]# chown prometheus:prometheus /var/lib/prometheus
Copier les binaires sur la structure Promotheus
[root@grafana03 tmp]# cp prometheuspackage/prometheus /usr/local/bin/ [root@grafana03 tmp]# cp prometheuspackage/promtool /usr/local/bin/ [root@grafana03 tmp]# chown prometheus:prometheus /usr/local/bin/prometheus [root@grafana03 tmp]# chown prometheus:prometheus /usr/local/bin/promtool
Copier les fichiers conf sur la structure Promotheus
[root@grafana03 tmp]# cp -r prometheuspackage/consoles /etc/prometheus [root@grafana03 tmp]# cp -r prometheuspackage/console_libraries /etc/prometheus [root@grafana03 tmp]# chown -R prometheus:prometheus /etc/prometheus/consoles [root@grafana03 tmp]# chown -R prometheus:prometheus /etc/prometheus/console_libraries
Création du service Promotheus
[root@grafana03 tmp]# vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
Configurer Promotheus
[root@grafana03 chris]# vi /etc/prometheus/prometheus.yml
global:
scrape_interval: 10s
scrape_configs:
- job_name: 'coffeebreak'
scrape_interval: 5s
static_configs:
- targets: ['vps:9901']
Démarrage du service Promotheus
[root@grafana03 tmp]# systemctl daemon-reload [root@grafana03 tmp]# systemctl start prometheus && systemctl enable prometheus [root@grafana03 tmp]# systemctl status prometheus
Régle de Firewall – Promotheus
[root@grafana03 ~]# firewall-cmd --zone=public --add-port=9901/tcp --permanent [root@grafana03 ~]# firewall-cmd --reload
7°) Installation Grafana
[root@grafana03 ~]# vi /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
[root@grafana03 ~]# dnf update [root@grafana03 ~]# dnf install grafana
Installation de font du Supplémentaire
[root@grafana03 ~]# dnf install fontconfig freetype* urw-fonts
Activer Grafana
[root@grafana03 ~]# systemctl start grafana-server && systemctl enable grafana-server [root@grafana03 ~]# systemctl status grafana-server
Régle de Firewall – grafana
[root@grafana03 ~]# firewall-cmd - zone=public --add-port=3000/tcp --permanent [root@grafana03 ~]# firewall-cmd --reload
8°) Installer l’exporter sur le Site VPS
Récupération de l’exporter apache
[root@vps-xxxxxx chris]# yum install git [root@vps-xxxxxx chris]# cd /tmp [root@vps-xxxxxx tmp]# git clone https://github.com/Lusitaniae/apache_exporter.git
Installation de GO
[root@vps-xxxxxx tmp]# yum update -y [root@vps-xxxxxx tmp]# yum groupinstall 'Development Tools' [root@vps-xxxxxx tmp]# cd /tmp;wget https://golang.org/dl/go1.15.3.linux-amd64.tar.gz [root@vps-xxxxxx tmp]# tar -zxvf go1.15.3.linux-amd64.tar.gz -C /usr/local
[root@vps-xxxxxx tmp]# echo 'export GOROOT=/usr/local/go' | sudo tee -a /etc/profile export GOROOT=/usr/local/go [root@vps-xxxxxx tmp]# echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee -a /etc/profile export PATH=$PATH:/usr/local/go/bin [root@vps-xxxxxx tmp]# source /etc/profile
[root@vps-xxxxxx tmp]# go version go version go1.15.3 linux/amd64
Compiler et installer exporter Apache
[root@vps-xxxxxx tmp]# cd apache_exporter/ [root@vps-xxxxxx apache_exporter]# make Ne pas tenir compte du message d’erreur « for file in test/*.metrics; do docker run -i --rm -w "/tmp/apache_exporter" -v "/tmp/apache_exporter:/tmp/apache_exporter" --entrypoint promtool quay.io/prometheus/prometheus:latest check metrics < $file || exit 1; done » [root@vps-xxxxxx apache_exporter]# mv apache_exporter /usr/local/bin [root@vps-xxxxxx apache_exporter]# /usr/local/bin/apache_exporter --version
Création Group/User privilège
[root@vps-xxxxxx apache_exporter]# groupadd --system prometheus [root@vps-xxxxxx apache_exporter]# useradd -s /sbin/nologin --system -g prometheus prometheus
Création du service exporter Apache
[root@vps-e7276df3 apache_exporter]# vi /etc/systemd/system/apache_exporter.service
[unit]
Description=Prometheus
Documentation=https://github.com/Lusitaniae/apache_exporter
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/apache_exporter \
--insecure \
--scrape_uri=http://localhost/server-status/?auto \
--telemetry.address=0.0.0.0:9901 \
--telemetry.endpoint=/metrics
SyslogIdentifier=apache_exporter
Restart=always
[Install]
WantedBy=multi-user.target
[root@vps-xxxxxx apache_exporter]# systemctl daemon-reload [root@vps-xxxxxx apache_exporter]# systemctl start apache_exporter.service [root@vps-xxxxxx apache_exporter]# systemctl enable apache_exporter.service
9°) Activer mod_status apache
[root@vps-xxxxxx chris]# apachectl -M | grep status
status_module (shared)
[root@vps-e7276df3 chris]# vi /etc/httpd/conf.d/status.conf
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
# IP Autorisés
Allow from localhost 83.XX 149.XXX
</Location>
[root@vps-xxxxxx chris]# systemctl reload httpd
Test Local
[root@vps-xxxxxx chris]# yum install lynx [root@vps-xxxxxx chris]# lynx http://localhost/server-status
https://coffeebreak.en-images.info/server-status
Régle de Firewall – Exporter Apache
[root@ vps-xxxxxx apache_exporter]# firewall-cmd --zone=public --add-port=9901/tcp --permanent [root@ vps-xxxxxx apache_exporter]# firewall-cmd --reload
10°) Configurer Prometheus et Grafana
« Ajouter DATA source »
« Choisir la source »
« Inscrire l’adresse du serveur Promotheus »
Ajouter un Dasboard
Il existe de nombreux Dashboard prêt à l’emploi
« Import »
« Ajouter l’ID souhaité » puis « Load »
« Import »
« Arrivée des métriques »
Views: 10