Aller au contenu principal

Troubleshooting et diagnostic


Table des matières

  1. Méthodologie de diagnostic
  2. Problèmes de boot
  3. Problèmes de performance
  4. Problèmes réseau
  5. Problèmes applicatifs
  6. Exercices pratiques


1 - Méthodologie de diagnostic

Approche structurée

Questions à se poser

  1. Quoi - Quel est le symptôme exact ?
  2. Quand - Depuis quand ? Après quel changement ?
  3. Qui - Tous les utilisateurs ? Un seul ?
  4. - Un serveur ? Tous ?
  5. Comment - Comment reproduire ?

Outils essentiels

DomaineOutils
Systèmedmesg, journalctl, top, htop
Processusps, strace, lsof
Réseauss, tcpdump, ping, traceroute
Disquedf, du, iostat, iotop
Mémoirefree, vmstat, /proc/meminfo

Checklist de premier niveau

# État général
uptime
free -h
df -h
dmesg | tail -50
journalctl -p err --since "1 hour ago"

# Processus
top -bn1 | head -20
ps aux --sort=-%cpu | head -10

# Réseau
ss -tunapl
ping -c 3 google.com

# Services critiques
systemctl --failed

🔝 Retour à la table des matières



2 - Problèmes de boot

Symptômes courants

SymptômeCause possible
Kernel panicModule corrompu, hardware
Stuck at GRUBConfig GRUB invalide
Emergency modefstab incorrect, fs corrompu
Black screenDriver graphique

Mode recovery

# Au boot GRUB, éditer l'entrée (e)
# Ajouter à la ligne linux:
systemd.unit=rescue.target
# ou
init=/bin/bash

# Puis Ctrl+X pour booter

Réparer GRUB

# Depuis un live USB
mount /dev/sda2 /mnt
mount /dev/sda1 /mnt/boot/efi # Si UEFI
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

chroot /mnt
grub-install /dev/sda
update-grub
exit

umount -R /mnt
reboot

Réparer fstab

# En mode recovery, remonter en RW
mount -o remount,rw /

# Éditer fstab
nano /etc/fstab

# Commenter la ligne problématique
# /dev/sdb1 /data ext4 defaults 0 0

# Ou utiliser nofail
/dev/sdb1 /data ext4 defaults,nofail 0 0

Vérifier le filesystem

# Depuis recovery (FS démonté)
fsck -y /dev/sda2

# Forcer au prochain boot
touch /forcefsck

🔝 Retour à la table des matières



3 - Problèmes de performance

Diagnostic CPU

# Identifier les processus CPU
top -b -n1 -o %CPU | head -15

# Processus en état D (I/O wait)
ps aux | awk '$8 ~ /D/'

# Interruptions
cat /proc/interrupts

# Profiling avec perf
perf top
perf record -g -p PID
perf report

Diagnostic mémoire

# Vue mémoire
free -h
cat /proc/meminfo

# Processus consommateurs
ps aux --sort=-%mem | head

# OOM killer
dmesg | grep -i "out of memory"
journalctl | grep -i oom

# Cache pressure
vmstat 1
# Si si/so élevés = swapping

Diagnostic I/O

# I/O par processus
iotop -oP

# Statistiques disque
iostat -xz 1

# Colonnes importantes:
# await : latence moyenne
# %util : saturation

# Queue I/O
cat /sys/block/sda/queue/nr_requests

# Fichiers ouverts
lsof +D /var/log

Diagnostic réseau

# Connexions
ss -tunapl | wc -l
ss -s

# Trafic par interface
sar -n DEV 1

# Paquets droppés
netstat -i
cat /proc/net/dev

# Congestion
ss -ti

🔝 Retour à la table des matières



4 - Problèmes réseau

Pas de connectivité

# 1. Interface UP ?
ip link show
ip addr show

# 2. IP configurée ?
ip addr show eth0

# 3. Route par défaut ?
ip route show
ip route get 8.8.8.8

# 4. DNS ?
cat /etc/resolv.conf
nslookup google.com
dig google.com

# 5. Firewall ?
iptables -L -n
ufw status

Port non accessible

# Service écoute ?
ss -tlnp | grep :80
netstat -tlnp | grep :80

# Firewall local ?
iptables -L INPUT -n --line-numbers

# Firewall distant ?
nmap -p 80 target

# Test connexion
telnet target 80
nc -zv target 80

Capture de trafic

# Tout le trafic sur une interface
tcpdump -i eth0

# Port spécifique
tcpdump -i eth0 port 80

# Avec détails
tcpdump -i eth0 -nn -A port 80

# Sauvegarder
tcpdump -i eth0 -w capture.pcap

# Analyser
tcpdump -r capture.pcap

Debug DNS

# Test résolution
dig example.com
nslookup example.com

# DNS spécifique
dig @8.8.8.8 example.com

# Trace
dig +trace example.com

# Cache DNS local
systemd-resolve --status
systemd-resolve --flush-caches

🔝 Retour à la table des matières



5 - Problèmes applicatifs

Analyser un processus

# État du processus
ps aux | grep myapp
cat /proc/PID/status

# Fichiers ouverts
lsof -p PID

# Descripteurs de fichiers
ls -la /proc/PID/fd/

# Limites
cat /proc/PID/limits

# Mémoire mappée
pmap -x PID
cat /proc/PID/maps

Tracer les appels système

# Tracer un processus
strace -p PID

# Tracer une commande
strace -f -e trace=network ./myapp

# Avec timing
strace -T -p PID

# Résumé
strace -c -p PID
# Ctrl+C pour voir les stats

Analyser les logs applicatifs

# Suivre en temps réel
tail -f /var/log/myapp/app.log

# Chercher les erreurs
grep -i error /var/log/myapp/app.log | tail -50

# Compter par type
grep -oE "(ERROR|WARN|INFO)" app.log | sort | uniq -c

# Timeline des erreurs
grep ERROR app.log | awk '{print $1, $2}' | uniq -c

Debug avec GDB

# Attacher à un processus
gdb -p PID

# Commandes GDB:
# bt - backtrace
# info threads - lister les threads
# thread N - sélectionner un thread
# continue - reprendre l'exécution

# Core dump
ulimit -c unlimited
gdb ./myapp core

Génération de core dump

# Activer
ulimit -c unlimited

# Configuration système
echo "/var/crash/core.%e.%p" > /proc/sys/kernel/core_pattern

# Forcer un core dump
kill -ABRT PID
gcore PID # Sans tuer

🔝 Retour à la table des matières



6 - Exercices pratiques

Exercice 1 : Diagnostic de lenteur

Un serveur web est lent. Trouvez la cause :

Approche
# 1. Vue d'ensemble
top
vmstat 1 5

# 2. Si CPU élevé
ps aux --sort=-%cpu | head

# 3. Si I/O wait élevé
iotop
iostat -xz 1

# 4. Si mémoire saturée
free -h
ps aux --sort=-%mem | head

# 5. Vérifier le service
systemctl status nginx
tail -f /var/log/nginx/error.log

Exercice 2 : Port non accessible

Le port 8080 n'est pas accessible depuis l'extérieur :

Approche
# 1. Service écoute ?
ss -tlnp | grep 8080

# 2. Écoute sur 0.0.0.0 ou 127.0.0.1 ?
ss -tlnp | grep 8080
# Si 127.0.0.1 -> problème de binding

# 3. Firewall ?
iptables -L INPUT -n | grep 8080
ufw status

# 4. Connexion locale OK ?
curl localhost:8080

# 5. SELinux ?
getenforce
ausearch -m avc -ts recent

Quiz

Q1. Quelle commande montre les processus en I/O wait ?

Réponse

ps aux | awk '$8 ~ /D/' ou top (regarder le %wa)

Q2. Comment tracer les appels système d'un processus ?

Réponse

strace -p PID

🔝 Retour à la table des matières



Points clés à retenir

  • Méthodologie : symptôme → collecte → hypothèses → test
  • dmesg et journalctl pour les logs système
  • top, vmstat, iostat pour la performance
  • ss, tcpdump pour le réseau
  • strace pour tracer les appels système
  • lsof pour les fichiers ouverts
  • Toujours documenter la résolution

🔝 Retour à la table des matières


← Chapitre précédent | Chapitre suivant : Projet final →