| 參數 | 值來源 | 範例 |
| Location name | 自訂 | RemoteCluster |
| Map/Reduce Master Host | yarn-site.xml → yarn.resourcemanager.address | 192.168.1.100:8032 |
| DFS Master Port | core-site.xml → fs.defaultFS | 192.168.1.100:9000 |
| User name | Hadoop 運行用戶 | hadoop |
5. 權限問題解決
遠端 hdfs-site.xml:
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
執行:
hadoop dfsadmin -safemode leave
hadoop fs -chmod 777 /
6. WordCount 專案建立與除錯
- New → Map/Reduce Project
- 加入標準 WordCount.java
- src/log4j.properties 配置控制台輸出
- Run Configurations → Arguments → Program arguments:
hdfs://192.168.1.100:9000/user/input/README.txt
hdfs://192.168.1.100:9000/user/output/
- 輸入檔預先上傳 HDFS
- 輸出目錄必須不存在
- 設定斷點 → Debug As → Hadoop Application
IntelliJ IDEA 遠端除錯配置
1. Maven 專案建立
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-jobclient</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
2. 模組依賴配置
- File → Project Structure (Ctrl+Alt+Shift+S) → Modules → Dependencies
- + → JARs or directories → 選擇
$HADOOP_HOME 下所有 JAR
- 命名 Library:
hadoop-2.6
3. 運行配置
- Run → Edit Configurations → + → Application
- Main class: WordCount
- Program arguments: 同 Eclipse
- Working directory:
$HADOOP_HOME
4. 關鍵:core-site.xml 放入資源目錄
src/main/resources/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://192.168.1.100:9000</value>
</property>
</configuration>
讓 IDE 運行時能解析 HDFS 位址。
5. 輸出目錄自動清理改良
// WordCount main 方法開頭加入
Configuration conf = new Configuration();
String outputPath = otherArgs[otherArgs.length - 1];
FileSystem fs = FileSystem.get(conf);
Path outPath = new Path(outputPath);
if (fs.exists(outPath)) {
fs.delete(outPath, true);
System.out.println("已清理舊輸出目錄: " + outputPath);
}
兩 IDE 對比總結
| 功能 | Eclipse | IntelliJ IDEA |
| HDFS 瀏覽 | 內建插件支援 | 需外部工具或命令行 |
| 專案建立 | Map/Reduce Project 向導 | 標準 Maven 專案 |
| 依賴管理 | 手動加入 JAR | Maven 自動管理 |
| 配置複雜度 | 較高(插件、原生庫) | 較低(標準化) |
| 除錯體驗 | 良好 | 優秀 |
| 輸出目錄清理 | 手動 | 代碼控制 |
連線驗證指令
telnet 192.168.1.100 9000
# 或
hadoop fs -ls hdfs://192.168.1.100:9000/
- 上一篇文章: Maven 安裝與 MyEclipse 整合完整指南:從環境變數到專案建立
- 下一篇文章: Spring MVC RESTful 配置常見陷阱:靜態資源衝突、路徑匹配、內容協商完整解析
Copyright ©
程式碼之家 All Rights Reserved