### 1. 实验一 Hadoop安装使用 #### 1.1 在PC机上以伪分布式模式安装Hadoop docker-comose伪集群定义 ```yaml networks: bigdata-net: driver: bridge volumes: namenode: datanode: services: # ---------------------------- # 1. HDFS 存储层 # ---------------------------- namenode: image: bde2020/hadoop-namenode:2.0.0-hadoop3.2.1-java8 container_name: namenode hostname: namenode restart: always ports: - "9870:9870" # HDFS Web UI - "9000:9000" # RPC env_file: - ./hadoop.env volumes: - namenode:/hadoop/dfs/name networks: - bigdata-net datanode: image: bde2020/hadoop-datanode:2.0.0-hadoop3.2.1-java8 container_name: datanode hostname: datanode restart: always environment: SERVICE_PRECONDITION: "namenode:9870 namenode:9000" env_file: - ./hadoop.env volumes: - datanode:/hadoop/dfs/data networks: - bigdata-net # ---------------------------- # 2. YARN 计算层 (MapReduce) # ---------------------------- resourcemanager: image: bde2020/hadoop-resourcemanager:2.0.0-hadoop3.2.1-java8 container_name: resourcemanager hostname: resourcemanager restart: always ports: - "8088:8088" # YARN Web UI environment: SERVICE_PRECONDITION: "namenode:9000 namenode:9870 datanode:9864" env_file: - ./hadoop.env networks: - bigdata-net nodemanager: image: bde2020/hadoop-nodemanager:2.0.0-hadoop3.2.1-java8 container_name: nodemanager hostname: nodemanager restart: always environment: SERVICE_PRECONDITION: "namenode:9000 namenode:9870 datanode:9864 resourcemanager:8088" env_file: - ./hadoop.env networks: - bigdata-net # ---------------------------- # 3. Zookeeper & HBase # ---------------------------- zookeeper: image: zookeeper:3.8 container_name: zookeeper hostname: zookeeper restart: always ports: - "2181:2181" networks: - bigdata-net hbase: # 这里的 latest 通常是 HBase 2.x 版本,兼容 Hadoop 3.2 image: harisekhon/hbase:latest container_name: hbase hostname: hbase restart: always ports: - "16010:16010" # HBase Web UI depends_on: - namenode - zookeeper environment: - HBASE_MANAGES_ZK=false - HBASE_ZOOKEEPER_QUORUM=zookeeper - HBASE_ROOTDIR=hdfs://namenode:9000/hbase # 等待 HDFS 和 ZK 启动后再启动 HBase - SERVICE_PRECONDITION=namenode:9000 zookeeper:2181 networks: - bigdata-net # ---------------------------- # 4. 全能工作台 (Client) # ---------------------------- client: image: bde2020/hadoop-base:2.0.0-hadoop3.2.1-java8 container_name: lab-client hostname: client restart: always volumes: - ./workspace:/workspace env_file: - ./hadoop.env networks: - bigdata-net environment: CORE_CONF_fs_defaultFS: hdfs://namenode:9000 YARN_CONF_yarn_resourcemanager_hostname: resourcemanager SERVICE_PRECONDITION: "namenode:9000 resourcemanager:8088 hbase:16010" command: tail -f /dev/null ``` `hadoop.env`环境 ```env CLUSTER_NAME=test CORE_CONF_fs_defaultFS=hdfs://namenode:9000 CORE_CONF_hadoop_http_staticuser_user=root CORE_CONF_hadoop_proxyuser_hue_hosts=* CORE_CONF_hadoop_proxyuser_hue_groups=* HDFS_CONF_dfs_webhdfs_enabled=true HDFS_CONF_dfs_permissions_enabled=false HDFS_CONF_dfs_replication=1 YARN_CONF_yarn_log_aggregation_enable=true YARN_CONF_yarn_resourcemanager_recovery_enabled=true YARN_CONF_yarn_resourcemanager_store_class=org.apache.hadoop.yarn.server.resourcemanager.recovery.FileSystemRMStateStore YARN_CONF_yarn_resourcemanager_fs_state_store_uri=/rmstate YARN_CONF_yarn_nodemanager_remote_app_log_dir=/app-logs YARN_CONF_yarn_log_aggregation_retain_seconds=-1 YARN_CONF_yarn_log_aggregation_retain_check_interval_seconds=-1 ``` 创建环境 ```shell docker compose up -d ``` #### 1.2 访问Web界面查看Hadoop信息 - **HDFS 管理界面**: [http://localhost:9870](https://www.google.com/search?q=http://localhost:9870) (查看 Datanode 信息) - **YARN 管理界面**: [http://localhost:8088](https://www.google.com/search?q=http://localhost:8088) (查看集群资源) - **HBase 管理界面**: [http://localhost:16010](https://www.google.com/search?q=http://localhost:16010) (查看 RegionServer) 在宿主机创建workspace目录 `~/Code/BD/workspace` - **进入容器**: `docker exec -it lab-client bash` --- ### 2. 实验二 HDFS编程实践 #### 2.1 使用HDFS文件操作的常用Shell命令 在1.3中进入容器后,在`root@client:/#`下逐行复制执行 ```shell # 在容器中进入workspace目录 cd /workspace # 创建用户目录 hdfs dfs -mkdir -p /user/root # 新建一个测试文件 echo "Hello CachyOS Hello Hadoop" > test.txt # 上传文件到 HDFS hdfs dfs -put test.txt /user/root/ # 查看文件内容 hdfs dfs -cat /user/root/test.txt # 查看目录列表 hdfs dfs -ls /user/root/ ``` #### 2.2 利用Hadoop提供的Java API进行基本的文件操作 在宿主机下创建文件 `~/Code/BD/workspace/HDFSTest.java` 由于java8编译器默认编码为ASCII,为避免麻烦文件中全部替换为中文 写入内容如下 ```java import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FileStatus; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URI; public class HDFSTest { // HDFS root URI private static final String HDFS_URI = "hdfs://namenode:9000"; private static FileSystem fs; public static void main(String[] args) { try { // 1. Initialize Configuration Configuration conf = new Configuration(); fs = FileSystem.get(URI.create(HDFS_URI), conf, "root"); // Define file paths Path filePath = new Path("/user/root/input/java_crud_test.txt"); Path renamedPath = new Path("/user/root/input/java_crud_renamed.txt"); System.out.println(">>> STARTING HDFS CRUD TEST <<<"); // 2. CREATE: Create a file and write data System.out.println("\n[1] TEST: Create & Write"); createFile(filePath, "Hello Hadoop! This is a test for CRUD operations."); // 3. READ: Read the content System.out.println("\n[2] TEST: Read"); readFile(filePath); // 4. UPDATE (Rename): Rename the file System.out.println("\n[3] TEST: Rename"); renameFile(filePath, renamedPath); // 5. LIST: Check file status System.out.println("\n[4] TEST: List File Status"); listFileStatus(renamedPath); // 6. DELETE: Delete the file System.out.println("\n[5] TEST: Delete"); deleteFile(renamedPath); System.out.println("\n>>> ALL TESTS PASSED SUCCESSFULLY! <<<"); fs.close(); } catch (Exception e) { e.printStackTrace(); } } // --- Helper Methods --- // Create and Write private static void createFile(Path path, String content) throws Exception { // overwrite = true FSDataOutputStream os = fs.create(path, true); os.write(content.getBytes()); os.close(); System.out.println(">>> Success: Created file " + path.toString()); } // Read private static void readFile(Path path) throws Exception { if (!fs.exists(path)) { System.out.println(">>> Error: File not found!"); return; } FSDataInputStream is = fs.open(path); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = br.readLine(); System.out.println(">>> Content: " + line); br.close(); is.close(); } // Rename private static void renameFile(Path oldPath, Path newPath) throws Exception { if (fs.rename(oldPath, newPath)) { System.out.println(">>> Success: Renamed " + oldPath.getName() + " to " + newPath.getName()); } else { System.out.println(">>> Error: Rename failed!"); } } // List Status private static void listFileStatus(Path path) throws Exception { FileStatus status = fs.getFileStatus(path); System.out.println(">>> File Path: " + status.getPath()); System.out.println(">>> Owner: " + status.getOwner()); System.out.println(">>> Size: " + status.getLen() + " bytes"); System.out.println(">>> Replication: " + status.getReplication()); } // Delete private static void deleteFile(Path path) throws Exception { // recursive = true (though not strictly needed for files) if (fs.delete(path, true)) { System.out.println(">>> Success: Deleted file " + path.toString()); } else { System.out.println(">>> Error: Delete failed!"); } } } ``` 这个程序将依次自动执行以下操作: 1. **Create (增)**:创建一个新文件并写入数据。 2. **Read (查)**:读取刚才写入的内容。 3. **Rename (改)**:将文件重命名(HDFS 中常见的修改操作)。 4. **List (查)**:查看文件的详细信息(大小、时间、副本数)。 5. **Delete (删)**:最后删除文件,清理现场。 **编译**: ```bash javac -cp `hadoop classpath` HdfsTest.java ``` **运行**: ```bash java -cp .:`hadoop classpath` HdfsTest ``` **结果**: ```shell root@client:/workspace# javac -cp `hadoop classpath` HDFSTest.java root@client:/workspace# java -cp .:`hadoop classpath` HDFSTest 2025-12-25 13:55:47,296 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable >>> STARTING HDFS CRUD TEST <<< [1] TEST: Create & Write 2025-12-25 13:55:47,979 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false >>> Success: Created file /user/root/input/java_crud_test.txt [2] TEST: Read 2025-12-25 13:55:48,140 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false >>> Content: Hello Hadoop! This is a test for CRUD operations. [3] TEST: Rename >>> Success: Renamed java_crud_test.txt to java_crud_renamed.txt [4] TEST: List File Status >>> File Path: hdfs://namenode:9000/user/root/input/java_crud_renamed.txt >>> Owner: root >>> Size: 49 bytes >>> Replication: 1 [5] TEST: Delete >>> Success: Deleted file /user/root/input/java_crud_renamed.txt >>> ALL TESTS PASSED SUCCESSFULLY! <<< root@client:/workspace# ``` ### 3. 实验三 HBase编程实践 #### 3.1 在Hadoop基础上安装HBase 已在docker-compose中预备好 #### 3.2 使用HBase Shell命令 ##### 3.2.1 Namespace 与 建表 (DDL) HBase 是列式数据库,建表时只需要指定 **Column Family (列族)**。 ```bash # 1. 查看当前状态 status 'detailed' # 2. 创建表 'student',包含两个列族:'info' (基本信息), 'score' (成绩) create 'student', 'info', 'score' # 3. 查看表结构 (Schema) describe 'student' # 4. 列出所有表 list ``` ##### 3.2.2 数据插入 HBase 是 Key-Value 存储,每一行必须有一个 **RowKey**。我们假设 RowKey 是学号。 ```bash # --- 插入第一个学生 (学号 1001) --- # 姓名 put 'student', '1001', 'info:name', 'Alice' # 班级 put 'student', '1001', 'info:class', 'CS-1' # 数学成绩 put 'student', '1001', 'score:math', '85' # 英语成绩 put 'student', '1001', 'score:english', '90' # --- 插入第二个学生 (学号 1002) --- put 'student', '1002', 'info:name', 'Bob' put 'student', '1002', 'info:class', 'CS-2' put 'student', '1002', 'score:math', '92' ``` ##### 3.2.3 数据查询 ```shell # 1. 查询全表数据 (扫描) scan 'student' # 2. 查询单行数据 (获取学号 1001 的所有信息) get 'student', '1001' # 3. 查询单行的特定列 (只看 Alice 的名字) get 'student', '1001', 'info:name' # 4. 查询单行的特定列族 (只看 Bob 的成绩) get 'student', '1002', 'score' ``` ##### 3.2.4 数据删除与清空 ```shell # 1. 删除一个单元格 (删除 Bob 的数学成绩) delete 'student', '1002', 'score:math' # 验证删除 (Bob 应该没有数学成绩了) get 'student', '1002' # 2. 删除整行 (删除 Bob 这个人) deleteall 'student', '1002' ``` ##### 3.2.5 删表操作 ```shell # 1. 禁用表 disable 'student' # 2. 删除表 drop 'student' # 3. 验证是否删除 list ``` #### 3.3 使用HBase常用Java API创建表、插入数据、浏览数据。 ```java import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.*; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor; import java.io.IOException; public class HBaseTest { public static void main(String[] args) { Connection connection = null; Admin admin = null; try { System.out.println(">>> 1. Initializing Configuration..."); Configuration config = HBaseConfiguration.create(); config.set("hbase.zookeeper.quorum", "zookeeper"); config.set("hbase.zookeeper.property.clientPort", "2181"); config.set("hbase.client.retries.number", "3"); System.out.println(">>> 2. Connecting to HBase..."); connection = ConnectionFactory.createConnection(config); admin = connection.getAdmin(); System.out.println(">>> Connection Success!"); TableName tableName = TableName.valueOf("student_java"); System.out.println(">>> 3. Checking Table..."); if (admin.tableExists(tableName)) { System.out.println(">>> Table exists, deleting it first (for test)..."); admin.disableTable(tableName); admin.deleteTable(tableName); } System.out.println(">>> Creating Table 'student_java'..."); TableDescriptorBuilder tableBuilder = TableDescriptorBuilder.newBuilder(tableName); ColumnFamilyDescriptor family = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("info")).build(); tableBuilder.setColumnFamily(family); admin.createTable(tableBuilder.build()); System.out.println(">>> Table Created!"); System.out.println(">>> 4. Inserting Data..."); Table table = connection.getTable(tableName); Put put = new Put(Bytes.toBytes("1001")); put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("name"), Bytes.toBytes("student")); put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("os"), Bytes.toBytes("CachyOS")); table.put(put); System.out.println(">>> Insert Success!"); System.out.println(">>> 5. Scanning Data..."); Scan scan = new Scan(); ResultScanner scanner = table.getScanner(scan); for (Result result : scanner) { System.out.println(">>> Found Row: " + result); String name = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("name"))); String os = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("os"))); System.out.println(" -> Name: " + name + ", OS: " + os); } scanner.close(); table.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (admin != null) admin.close(); if (connection != null) connection.close(); } catch (IOException e) { e.printStackTrace(); } } } } ``` **编译** ```shell javac -cp .:$(hadoop classpath):/workspace/hbase-lib/* HBaseTest.java ``` **运行**: ```shell java -cp .:$(hadoop classpath):/workspace/hbase-lib/* HBaseTest ``` ### 4. 实验四 MapReduce编程实践 使用MapReduce实现多个文本文件中WordCount词频统计功能,实验编写Map处理逻辑、编写Reduce处理逻辑、编写main方法。 #### 4.1 生成数据 ```shell # 1. 准备本地数据 (随便写点英文句子) echo "Hello Hadoop Hello MapReduce" > file1.txt echo "MapReduce is cool and Hadoop is powerful" > file2.txt echo "CachyOS runs Docker very fast" > file3.txt # 2. 在 HDFS 创建输入目录 hdfs dfs -mkdir -p /input # 3. 上传数据 hdfs dfs -put file1.txt file2.txt file3.txt /input/ # 4. 验证一下 hdfs dfs -ls /input/ ``` #### 4.2 编写代码 ```java import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class WordCount { // 1. Mapper 阶段 // 输入类型: (偏移量, 一行文本) // 输出类型: (单词, 1) public static class TokenizerMapper extends Mapper{ private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(Object key, Text value, Context context) throws IOException, InterruptedException { // 将读取的一行文本转换成 String StringTokenizer itr = new StringTokenizer(value.toString()); // 遍历每个单词 while (itr.hasMoreTokens()) { word.set(itr.nextToken()); // 输出: <单词, 1> context.write(word, one); } } } // 2. Reducer 阶段 // 输入类型: (Mapper 的输出) // 输出类型: (单词, 总次数) public static class IntSumReducer extends Reducer { private IntWritable result = new IntWritable(); public void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { int sum = 0; // 累加同一个单词出现的所有次数 for (IntWritable val : values) { sum += val.get(); } result.set(sum); // 输出最终统计结果 context.write(key, result); } } // 3. Driver 驱动阶段 public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "word count"); // 设置 Jar 包的主类 job.setJarByClass(WordCount.class); // 设置 Mapper 和 Reducer 类 job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); // Combiner 是 Mapper 端的小聚合,优化性能 job.setReducerClass(IntSumReducer.class); // 设置输出 Key-Value 类型 job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); // 设置输入和输出路径 (从命令行参数获取) FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); // 提交任务并等待完成 System.exit(job.waitForCompletion(true) ? 0 : 1); } } ``` #### 4.3 编译、打包、运行 **在容器终端** (`root@client:/workspace#`) 执行: ```shell # 0. 清理旧的 class 文件 rm -f *.class # 1. 编译 (Compile) javac -cp `hadoop classpath` WordCount.java # 2. 打包 (Jar) # 把编译好的 .class 文件打包成 wc.jar jar cf wc.jar WordCount*.class # 3. 运行 (Run) # 语法: hadoop jar <主类> # 注意: /output 目录必须是不存在的,Hadoop 会自动创建它 hadoop jar wc.jar WordCount /input /output ``` 输出结果 ```shell 2025-12-25 14:40:12,704 INFO impl.MetricsConfig: Loaded properties from hadoop-metrics2.properties 2025-12-25 14:40:12,775 INFO impl.MetricsSystemImpl: Scheduled Metric snapshot period at 10 second(s). 2025-12-25 14:40:12,775 INFO impl.MetricsSystemImpl: JobTracker metrics system started 2025-12-25 14:40:13,051 WARN mapreduce.JobResourceUploader: Hadoop command-line option parsing not performed. Implement the Tool interface and execute your application with ToolRunner to remedy this. 2025-12-25 14:40:13,226 INFO input.FileInputFormat: Total input files to process : 3 2025-12-25 14:40:13,264 INFO mapreduce.JobSubmitter: number of splits:3 2025-12-25 14:40:13,496 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_local2027701423_0001 2025-12-25 14:40:13,497 INFO mapreduce.JobSubmitter: Executing with tokens: [] 2025-12-25 14:40:13,693 INFO mapreduce.Job: The url to track the job: http://localhost:8080/ 2025-12-25 14:40:13,694 INFO mapreduce.Job: Running job: job_local2027701423_0001 2025-12-25 14:40:13,696 INFO mapred.LocalJobRunner: OutputCommitter set in config null 2025-12-25 14:40:13,707 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 2 2025-12-25 14:40:13,707 INFO output.FileOutputCommitter: FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 2025-12-25 14:40:13,708 INFO mapred.LocalJobRunner: OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter 2025-12-25 14:40:13,771 INFO mapred.LocalJobRunner: Waiting for map tasks 2025-12-25 14:40:13,772 INFO mapred.LocalJobRunner: Starting task: attempt_local2027701423_0001_m_000000_0 2025-12-25 14:40:13,806 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 2 2025-12-25 14:40:13,806 INFO output.FileOutputCommitter: FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 2025-12-25 14:40:13,832 INFO mapred.Task: Using ResourceCalculatorProcessTree : [ ] 2025-12-25 14:40:13,840 INFO mapred.MapTask: Processing split: hdfs://namenode:9000/input/file2.txt:0+41 2025-12-25 14:40:13,882 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584) 2025-12-25 14:40:13,882 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100 2025-12-25 14:40:13,882 INFO mapred.MapTask: soft limit at 83886080 2025-12-25 14:40:13,882 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600 2025-12-25 14:40:13,882 INFO mapred.MapTask: kvstart = 26214396; length = 6553600 2025-12-25 14:40:13,889 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer 2025-12-25 14:40:13,924 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false 2025-12-25 14:40:14,034 INFO mapred.LocalJobRunner: 2025-12-25 14:40:14,039 INFO mapred.MapTask: Starting flush of map output 2025-12-25 14:40:14,039 INFO mapred.MapTask: Spilling map output 2025-12-25 14:40:14,039 INFO mapred.MapTask: bufstart = 0; bufend = 69; bufvoid = 104857600 2025-12-25 14:40:14,039 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214372(104857488); length = 25/6553600 2025-12-25 14:40:14,056 INFO mapred.MapTask: Finished spill 0 2025-12-25 14:40:14,069 INFO mapred.Task: Task:attempt_local2027701423_0001_m_000000_0 is done. And is in the process of committing 2025-12-25 14:40:14,075 INFO mapred.LocalJobRunner: map 2025-12-25 14:40:14,075 INFO mapred.Task: Task 'attempt_local2027701423_0001_m_000000_0' done. 2025-12-25 14:40:14,086 INFO mapred.Task: Final Counters for attempt_local2027701423_0001_m_000000_0: Counters: 24 File System Counters FILE: Number of bytes read=3457 FILE: Number of bytes written=528804 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=41 HDFS: Number of bytes written=0 HDFS: Number of read operations=5 HDFS: Number of large read operations=0 HDFS: Number of write operations=1 HDFS: Number of bytes read erasure-coded=0 Map-Reduce Framework Map input records=1 Map output records=7 Map output bytes=69 Map output materialized bytes=80 Input split bytes=101 Combine input records=7 Combine output records=6 Spilled Records=6 Failed Shuffles=0 Merged Map outputs=0 GC time elapsed (ms)=0 Total committed heap usage (bytes)=497549312 File Input Format Counters Bytes Read=41 2025-12-25 14:40:14,086 INFO mapred.LocalJobRunner: Finishing task: attempt_local2027701423_0001_m_000000_0 2025-12-25 14:40:14,087 INFO mapred.LocalJobRunner: Starting task: attempt_local2027701423_0001_m_000001_0 2025-12-25 14:40:14,089 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 2 2025-12-25 14:40:14,089 INFO output.FileOutputCommitter: FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 2025-12-25 14:40:14,090 INFO mapred.Task: Using ResourceCalculatorProcessTree : [ ] 2025-12-25 14:40:14,092 INFO mapred.MapTask: Processing split: hdfs://namenode:9000/input/file3.txt:0+30 2025-12-25 14:40:14,117 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584) 2025-12-25 14:40:14,117 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100 2025-12-25 14:40:14,117 INFO mapred.MapTask: soft limit at 83886080 2025-12-25 14:40:14,118 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600 2025-12-25 14:40:14,118 INFO mapred.MapTask: kvstart = 26214396; length = 6553600 2025-12-25 14:40:14,119 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer 2025-12-25 14:40:14,128 INFO mapred.LocalJobRunner: 2025-12-25 14:40:14,128 INFO mapred.MapTask: Starting flush of map output 2025-12-25 14:40:14,128 INFO mapred.MapTask: Spilling map output 2025-12-25 14:40:14,128 INFO mapred.MapTask: bufstart = 0; bufend = 50; bufvoid = 104857600 2025-12-25 14:40:14,128 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214380(104857520); length = 17/6553600 2025-12-25 14:40:14,132 INFO mapred.MapTask: Finished spill 0 2025-12-25 14:40:14,134 INFO mapred.Task: Task:attempt_local2027701423_0001_m_000001_0 is done. And is in the process of committing 2025-12-25 14:40:14,139 INFO mapred.LocalJobRunner: map 2025-12-25 14:40:14,139 INFO mapred.Task: Task 'attempt_local2027701423_0001_m_000001_0' done. 2025-12-25 14:40:14,140 INFO mapred.Task: Final Counters for attempt_local2027701423_0001_m_000001_0: Counters: 24 File System Counters FILE: Number of bytes read=3779 FILE: Number of bytes written=528902 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=71 HDFS: Number of bytes written=0 HDFS: Number of read operations=7 HDFS: Number of large read operations=0 HDFS: Number of write operations=1 HDFS: Number of bytes read erasure-coded=0 Map-Reduce Framework Map input records=1 Map output records=5 Map output bytes=50 Map output materialized bytes=66 Input split bytes=101 Combine input records=5 Combine output records=5 Spilled Records=5 Failed Shuffles=0 Merged Map outputs=0 GC time elapsed (ms)=9 Total committed heap usage (bytes)=497549312 File Input Format Counters Bytes Read=30 2025-12-25 14:40:14,140 INFO mapred.LocalJobRunner: Finishing task: attempt_local2027701423_0001_m_000001_0 2025-12-25 14:40:14,140 INFO mapred.LocalJobRunner: Starting task: attempt_local2027701423_0001_m_000002_0 2025-12-25 14:40:14,142 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 2 2025-12-25 14:40:14,142 INFO output.FileOutputCommitter: FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 2025-12-25 14:40:14,143 INFO mapred.Task: Using ResourceCalculatorProcessTree : [ ] 2025-12-25 14:40:14,145 INFO mapred.MapTask: Processing split: hdfs://namenode:9000/input/file1.txt:0+29 2025-12-25 14:40:14,164 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584) 2025-12-25 14:40:14,164 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100 2025-12-25 14:40:14,164 INFO mapred.MapTask: soft limit at 83886080 2025-12-25 14:40:14,164 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600 2025-12-25 14:40:14,164 INFO mapred.MapTask: kvstart = 26214396; length = 6553600 2025-12-25 14:40:14,165 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer 2025-12-25 14:40:14,173 INFO mapred.LocalJobRunner: 2025-12-25 14:40:14,173 INFO mapred.MapTask: Starting flush of map output 2025-12-25 14:40:14,173 INFO mapred.MapTask: Spilling map output 2025-12-25 14:40:14,173 INFO mapred.MapTask: bufstart = 0; bufend = 45; bufvoid = 104857600 2025-12-25 14:40:14,173 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214384(104857536); length = 13/6553600 2025-12-25 14:40:14,176 INFO mapred.MapTask: Finished spill 0 2025-12-25 14:40:14,178 INFO mapred.Task: Task:attempt_local2027701423_0001_m_000002_0 is done. And is in the process of committing 2025-12-25 14:40:14,182 INFO mapred.LocalJobRunner: map 2025-12-25 14:40:14,183 INFO mapred.Task: Task 'attempt_local2027701423_0001_m_000002_0' done. 2025-12-25 14:40:14,185 INFO mapred.Task: Final Counters for attempt_local2027701423_0001_m_000002_0: Counters: 24 File System Counters FILE: Number of bytes read=4101 FILE: Number of bytes written=528981 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=100 HDFS: Number of bytes written=0 HDFS: Number of read operations=9 HDFS: Number of large read operations=0 HDFS: Number of write operations=1 HDFS: Number of bytes read erasure-coded=0 Map-Reduce Framework Map input records=1 Map output records=4 Map output bytes=45 Map output materialized bytes=47 Input split bytes=101 Combine input records=4 Combine output records=3 Spilled Records=3 Failed Shuffles=0 Merged Map outputs=0 GC time elapsed (ms)=0 Total committed heap usage (bytes)=497549312 File Input Format Counters Bytes Read=29 2025-12-25 14:40:14,185 INFO mapred.LocalJobRunner: Finishing task: attempt_local2027701423_0001_m_000002_0 2025-12-25 14:40:14,186 INFO mapred.LocalJobRunner: map task executor complete. 2025-12-25 14:40:14,191 INFO mapred.LocalJobRunner: Waiting for reduce tasks 2025-12-25 14:40:14,191 INFO mapred.LocalJobRunner: Starting task: attempt_local2027701423_0001_r_000000_0 2025-12-25 14:40:14,203 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 2 2025-12-25 14:40:14,203 INFO output.FileOutputCommitter: FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 2025-12-25 14:40:14,204 INFO mapred.Task: Using ResourceCalculatorProcessTree : [ ] 2025-12-25 14:40:14,207 INFO mapred.ReduceTask: Using ShuffleConsumerPlugin: org.apache.hadoop.mapreduce.task.reduce.Shuffle@1e5d4cca 2025-12-25 14:40:14,210 WARN impl.MetricsSystemImpl: JobTracker metrics system already initialized! 2025-12-25 14:40:14,232 INFO reduce.MergeManagerImpl: MergerManager: memoryLimit=5172887552, maxSingleShuffleLimit=1293221888, mergeThreshold=3414105856, ioSortFactor=10, memToMemMergeOutputsThreshold=10 2025-12-25 14:40:14,237 INFO reduce.EventFetcher: attempt_local2027701423_0001_r_000000_0 Thread started: EventFetcher for fetching Map Completion Events 2025-12-25 14:40:14,274 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local2027701423_0001_m_000001_0 decomp: 62 len: 66 to MEMORY 2025-12-25 14:40:14,279 INFO reduce.InMemoryMapOutput: Read 62 bytes from map-output for attempt_local2027701423_0001_m_000001_0 2025-12-25 14:40:14,281 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 62, inMemoryMapOutputs.size() -> 1, commitMemory -> 0, usedMemory ->62 2025-12-25 14:40:14,287 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local2027701423_0001_m_000000_0 decomp: 76 len: 80 to MEMORY 2025-12-25 14:40:14,288 INFO reduce.InMemoryMapOutput: Read 76 bytes from map-output for attempt_local2027701423_0001_m_000000_0 2025-12-25 14:40:14,288 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 76, inMemoryMapOutputs.size() -> 2, commitMemory -> 62, usedMemory ->138 2025-12-25 14:40:14,290 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local2027701423_0001_m_000002_0 decomp: 43 len: 47 to MEMORY 2025-12-25 14:40:14,291 INFO reduce.InMemoryMapOutput: Read 43 bytes from map-output for attempt_local2027701423_0001_m_000002_0 2025-12-25 14:40:14,291 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 43, inMemoryMapOutputs.size() -> 3, commitMemory -> 138, usedMemory ->181 2025-12-25 14:40:14,291 INFO reduce.EventFetcher: EventFetcher is interrupted.. Returning 2025-12-25 14:40:14,293 INFO mapred.LocalJobRunner: 3 / 3 copied. 2025-12-25 14:40:14,293 INFO reduce.MergeManagerImpl: finalMerge called with 3 in-memory map-outputs and 0 on-disk map-outputs 2025-12-25 14:40:14,302 INFO mapred.Merger: Merging 3 sorted segments 2025-12-25 14:40:14,303 INFO mapred.Merger: Down to the last merge-pass, with 3 segments left of total size: 153 bytes 2025-12-25 14:40:14,305 INFO reduce.MergeManagerImpl: Merged 3 segments, 181 bytes to disk to satisfy reduce memory limit 2025-12-25 14:40:14,305 INFO reduce.MergeManagerImpl: Merging 1 files, 181 bytes from disk 2025-12-25 14:40:14,306 INFO reduce.MergeManagerImpl: Merging 0 segments, 0 bytes from memory into reduce 2025-12-25 14:40:14,306 INFO mapred.Merger: Merging 1 sorted segments 2025-12-25 14:40:14,307 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 167 bytes 2025-12-25 14:40:14,308 INFO mapred.LocalJobRunner: 3 / 3 copied. 2025-12-25 14:40:14,351 INFO Configuration.deprecation: mapred.skip.on is deprecated. Instead, use mapreduce.job.skiprecords 2025-12-25 14:40:14,388 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false 2025-12-25 14:40:14,423 INFO mapred.Task: Task:attempt_local2027701423_0001_r_000000_0 is done. And is in the process of committing 2025-12-25 14:40:14,425 INFO mapred.LocalJobRunner: 3 / 3 copied. 2025-12-25 14:40:14,425 INFO mapred.Task: Task attempt_local2027701423_0001_r_000000_0 is allowed to commit now 2025-12-25 14:40:14,442 INFO output.FileOutputCommitter: Saved output of task 'attempt_local2027701423_0001_r_000000_0' to hdfs://namenode:9000/output 2025-12-25 14:40:14,443 INFO mapred.LocalJobRunner: reduce > reduce 2025-12-25 14:40:14,443 INFO mapred.Task: Task 'attempt_local2027701423_0001_r_000000_0' done. 2025-12-25 14:40:14,444 INFO mapred.Task: Final Counters for attempt_local2027701423_0001_r_000000_0: Counters: 30 File System Counters FILE: Number of bytes read=4571 FILE: Number of bytes written=529162 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=100 HDFS: Number of bytes written=98 HDFS: Number of read operations=14 HDFS: Number of large read operations=0 HDFS: Number of write operations=3 HDFS: Number of bytes read erasure-coded=0 Map-Reduce Framework Combine input records=0 Combine output records=0 Reduce input groups=12 Reduce shuffle bytes=193 Reduce input records=14 Reduce output records=12 Spilled Records=14 Shuffled Maps =3 Failed Shuffles=0 Merged Map outputs=3 GC time elapsed (ms)=0 Total committed heap usage (bytes)=497549312 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Output Format Counters Bytes Written=98 2025-12-25 14:40:14,444 INFO mapred.LocalJobRunner: Finishing task: attempt_local2027701423_0001_r_000000_0 2025-12-25 14:40:14,444 INFO mapred.LocalJobRunner: reduce task executor complete. 2025-12-25 14:40:14,702 INFO mapreduce.Job: Job job_local2027701423_0001 running in uber mode : false 2025-12-25 14:40:14,704 INFO mapreduce.Job: map 100% reduce 100% 2025-12-25 14:40:14,706 INFO mapreduce.Job: Job job_local2027701423_0001 completed successfully 2025-12-25 14:40:14,717 INFO mapreduce.Job: Counters: 36 File System Counters FILE: Number of bytes read=15908 FILE: Number of bytes written=2115849 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=312 HDFS: Number of bytes written=98 HDFS: Number of read operations=35 HDFS: Number of large read operations=0 HDFS: Number of write operations=6 HDFS: Number of bytes read erasure-coded=0 Map-Reduce Framework Map input records=3 Map output records=16 Map output bytes=164 Map output materialized bytes=193 Input split bytes=303 Combine input records=16 Combine output records=14 Reduce input groups=12 Reduce shuffle bytes=193 Reduce input records=14 Reduce output records=12 Spilled Records=28 Shuffled Maps =3 Failed Shuffles=0 Merged Map outputs=3 GC time elapsed (ms)=9 Total committed heap usage (bytes)=1990197248 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Input Format Counters Bytes Read=100 File Output Format Counters Bytes Written=98 ``` #### 4.4 查看日志 ```shell # 查看输出目录下的文件列表 hdfs dfs -ls /output # 查看统计结果 (part-r-00000 是结果文件) hdfs dfs -cat /output/part-r-00000 ``` 成功输出 ```log ```