一. 自己搭建開發環境
今天自己搭建了一套Centos5.3 + Hadoop2.2 + Hbase0.96.1.1的開發環境,Win7 Eclipse調試MapReduce成功。可能是版本比較高的原因,出了問題,網上找不到完整解決方案,只能靠自己。
二. Hadoop安裝
這個就不囉嗦了,網上大把文章。我下載的是hadoop-2.2.0.tar.gz。
- http://www.cnblogs.com/xia520pi/archive/2012/05/16/2503949.html 很詳細的介紹了Hadoop Hdfs的安裝。它這個不是Hadoop2.2的,但配置都大同小異。
- MapReduce的配置可以參考http://blog.sina.com.cn/s/blog_546abd9f0101i8b8.html。
安裝成功後,能順利查看以下幾個頁面,就OK了。我的集羣環境是200master,201-203slave。
- dfs.http.address 192.168.1.200:50070
- dfs.secondary.http.address 192.168.1.200:50090
- dfs.datanode.http.address 192.168.1.201:50075
- yarn.resourcemanager.webapp.address 192.168.1.200:50030
- mapreduce.jobhistory.webapp.address 192.168.1.200:19888。這個好像訪問不了。需要啓動hadoop/sbin/mr-jobhistory-daemon.sh start historyserver纔可以訪問。
三. Hadoop2.x eclispe-plugin
https://github.com/winghc/hadoop2x-eclipse-plugin
目前這個插件還在開發中,你可以自己下載源碼編譯,網上也有人發佈編譯好的jar。
http://blog.csdn.net/zythy/article/details/17397153 這個同學寫的很詳細了。
需要注意一點的是,Hadoop installation directory裏填寫Win下的hadoop home地址,其目的在於創建MapReduce Project能從這個地方自動引入MapReduce需要的jar。解壓hadoop-2.2.0.tar.gz到本地即可。
四. 各種問題
上面一步完成後,創建一個MapReduce Project,運行時發現出問題了。
-
- java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
- public static final String getQualifiedBinPath(String executable)
- throws IOException {
- // construct hadoop bin path to the specified executable
- String fullExeName = HADOOP_HOME_DIR + File.separator + "bin"
- + File.separator + executable;
- File exeFile = new File(fullExeName);
- if (!exeFile.exists()) {
- throw new IOException("Could not locate executable " + fullExeName
- + " in the Hadoop binaries.");
- }
- return exeFile.getCanonicalPath();
- }
- private static String HADOOP_HOME_DIR = checkHadoopHome();
- private static String checkHadoopHome() {
- // first check the Dflag hadoop.home.dir with JVM scope
- String home = System.getProperty("hadoop.home.dir");
- // fall back to the system/user-global env variable
- if (home == null) {
- home = System.getenv("HADOOP_HOME");
- }
- ...
- }
- 這個時候得到完整的地址fullExeName,我機器上是D:\Hadoop\tar\hadoop-2.2.0\hadoop-2.2.0\bin\winutils.exe。繼續執行代碼又發現了錯誤
- Could not locate executable D:\Hadoop\tar\hadoop-2.2.0\hadoop-2.2.0\bin\winutils.exe in the Hadoop binaries.
- 繼續出問題
- at org.apache.hadoop.util.Shell.execCommand(Shell.java:661)
- at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:639)
- at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:435)
- public static String[] getSetPermissionCommand(String perm, boolean recursive,
- String file) {
- String[] baseCmd = getSetPermissionCommand(perm, recursive);
- String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
- cmdWithFile[cmdWithFile.length - 1] = file;
- return cmdWithFile;
- }
- /** Return a command to set permission */
- public static String[] getSetPermissionCommand(String perm, boolean recursive) {
- if (recursive) {
- return (WINDOWS) ? new String[] { WINUTILS, "chmod", "-R", perm }
- : new String[] { "chmod", "-R", perm };
- } else {
- return (WINDOWS) ? new String[] { WINUTILS, "chmod", perm }
- : new String[] { "chmod", perm };
- }
- }
- 無法啓動此程序,因爲計算機中丟失 MSVCR100.dll
- 應用程序無法正常啓動(0xc000007b)
- 到了這裏,已經看到曙光了,但問題又來了
- Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z
- /** Windows only method used to check if the current process has requested
- * access rights on the given path. */
- private static native boolean access0(String path, int requestedAccess);
- 終於看到了MapReduce的正確輸出output99。
五. 總結
- hadoop eclipse插件不是必須的,其作用在我看來就是如下三點(這個是一個錯誤的認識,具體請參考http://zy19982004.iteye.com/blog/2031172)。study-hadoop是一個普通project,直接運行(不通過Run
on Hadoop這隻大象),一樣可以調試到MapReduce。
- 對hadoop中的文件可視化。
- 創建MapReduce Project時幫你引入依賴的jar。
- Configuration conf = new Configuration();時就已經包含了所有的配置信息。
- 還是自己下載hadoop2.2的源碼編譯好,應該是不會有任何問題的(沒有親測)。
六. 其它問題
還是- Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z
- static {
- // Try to load native hadoop library and set fallback flag appropriately
- if(LOG.isDebugEnabled()) {
- LOG.debug("Trying to load the custom-built native-hadoop library...");
- }
- try {
- System.loadLibrary("hadoop");
- LOG.debug("Loaded the native-hadoop library");
- nativeCodeLoaded = true;
- } catch (Throwable t) {
- // Ignore failure to load
- if(LOG.isDebugEnabled()) {
- LOG.debug("Failed to load native-hadoop with error: " + t);
- LOG.debug("java.library.path=" +
- System.getProperty("java.library.path"));
- }
- }
- if (!nativeCodeLoaded) {
- LOG.warn("Unable to load native-hadoop library for your platform... " +
- "using builtin-java classes where applicable");
- }
- }
- DEBUG org.apache.hadoop.util.NativeCodeLoader - Failed to load native-hadoop with error: java.lang.UnsatisfiedLinkError: HADOOP_HOME\bin\hadoop.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
- 2014-03-11 19:43:08,805 DEBUG org.apache.hadoop.util.NativeCodeLoader - Trying to load the custom-built native-hadoop library...
- 2014-03-11 19:43:08,812 DEBUG org.apache.hadoop.util.NativeCodeLoader - Loaded the native-hadoop library
- WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
轉載 http://zy19982004.iteye.com/blog/2024467