Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| eadl:bloc5:fm3:td1 [2026/09/12 00:02] – créée jcheron | eadl:bloc5:fm3:td1 [2026/09/12 00:20] (Version actuelle) – jcheron | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== TD1 — De Spark à Hadoop : stocker et traiter des données avec HDFS et YARN ====== | ====== TD1 — De Spark à Hadoop : stocker et traiter des données avec HDFS et YARN ====== | ||
| - | **Durée :** 4 heures | + | * **Durée :** 4 heures |
| - | **Travail :** binôme | + | |
| - | **Environnement :** Docker Compose, Hadoop, HDFS, YARN | + | |
| ===== 1. Contexte ===== | ===== 1. Contexte ===== | ||
| Ligne 43: | Ligne 43: | ||
| ===== 3. Architecture utilisée ===== | ===== 3. Architecture utilisée ===== | ||
| - | <code> | + | <sxh> |
| | | ||
| | ResourceManager | | | ResourceManager | | ||
| Ligne 62: | Ligne 62: | ||
| | Métadonnées HDFS| | | Métadonnées HDFS| | ||
| | | ||
| - | </code> | + | </sxh> |
| ^ Composant ^ Rôle ^ | ^ Composant ^ Rôle ^ | ||
| Ligne 85: | Ligne 85: | ||
| Vérifier l’installation : | Vérifier l’installation : | ||
| - | <code bash> | + | <sxh bash> |
| docker --version | docker --version | ||
| docker compose version | docker compose version | ||
| git --version | git --version | ||
| - | </code> | + | </sxh> |
| Une dizaine de gigaoctets d’espace disque libre est recommandée. | Une dizaine de gigaoctets d’espace disque libre est recommandée. | ||
| Ligne 97: | Ligne 97: | ||
| Nous utilisons une image Docker Hadoop préconfigurée pour un environnement pédagogique. | Nous utilisons une image Docker Hadoop préconfigurée pour un environnement pédagogique. | ||
| - | <code bash> | + | <sxh bash> |
| git clone https:// | git clone https:// | ||
| cd docker-hadoop | cd docker-hadoop | ||
| - | </code> | + | </sxh> |
| Démarrer l’environnement : | Démarrer l’environnement : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose up -d | docker compose up -d | ||
| - | </code> | + | </sxh> |
| Vérifier l’état des conteneurs : | Vérifier l’état des conteneurs : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose ps | docker compose ps | ||
| - | </code> | + | </sxh> |
| Vous devez retrouver notamment des services proches de : | Vous devez retrouver notamment des services proches de : | ||
| - | <code> | + | <sxh> |
| namenode | namenode | ||
| datanode | datanode | ||
| Ligne 122: | Ligne 122: | ||
| nodemanager | nodemanager | ||
| historyserver | historyserver | ||
| - | </code> | + | </sxh> |
| ==== 4.3 Interfaces web ==== | ==== 4.3 Interfaces web ==== | ||
| Ligne 135: | Ligne 135: | ||
| Pour ouvrir un terminal dans le NameNode : | Pour ouvrir un terminal dans le NameNode : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose exec namenode bash | docker compose exec namenode bash | ||
| - | </code> | + | </sxh> |
| Pour ouvrir un terminal dans le ResourceManager : | Pour ouvrir un terminal dans le ResourceManager : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose exec resourcemanager bash | docker compose exec resourcemanager bash | ||
| - | </code> | + | </sxh> |
| Les commandes Hadoop sont exécutées dans le conteneur '' | Les commandes Hadoop sont exécutées dans le conteneur '' | ||
| Ligne 153: | Ligne 153: | ||
| On considère l’architecture suivante : | On considère l’architecture suivante : | ||
| - | <code> | + | <sxh> |
| Serveur unique | Serveur unique | ||
| | | | | ||
| Ligne 160: | Ligne 160: | ||
| +-- clics_j1.csv | +-- clics_j1.csv | ||
| +-- application.log | +-- application.log | ||
| - | </code> | + | </sxh> |
| Répondre aux questions suivantes : | Répondre aux questions suivantes : | ||
| Ligne 178: | Ligne 178: | ||
| Sur votre machine hôte, créer un fichier '' | Sur votre machine hôte, créer un fichier '' | ||
| - | <code python> | + | <sxh python> |
| import csv | import csv | ||
| import random | import random | ||
| Ligne 215: | Ligne 215: | ||
| montant | montant | ||
| ]) | ]) | ||
| - | </code> | + | </sxh> |
| Exécuter : | Exécuter : | ||
| - | <code bash> | + | <sxh bash> |
| python generer_donnees.py | python generer_donnees.py | ||
| - | </code> | + | </sxh> |
| Observer la taille du fichier : | Observer la taille du fichier : | ||
| - | <code bash> | + | <sxh bash> |
| ls -lh ventes.csv | ls -lh ventes.csv | ||
| wc -l ventes.csv | wc -l ventes.csv | ||
| head ventes.csv | head ventes.csv | ||
| - | </code> | + | </sxh> |
| Répondre : | Répondre : | ||
| Ligne 244: | Ligne 244: | ||
| Dans le conteneur '' | Dans le conteneur '' | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -mkdir -p / | hdfs dfs -mkdir -p / | ||
| hdfs dfs -mkdir -p / | hdfs dfs -mkdir -p / | ||
| hdfs dfs -mkdir -p / | hdfs dfs -mkdir -p / | ||
| - | </code> | + | </sxh> |
| Depuis la machine hôte, copier le fichier dans le conteneur : | Depuis la machine hôte, copier le fichier dans le conteneur : | ||
| - | <code bash> | + | <sxh bash> |
| docker cp ventes.csv docker-hadoop-namenode-1:/ | docker cp ventes.csv docker-hadoop-namenode-1:/ | ||
| - | </code> | + | </sxh> |
| Le nom exact du conteneur peut être vérifié avec : | Le nom exact du conteneur peut être vérifié avec : | ||
| - | <code bash> | + | <sxh bash> |
| docker ps | docker ps | ||
| - | </code> | + | </sxh> |
| Dans le conteneur '' | Dans le conteneur '' | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -put / | hdfs dfs -put / | ||
| - | </code> | + | </sxh> |
| Vérifier la présence du fichier : | Vérifier la présence du fichier : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -ls -h / | hdfs dfs -ls -h / | ||
| - | </code> | + | </sxh> |
| Afficher quelques lignes : | Afficher quelques lignes : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -cat / | hdfs dfs -cat / | ||
| - | </code> | + | </sxh> |
| Répondre : | Répondre : | ||
| Ligne 291: | Ligne 291: | ||
| Exécuter : | Exécuter : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs fsck / | hdfs fsck / | ||
| -files \ | -files \ | ||
| -blocks \ | -blocks \ | ||
| -locations | -locations | ||
| - | </code> | + | </sxh> |
| Relever : | Relever : | ||
| Ligne 327: | Ligne 327: | ||
| Dans '' | Dans '' | ||
| - | <code> | + | <sxh> |
| HDFS_CONF_dfs_blocksize=1048576 | HDFS_CONF_dfs_blocksize=1048576 | ||
| HDFS_CONF_dfs_replication=2 | HDFS_CONF_dfs_replication=2 | ||
| - | </code> | + | </sxh> |
| Cette configuration correspond à : | Cette configuration correspond à : | ||
| Ligne 339: | Ligne 339: | ||
| Reconstruire l’environnement : | Reconstruire l’environnement : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose down -v | docker compose down -v | ||
| docker compose up -d | docker compose up -d | ||
| - | </code> | + | </sxh> |
| > Cette étape supprime les volumes Docker associés au cluster. | > Cette étape supprime les volumes Docker associés au cluster. | ||
| Ligne 350: | Ligne 350: | ||
| Relancer : | Relancer : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs fsck / | hdfs fsck / | ||
| -files \ | -files \ | ||
| -blocks \ | -blocks \ | ||
| -locations | -locations | ||
| - | </code> | + | </sxh> |
| Dessiner un schéma représentant la répartition des blocs. | Dessiner un schéma représentant la répartition des blocs. | ||
| Ligne 361: | Ligne 361: | ||
| Exemple : | Exemple : | ||
| - | <code> | + | <sxh> |
| ventes.csv | ventes.csv | ||
| | | | | ||
| Ligne 367: | Ligne 367: | ||
| +-- Bloc 1 -> DataNode 2, DataNode 3 | +-- Bloc 1 -> DataNode 2, DataNode 3 | ||
| +-- Bloc 2 -> DataNode 1, DataNode 3 | +-- Bloc 2 -> DataNode 1, DataNode 3 | ||
| - | </code> | + | </sxh> |
| ====== Mission 5 — Comprendre la réplication ====== | ====== Mission 5 — Comprendre la réplication ====== | ||
| Ligne 375: | Ligne 375: | ||
| Vérifier le facteur de réplication : | Vérifier le facteur de réplication : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs fsck / | hdfs fsck / | ||
| -files \ | -files \ | ||
| -blocks \ | -blocks \ | ||
| -locations | -locations | ||
| - | </code> | + | </sxh> |
| Modifier la réplication du fichier : | Modifier la réplication du fichier : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -setrep -w 3 \ | hdfs dfs -setrep -w 3 \ | ||
| / | / | ||
| - | </code> | + | </sxh> |
| Vérifier le résultat : | Vérifier le résultat : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs fsck / | hdfs fsck / | ||
| -files \ | -files \ | ||
| -blocks \ | -blocks \ | ||
| -locations | -locations | ||
| - | </code> | + | </sxh> |
| Répondre : | Répondre : | ||
| Ligne 413: | Ligne 413: | ||
| Dans le conteneur '' | Dans le conteneur '' | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfsadmin -report | hdfs dfsadmin -report | ||
| - | </code> | + | </sxh> |
| Relever : | Relever : | ||
| Ligne 426: | Ligne 426: | ||
| Depuis la machine hôte : | Depuis la machine hôte : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose ps | docker compose ps | ||
| - | </code> | + | </sxh> |
| Identifier le conteneur correspondant à un DataNode. | Identifier le conteneur correspondant à un DataNode. | ||
| Ligne 436: | Ligne 436: | ||
| Arrêter un DataNode : | Arrêter un DataNode : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose stop datanode | docker compose stop datanode | ||
| - | </code> | + | </sxh> |
| Si plusieurs DataNodes portent un suffixe : | Si plusieurs DataNodes portent un suffixe : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose stop datanode1 | docker compose stop datanode1 | ||
| - | </code> | + | </sxh> |
| ou : | ou : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose stop datanode2 | docker compose stop datanode2 | ||
| - | </code> | + | </sxh> |
| Vérifier l’état : | Vérifier l’état : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose ps | docker compose ps | ||
| - | </code> | + | </sxh> |
| Puis : | Puis : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfsadmin -report | hdfs dfsadmin -report | ||
| - | </code> | + | </sxh> |
| Examiner le fichier : | Examiner le fichier : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs fsck / | hdfs fsck / | ||
| -files \ | -files \ | ||
| -blocks \ | -blocks \ | ||
| -locations | -locations | ||
| - | </code> | + | </sxh> |
| Lire le fichier : | Lire le fichier : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -cat / | hdfs dfs -cat / | ||
| - | </code> | + | </sxh> |
| Répondre : | Répondre : | ||
| Ligne 489: | Ligne 489: | ||
| Redémarrer le DataNode : | Redémarrer le DataNode : | ||
| - | <code bash> | + | <sxh bash> |
| docker compose start datanode | docker compose start datanode | ||
| - | </code> | + | </sxh> |
| Puis vérifier : | Puis vérifier : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfsadmin -report | hdfs dfsadmin -report | ||
| - | </code> | + | </sxh> |
| ====== Mission 7 — Comprendre YARN ====== | ====== Mission 7 — Comprendre YARN ====== | ||
| Ligne 520: | Ligne 520: | ||
| Dans le conteneur '' | Dans le conteneur '' | ||
| - | <code bash> | + | <sxh bash> |
| yarn node -list | yarn node -list | ||
| - | </code> | + | </sxh> |
| Afficher les applications : | Afficher les applications : | ||
| - | <code bash> | + | <sxh bash> |
| yarn application -list | yarn application -list | ||
| - | </code> | + | </sxh> |
| Afficher les informations du cluster : | Afficher les informations du cluster : | ||
| - | <code bash> | + | <sxh bash> |
| yarn cluster | yarn cluster | ||
| - | </code> | + | </sxh> |
| Consulter l’interface : | Consulter l’interface : | ||
| - | <code> | + | <sxh> |
| http:// | http:// | ||
| - | </code> | + | </sxh> |
| Identifier : | Identifier : | ||
| Ligne 564: | Ligne 564: | ||
| Rechercher les exemples MapReduce : | Rechercher les exemples MapReduce : | ||
| - | <code bash> | + | <sxh bash> |
| find / -name " | find / -name " | ||
| - | </code> | + | </sxh> |
| Créer un petit fichier texte dans HDFS : | Créer un petit fichier texte dans HDFS : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -mkdir -p / | hdfs dfs -mkdir -p / | ||
| hdfs dfs -put /etc/hosts / | hdfs dfs -put /etc/hosts / | ||
| - | </code> | + | </sxh> |
| Lancer '' | Lancer '' | ||
| - | <code bash> | + | <sxh bash> |
| hadoop jar \ | hadoop jar \ | ||
| / | / | ||
| Ligne 583: | Ligne 583: | ||
| / | / | ||
| / | / | ||
| - | </code> | + | </sxh> |
| Si le répertoire existe déjà : | Si le répertoire existe déjà : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -rm -r / | hdfs dfs -rm -r / | ||
| - | </code> | + | </sxh> |
| Afficher le résultat : | Afficher le résultat : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -cat / | hdfs dfs -cat / | ||
| - | </code> | + | </sxh> |
| Pendant l’exécution, | Pendant l’exécution, | ||
| - | <code bash> | + | <sxh bash> |
| yarn application -list | yarn application -list | ||
| - | </code> | + | </sxh> |
| Puis : | Puis : | ||
| - | <code bash> | + | <sxh bash> |
| yarn application -list -appStates ALL | yarn application -list -appStates ALL | ||
| - | </code> | + | </sxh> |
| Répondre : | Répondre : | ||
| Ligne 624: | Ligne 624: | ||
| Le code suivant correspond à un traitement Spark : | Le code suivant correspond à un traitement Spark : | ||
| - | <code python> | + | <sxh python> |
| df = spark.read \ | df = spark.read \ | ||
| .option(" | .option(" | ||
| Ligne 632: | Ligne 632: | ||
| df.printSchema() | df.printSchema() | ||
| df.show(5) | df.show(5) | ||
| - | </code> | + | </sxh> |
| Comparer avec : | Comparer avec : | ||
| - | <code python> | + | <sxh python> |
| spark.read.csv(" | spark.read.csv(" | ||
| - | </code> | + | </sxh> |
| Répondre : | Répondre : | ||
| Ligne 652: | Ligne 652: | ||
| Créer '' | Créer '' | ||
| - | <code python> | + | <sxh python> |
| from pyspark.sql import SparkSession | from pyspark.sql import SparkSession | ||
| from pyspark.sql.functions import sum, count, avg | from pyspark.sql.functions import sum, count, avg | ||
| Ligne 687: | Ligne 687: | ||
| spark.stop() | spark.stop() | ||
| - | </code> | + | </sxh> |
| Selon l’environnement Spark disponible : | Selon l’environnement Spark disponible : | ||
| - | <code bash> | + | <sxh bash> |
| spark-submit \ | spark-submit \ | ||
| --master yarn \ | --master yarn \ | ||
| Ligne 698: | Ligne 698: | ||
| --executor-memory 1G \ | --executor-memory 1G \ | ||
| analyse_ventes.py | analyse_ventes.py | ||
| - | </code> | + | </sxh> |
| Observer l’application : | Observer l’application : | ||
| - | <code bash> | + | <sxh bash> |
| yarn application -list | yarn application -list | ||
| - | </code> | + | </sxh> |
| Vérifier le résultat : | Vérifier le résultat : | ||
| - | <code bash> | + | <sxh bash> |
| hdfs dfs -ls / | hdfs dfs -ls / | ||
| - | </code> | + | </sxh> |
| Les fichiers Parquet doivent être relus avec Spark plutôt qu’avec '' | Les fichiers Parquet doivent être relus avec Spark plutôt qu’avec '' | ||
| Ligne 718: | Ligne 718: | ||
| Compléter : | Compléter : | ||
| - | <code> | + | <sxh> |
| Fichier de ventes | Fichier de ventes | ||
| | | | | ||
| Ligne 740: | Ligne 740: | ||
| v | v | ||
| Résultats stockés dans HDFS | Résultats stockés dans HDFS | ||
| - | </code> | + | </sxh> |
| Associer chaque composant à son rôle : | Associer chaque composant à son rôle : | ||
| - | <code> | + | <sxh> |
| HDFS | HDFS | ||
| YARN | YARN | ||
| Ligne 752: | Ligne 752: | ||
| Spark | Spark | ||
| MapReduce | MapReduce | ||
| - | </code> | + | </sxh> |
| ====== Travail à rendre ====== | ====== Travail à rendre ====== | ||
| Ligne 802: | Ligne 802: | ||
| ====== Commandes utiles ====== | ====== Commandes utiles ====== | ||
| - | <code bash> | + | <sxh bash> |
| # État des conteneurs | # État des conteneurs | ||
| docker compose ps | docker compose ps | ||
| Ligne 838: | Ligne 838: | ||
| # Applications terminées | # Applications terminées | ||
| yarn application -list -appStates ALL | yarn application -list -appStates ALL | ||
| - | </code> | + | </sxh> |
| ====== Schéma final à retenir ====== | ====== Schéma final à retenir ====== | ||
| - | <code> | + | <sxh> |
| YARN | YARN | ||
| | | ||
| Ligne 861: | Ligne 861: | ||
| | Blocs et réplication | | Blocs et réplication | ||
| | | ||
| - | </code> | + | </sxh> |
| **HDFS stocke. YARN organise les ressources. Spark ou MapReduce traite.** | **HDFS stocke. YARN organise les ressources. Spark ou MapReduce traite.** | ||