Installez Prometheus Grafana sur Ubuntu pour surveiller mysql, redis

Comme le dit le proverbe, un système sans surveillance fonctionne à nu, et une bonne surveillance est la troisième main et le troisième œil du personnel d'exploitation et de maintenance. Cet article utilisera prometheus et Grafana pour construire un système de surveillance pour surveiller l'hôte et la base de données ( MySQL , Redis ).

1. Sous-vêtements Grafana

Grafana est un panneau de visualisation (Dashboard), avec un très beau graphique et un affichage de mise en page, un tableau de bord de mesure complet et un éditeur de graphique, prenant en charge Graphite, zabbix, InfluxDB, Prometheus et d'autres sources de données.

1.1 Télécharger et installer

Lien de téléchargement: https://grafana.com/grafana/download

Après le téléchargement, vous pouvez l'installer:

sudo dpkg -i grafana_5.0.4_amd64.deb

Commencez à afficher le statut:

sudo systemctl start grafana-server état
sudo systemctl grafana-server

 

 Ensuite, configurez l'utilisateur et le répertoire prometheus:

vagrant@vagrant:/htdocs/share$ sudo useradd --no-create-home --shell /bin/false prometheus
vagrant@vagrant:/htdocs/share$ sudo useradd --no-create-home --shell /bin/false node_exporter
vagrant@vagrant:/htdocs/share$ sudo mkdir /etc/prometheus
vagrant@vagrant:/htdocs/share$ sudo mkdir /var/lib/prometheus
vagrant@vagrant:/htdocs/share$ sudo chown prometheus:prometheus /etc/prometheus
vagrant@vagrant:/htdocs/share$ sudo chown prometheus:prometheus /var/lib/prometheus

Prochain téléchargement prometheus:

vagrant @ vagrant: / htdocs / share $ cd 
vagrant @ vagrant: ~ $ curl -LO https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar .gz

 Décompressez et entrez dans le répertoire:

vagrant @ vagrant: / htdocs / share $ sudo cp prometheus-2.0.0.linux-amd64 / prometheus / usr / local / bin /
vagrant @ vagrant: / htdocs / share $ sudo cp prometheus-2.0.0.linux-amd64 / promtool / usr / local / bin /
vagrant @ vagrant: / htdocs / share $ sudo chown prometheus: prometheus / usr / local / bin / prometheus
vagrant @ vagrant: / htdocs / share $ sudo chown prometheus: prometheus / usr / local / bin / promtool
vagrant @ vagrant: / htdocs / share $ sudo cp -r prometheus-2.0.0.linux-amd64 / consoles / etc / prometheus
vagrant @ vagrant: / htdocs / share $ sudo cp -r prometheus-2.0.0.linux -amd64 / bibliothèques_consoles / etc / prometheus
vagrant @ vagrant: / htdocs / share $ sudo chown -R prometheus: prometheus / etc / prometheus / consoles
vagrant @ vagrant: / htdocs / share $ sudo chown -R prometheus: prometheus / etc / prometheus / console_libraries

 

 Ajouter une tâche de surveillance:

 Le contenu de /etc/prometheus/prometheus.yml est le suivant:

global:
  scrape_interval: 15s

scrape_configs:
  - nom_travail: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - cibles: ['localhost: 9090']
  - nom_travail: 'Mysql'
    static_configs:
      - cibles: ['192.168.0.200:9104']
        étiquettes:
          instance: '192.168. 0.200 '
  - nom_travail:' redis '
    static_configs:
      - cibles: [' 192.168.0.200:9121 ']
        étiquettes:
          instance:' 127.0.0.1 '


 

 Le contenu de /etc/systemd/system/prometheus.service est le suivant:

[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

[Installer]
WantedBy = multi-user.target
 

Enregistrez la configuration de redémarrage:

vagrant @ vagrant: / htdocs / share $ sudo systemctl daemon-reload

vagrant @ vagrant: / htdocs / share $ sudo systemctl start prometheus
vagrant @ vagrant: / htdocs / share $ sudo systemctl activer prometheus

 Ouvrez la page d'accueil: http://192.168.0.200:3000

Mot de passe par défaut: admin / admin

 http://192.168.0.200:9090/graph

 Ajouter une source de données:

 Importez le modèle Kanban séparément:

 

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz

$ tar xvfz mysqld_exporter-0.11.0.linux-amd64.tar.gz

$ cd mysqld_exporter-0.11.0.linux-amd64/

$ sudo vim my.cnf

Le contenu est le suivant:

[client]
user =
mot de passe de l' exportateur = 123456
port = 3306

Après l'enregistrement, exécutez:

nohup ./mysqld_exporter --config.my-cnf = "mon.cnf" &


Télécharger:

wget https://github.com/oliver006/redis_exporter/releases/download/v0.13/redis_exporter-v0.13.l

Décompressez:

tar -xvf  redis_exporter-v0.13.linux-amd64.tar.gz

Téléchargez le modèle prometheus-redis_rev1.json du redis de grafana:

wget  https://grafana.com/api/dashboards/763/revisions/1/download

Importez le modèle json dans grafana:

 

Démarrez redis_exporter:

## 无密码
./redis_exporter redis//192.168.0.200:6379 &
## 有密码
./redis_exporter  -redis.addr 192.168.0.200:6379  -redis.password 123456 

 

Téléchargez my2.sql:

git clone  https://github.com/john1337/my2Collector.git 

Une fois le téléchargement terminé, importez la base de données.

 Vous pouvez voir ces moniteurs dans Kanban:

 

 

Je suppose que tu aimes

Origine blog.csdn.net/lchmyhua88/article/details/107664342
conseillé
Classement