Aller au contenu principal

Projet final


Table des matières

  1. Objectifs du projet
  2. Architecture cible
  3. Étape 1 : Infrastructure
  4. Étape 2 : Sécurisation
  5. Étape 3 : Haute disponibilité
  6. Étape 4 : Monitoring
  7. Validation et certification


1 - Objectifs du projet

Contexte

Vous devez mettre en place une infrastructure web hautement disponible pour une application d'e-commerce.

Exigences

ExigenceSpécification
Disponibilité99.9% SLA
SécuritéHardening complet
MonitoringAlertes temps réel
BackupRPO 1h, RTO 4h
LogsCentralisés

Compétences évaluées

  • ✅ Administration système avancée
  • ✅ Sécurisation et hardening
  • ✅ Haute disponibilité
  • ✅ Monitoring et alerting
  • ✅ Automatisation
  • ✅ Troubleshooting

🔝 Retour à la table des matières



2 - Architecture cible

Diagramme

Composants

ComposantTechnologieQuantité
Load BalancerHAProxy + Keepalived2
Web ServerNginx + PHP-FPM2
DatabasePostgreSQL2
MonitoringPrometheus + Grafana1
LogsLoki1

🔝 Retour à la table des matières



3 - Étape 1 : Infrastructure

Tâches

  1. Provisioning : Créer les VMs (KVM ou LXD)
  2. Réseau : Configurer le réseau interne
  3. Installation : Installer les services de base

Script de création LXD

#!/bin/bash
# create-infra.sh

set -euo pipefail

# Créer le réseau
lxc network create infra-net ipv4.address=10.0.0.1/24 ipv4.nat=true

# Load Balancers
lxc launch ubuntu:22.04 lb1 --network infra-net
lxc launch ubuntu:22.04 lb2 --network infra-net

# Web Servers
lxc launch ubuntu:22.04 web1 --network infra-net
lxc launch ubuntu:22.04 web2 --network infra-net

# Database
lxc launch ubuntu:22.04 db1 --network infra-net
lxc launch ubuntu:22.04 db2 --network infra-net

# Monitoring
lxc launch ubuntu:22.04 monitor --network infra-net

echo "Infrastructure créée"
lxc list

Checklist Étape 1

  • VMs/Conteneurs créés
  • Réseau configuré
  • Connectivité SSH
  • Hostnames configurés
  • /etc/hosts synchronisé

🔝 Retour à la table des matières



4 - Étape 2 : Sécurisation

Tâches

  1. Hardening : Appliquer les mesures de sécurité
  2. Firewall : Configurer iptables/ufw
  3. SSH : Sécuriser les accès

Script de hardening

#!/bin/bash
# hardening.sh

set -euo pipefail

echo "=== Hardening du système ==="

# Mises à jour
apt update && apt upgrade -y

# SSH Hardening
cat >> /etc/ssh/sshd_config << 'EOF'
PermitRootLogin no
PasswordAuthentication no
X11Forwarding no
MaxAuthTries 3
EOF
systemctl restart sshd

# Sysctl hardening
cat > /etc/sysctl.d/99-hardening.conf << 'EOF'
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.tcp_syncookies = 1
kernel.randomize_va_space = 2
EOF
sysctl -p /etc/sysctl.d/99-hardening.conf

# Firewall de base
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw --force enable

# Fail2ban
apt install -y fail2ban
systemctl enable fail2ban

echo "=== Hardening terminé ==="

Checklist Étape 2

  • SSH sécurisé (clés only, no root)
  • Firewall configuré
  • Fail2ban actif
  • Sysctl hardening appliqué
  • Mises à jour automatiques

🔝 Retour à la table des matières



5 - Étape 3 : Haute disponibilité

HAProxy + Keepalived

# /etc/haproxy/haproxy.cfg (sur lb1 et lb2)
global
daemon
maxconn 4096

defaults
mode http
timeout connect 5s
timeout client 50s
timeout server 50s
option httplog
option httpchk GET /health

frontend http_front
bind *:80
default_backend web_back

backend web_back
balance roundrobin
server web1 10.0.0.11:80 check
server web2 10.0.0.12:80 check

listen stats
bind *:8404
stats enable
stats uri /stats
stats auth admin:secure_password
# /etc/keepalived/keepalived.conf (lb1 - MASTER)
vrrp_script check_haproxy {
script "/usr/bin/killall -0 haproxy"
interval 2
weight 2
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101

authentication {
auth_type PASS
auth_pass secure_pass
}

virtual_ipaddress {
10.0.0.100/24
}

track_script {
check_haproxy
}
}

PostgreSQL Replication

# Sur db1 (Primary)
# postgresql.conf
wal_level = replica
max_wal_senders = 3
wal_keep_size = 64MB

# pg_hba.conf
host replication replicator 10.0.0.0/24 md5

# Créer l'utilisateur
sudo -u postgres psql -c "CREATE USER replicator REPLICATION LOGIN PASSWORD 'secure';"

# Sur db2 (Replica)
pg_basebackup -h db1 -D /var/lib/postgresql/14/main -U replicator -P

# postgresql.conf
primary_conninfo = 'host=db1 user=replicator password=secure'

Checklist Étape 3

  • HAProxy configuré sur lb1 et lb2
  • Keepalived VIP fonctionnelle
  • Failover LB testé
  • Réplication PostgreSQL active
  • Application déployée sur web1 et web2

🔝 Retour à la table des matières



6 - Étape 4 : Monitoring

Prometheus

# /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'nodes'
static_configs:
- targets:
- 'lb1:9100'
- 'lb2:9100'
- 'web1:9100'
- 'web2:9100'
- 'db1:9100'
- 'db2:9100'

- job_name: 'haproxy'
static_configs:
- targets: ['lb1:8404', 'lb2:8404']

Alertes

# /etc/prometheus/alerts.yml
groups:
- name: infra
rules:
- alert: InstanceDown
expr: up == 0
for: 1m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.instance }} down"

- alert: HighCPU
expr: 100 - (avg by(instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU on {{ $labels.instance }}"

- alert: DiskSpaceLow
expr: (node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100 < 20
for: 5m
labels:
severity: warning
annotations:
summary: "Low disk space on {{ $labels.instance }}"

Checklist Étape 4

  • Node exporter sur tous les serveurs
  • Prometheus collecte les métriques
  • Grafana dashboards configurés
  • Alertes fonctionnelles
  • Logs centralisés

🔝 Retour à la table des matières



7 - Validation et certification

Tests de validation

TestCommande/ActionRésultat attendu
Failover LBStop HAProxy sur lb1VIP bascule vers lb2
Failover WebStop web1Trafic continue sur web2
Failover DBStop db1Application continue (lecture)
BackupRestaurer un backupDonnées intactes
MonitoringCréer un incidentAlerte reçue

Script de validation

#!/bin/bash
# validate.sh

echo "=== Tests de validation ==="

# Test connectivité VIP
echo -n "VIP accessible: "
curl -sf http://10.0.0.100/health && echo "OK" || echo "FAIL"

# Test HAProxy stats
echo -n "HAProxy stats: "
curl -sf http://lb1:8404/stats > /dev/null && echo "OK" || echo "FAIL"

# Test réplication DB
echo -n "DB Replication: "
lxc exec db2 -- sudo -u postgres psql -c "SELECT pg_is_in_recovery();" | grep -q "t" && echo "OK" || echo "FAIL"

# Test Prometheus
echo -n "Prometheus UP: "
curl -sf http://monitor:9090/-/healthy && echo "OK" || echo "FAIL"

echo "=== Tests terminés ==="

Critères de certification

Pour valider ce projet, vous devez :

  1. ✅ Infrastructure fonctionnelle
  2. ✅ Hardening appliqué
  3. ✅ HA testée et fonctionnelle
  4. ✅ Monitoring avec alertes
  5. ✅ Documentation complète
  6. ✅ Procédures de backup/restore testées

Félicitations !

Vous avez terminé le parcours Linux 5 - Administration Avancée ! 🎉

Vous êtes maintenant capable de :

  • Administrer des systèmes Linux en production
  • Sécuriser et hardener des serveurs
  • Mettre en place de la haute disponibilité
  • Monitorer et diagnostiquer des problèmes complexes
  • Automatiser des tâches avancées

Prochaines étapes

  • Pratiquez sur des projets réels
  • Passez une certification (RHCSA, LFCS)
  • Explorez Kubernetes et le cloud

← Retour à la table des matières du cours