Initial commit: VPS tutorial complet (105 etapes)
This commit is contained in:
163
06-monitoring.md
Normal file
163
06-monitoring.md
Normal file
@@ -0,0 +1,163 @@
|
||||
# 6. Monitoring
|
||||
|
||||
## Munin
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
apt install libcgi-fast-perl libapache2-mod-fcgid
|
||||
a2enmod fcgid
|
||||
apt install munin munin-node munin-plugins-extra logtail libcache-cache-perl
|
||||
```
|
||||
|
||||
### Plugins MySQL
|
||||
|
||||
```bash
|
||||
cd /etc/munin/plugins
|
||||
ln -s /usr/share/munin/plugins/mysql_ mysql_
|
||||
ln -s /usr/share/munin/plugins/mysql_bytes mysql_bytes
|
||||
ln -s /usr/share/munin/plugins/mysql_innodb mysql_innodb
|
||||
ln -s /usr/share/munin/plugins/mysql_isam_space_ mysql_isam_space_
|
||||
ln -s /usr/share/munin/plugins/mysql_queries mysql_queries
|
||||
ln -s /usr/share/munin/plugins/mysql_slowqueries mysql_slowqueries
|
||||
ln -s /usr/share/munin/plugins/mysql_threads mysql_threads
|
||||
```
|
||||
|
||||
### Base de donnees Munin
|
||||
|
||||
```sql
|
||||
CREATE SCHEMA munin_innodb;
|
||||
USE munin_innodb;
|
||||
CREATE TABLE something (anything int) ENGINE=InnoDB;
|
||||
GRANT SELECT ON munin_innodb.* TO 'munin'@'localhost' IDENTIFIED BY 'munin';
|
||||
FLUSH PRIVILEGES;
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
Editer `/etc/munin/munin.conf` :
|
||||
- Decommenter `dbdir`, `htmldir`, `logdir`, `rundir`, `tmpldir`
|
||||
- Remplacer `[localhost.localdomain]` par `[munin.<DOMAINE>]`
|
||||
|
||||
### Apache auth
|
||||
|
||||
```bash
|
||||
a2enconf munin
|
||||
htpasswd -c /etc/munin/munin-htpasswd admin
|
||||
```
|
||||
|
||||
Editer `/etc/apache2/conf-enabled/munin.conf` avec auth basic (voir scripts/setup_munin_config.py).
|
||||
|
||||
### Auto-configure plugins
|
||||
|
||||
```bash
|
||||
cd /etc/munin/plugins
|
||||
munin-node-configure --shell --families=contrib,auto | sh -x
|
||||
service munin-node restart
|
||||
service apache2 restart
|
||||
```
|
||||
|
||||
## Monit
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
apt install monit
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
Creer `/etc/monit/conf.d/monitrc.local` :
|
||||
|
||||
```
|
||||
set daemon 60
|
||||
set logfile syslog facility log_daemon
|
||||
set mailserver localhost
|
||||
set mail-format { from: monit@<DOMAINE> }
|
||||
set alert <EMAIL>
|
||||
set httpd port 2812 and
|
||||
SSL ENABLE
|
||||
PEMFILE /usr/local/ispconfig/interface/ssl/ispserver.pem
|
||||
allow admin:"<MOT_DE_PASSE>"
|
||||
```
|
||||
|
||||
### Fichiers de monitoring
|
||||
|
||||
Creer dans `/etc/monit/conf-enabled/` les fichiers pour : mariadb, pureftpd, named, sshd, apache2, memcached, ntpd, dovecot, postfix, redis.
|
||||
|
||||
Voir `scripts/setup_monit.py` pour le script complet.
|
||||
|
||||
```bash
|
||||
mkdir /var/www/html/monit
|
||||
echo "hello" > /var/www/html/monit/token
|
||||
service apache2 restart
|
||||
service monit restart
|
||||
```
|
||||
|
||||
Ajouter port 2812 au firewall ISPConfig.
|
||||
|
||||
## Grafana + Prometheus
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
echo "deb https://packages.grafana.com/oss/deb stable main" >> /etc/apt/sources.list.d/grafana.list
|
||||
cd /etc/apt/trusted.gpg.d && wget https://packages.grafana.com/gpg.key -O grafana.asc
|
||||
apt update
|
||||
apt install grafana prometheus prometheus-mysqld-exporter prometheus-apache-exporter prometheus-bind-exporter prometheus-process-exporter
|
||||
```
|
||||
|
||||
### Configurer Grafana sur port 3100
|
||||
|
||||
Editer `/etc/grafana/grafana.ini` :
|
||||
```ini
|
||||
http_port = 3100
|
||||
```
|
||||
|
||||
### Configurer Prometheus
|
||||
|
||||
Editer `/etc/prometheus/prometheus.yml` — ajouter les jobs : prometheus, node, dns-master, apache, process, mysql.
|
||||
|
||||
> **Piege :** Ne pas dupliquer les jobs (erreur "found multiple scrape configs with job name").
|
||||
|
||||
### Sous-domaine Grafana
|
||||
|
||||
DNS A `grafana` -> `<IP>`, puis sous-domaine ISPConfig avec proxy vers `http://localhost:3100/`.
|
||||
|
||||
### Demarrer
|
||||
|
||||
```bash
|
||||
systemctl enable grafana-server && systemctl start grafana-server
|
||||
service prometheus restart
|
||||
```
|
||||
|
||||
Login par defaut : **admin / admin**
|
||||
|
||||
## Loki + Promtail
|
||||
|
||||
### Loki
|
||||
|
||||
```bash
|
||||
cd /usr/local/bin
|
||||
# Telecharger la derniere version depuis https://github.com/grafana/loki/releases/
|
||||
wget <URL_LOKI_LINUX_AMD64> -O loki.zip
|
||||
unzip loki.zip && mv loki-linux-amd64 loki && chmod 755 loki && rm loki.zip
|
||||
```
|
||||
|
||||
Creer `/etc/config-loki.yml` et `/etc/systemd/system/loki.service`.
|
||||
|
||||
> **Piege :** Loki v3 a un format de config different de v2. Utiliser `schema: v13` et `store: tsdb`.
|
||||
|
||||
### Promtail
|
||||
|
||||
```bash
|
||||
# Promtail n'existe plus dans Loki v3, utiliser la derniere v2
|
||||
wget https://github.com/grafana/loki/releases/download/v2.9.10/promtail-linux-amd64.zip -O promtail.zip
|
||||
unzip promtail.zip && mv promtail-linux-amd64 promtail && chmod 755 promtail && rm promtail.zip
|
||||
```
|
||||
|
||||
Creer `/etc/config-promtail.yml` et `/etc/systemd/system/promtail.service`.
|
||||
|
||||
### Ajouter Loki dans Grafana
|
||||
|
||||
Configuration > Data Sources > Add > Loki > URL : `http://127.0.0.1:3101`
|
||||
Reference in New Issue
Block a user