SpringBoot集成Hadoop

淡淡的烟草味﹌ 2023-09-28 21:48 168阅读 0赞

SpringBoot集成Hadoop,相关配置过程如下。默认在Linux下已经装好Hadoop集群(Hadoop-2.8.5)。

一、集成HDFS

1、主要application.properties配置

  1. #hdfs
  2. hdfs.url=hdfs://192.168.2.5:9000
  3. hdfs.username=root
  4. hdfs.replication=2
  5. hdfs.blocksize=67108864

2、主要pom.xml配置

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-logging</artifactId>
  9. </exclusion>
  10. </exclusions>
  11. </dependency>
  12. <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
  13. <dependency>
  14. <groupId>org.apache.hadoop</groupId>
  15. <artifactId>hadoop-common</artifactId>
  16. <version>2.8.5</version>
  17. </dependency>
  18. <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs -->
  19. <dependency>
  20. <groupId>org.apache.hadoop</groupId>
  21. <artifactId>hadoop-hdfs</artifactId>
  22. <version>2.8.5</version>
  23. </dependency>
  24. <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client -->
  25. <dependency>
  26. <groupId>org.apache.hadoop</groupId>
  27. <artifactId>hadoop-client</artifactId>
  28. <version>2.8.5</version>
  29. </dependency>
  30. <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
  31. <dependency>
  32. <groupId>com.alibaba</groupId>
  33. <artifactId>fastjson</artifactId>
  34. <version>1.2.44</version>
  35. </dependency>
  36. <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
  37. <dependency>
  38. <groupId>io.springfox</groupId>
  39. <artifactId>springfox-swagger2</artifactId>
  40. <version>2.9.2</version>
  41. </dependency>
  42. <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
  43. <dependency>
  44. <groupId>io.springfox</groupId>
  45. <artifactId>springfox-swagger-ui</artifactId>
  46. <version>2.9.2</version>
  47. </dependency>
  48. <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
  49. <dependency>
  50. <groupId>com.google.guava</groupId>
  51. <artifactId>guava</artifactId>
  52. <version>27.0.1-jre</version>
  53. </dependency>
  54. </dependencies>

完成其他相关配置和代码。

3、Windows下环境变量设置

在Windows下启动程序,请求HDFS报以下错误:

java.io.FileNotFoundException: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.

Windows下Java集成HADOOP,需要用到winutils.exe。提示缺少HADOOP_HOME或hadoop.home.dir相关配置。从https://github.com/steveloughran/winutils下载相关库,与本集群hadoop-2.8.5最接近的库为hadoop-2.8.3,下载hadoop-2.8.3到本地磁盘。通过设置Windows环境变量或在程序中设置hadoop.home.dir解决。

(1)设置Windows环境变量

设置Windows环境变量HADOOP_HOME=D:softhadoopwinutilshadoop-2.8.3

(2)程序中设置hadoop.home.dir

在程序初始化Hadoop Configuration之前添加以下代码设置环境变量

  1. //Windows设置hadoop.home.dir
  2. System.setProperty("hadoop.home.dir","D:\soft\hadoop\winutils\hadoop-2.8.3");

4、Windows主机映射

需要配置本机的hosts文件,添加hadoop集群的主机映射,配置内容和hadoop集群的配置差不多。编辑C:WindowsSystem32driversetchosts文件,添加:

  1. # Copyright (c) 1993-2009 Microsoft Corp.
  2. #
  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  4. #
  5. # This file contains the mappings of IP addresses to host names. Each
  6. # entry should be kept on an individual line. The IP address should
  7. # be placed in the first column followed by the corresponding host name.
  8. # The IP address and the host name should be separated by at least one
  9. # space.
  10. #
  11. # Additionally, comments (such as these) may be inserted on individual
  12. # lines or following the machine name denoted by a '#' symbol.
  13. #
  14. # For example:
  15. #
  16. # 102.54.94.97 rhino.acme.com # source server
  17. # 38.25.63.10 x.acme.com # x client host
  18. # localhost name resolution is handled within DNS itself.
  19. # 127.0.0.1 localhost
  20. # ::1 localhost
  21. 192.168.2.5 hadoop.master

发表评论

表情:
评论列表 (有 0 条评论,168人围观)

还没有评论,来说两句吧...

相关阅读