Projet final
Table des matières
- Objectifs du projet
- Architecture cible
- Étape 1 : Infrastructure
- Étape 2 : Sécurisation
- Étape 3 : Haute disponibilité
- Étape 4 : Monitoring
- 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
| Exigence | Spécification |
|---|---|
| Disponibilité | 99.9% SLA |
| Sécurité | Hardening complet |
| Monitoring | Alertes temps réel |
| Backup | RPO 1h, RTO 4h |
| Logs | Centralisé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
| Composant | Technologie | Quantité |
|---|---|---|
| Load Balancer | HAProxy + Keepalived | 2 |
| Web Server | Nginx + PHP-FPM | 2 |
| Database | PostgreSQL | 2 |
| Monitoring | Prometheus + Grafana | 1 |
| Logs | Loki | 1 |
🔝 Retour à la table des matières
3 - Étape 1 : Infrastructure
Tâches
- Provisioning : Créer les VMs (KVM ou LXD)
- Réseau : Configurer le réseau interne
- 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
- Hardening : Appliquer les mesures de sécurité
- Firewall : Configurer iptables/ufw
- 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