win10基于IDEA,搭建Presto 0.280开发环境

1. 絮絮叨叨

  • 从工作开始,同事就说你要领一个mac,这样方便你的开发工作
  • 毕竟习惯了操作Linux服务器,在mac上使用常见的Linux命令,毫无障碍
  • 哪里像windows,使用shell命令都要先上网查一下
  • 最近不信邪,想在windows上、基于IDEA搭建Presto的开发环境
  • 编译、导入IDEA都还很顺利,等到运行时,就傻眼了

2. 准备工作

2.1 JDK

2.2 maven 3.x

2.3 安装git

  • 安装git,自己直接下载的官网最新版本2.37.1

  • 安装教程,可以参考博客:Windows系统Git安装教程(详解Git安装过程)

  • Presto-的presto-cli模块,在编译时需要使用Linux命令,如chmod

  • 如未正确设置,会编译报错:

    [ERROR] Failed to execute goal org.skife.maven:really-executable-jar-maven-plugin:1.0.5:really-executable-jar (default) on project presto-cli: FAILURE!:
     FAILURE!
    [ERROR] Cannot run program "chmod": CreateProcess error=2, 系统找不到指定的文件。
    
  • git bash是支持Linux命令的,可以借助git使得windows支持这些命令

  • 实现方法:在系统环境变量中,设置GIT_HOMEPath

  • GIT_HOME为git的安装路径,默认安装路径为:C:\Program Files\Git

  • 编辑Path,新建%GIT_HOME%\usr\bin

  • 设置完成后,新开一个命令行提示符中,运行Linux命令chmod进行测试

2.4 修改presto-maven-plugin-0.3的源码

  • 下载presto-maven-plugin-0.3源码的压缩包,下载地址:https://github.com/prestodb/presto-maven-plugin/tags

  • ctrl + N搜索ServiceDescriptorGenerator类,修改其122行的代码

    // 源代码
    String className = classPath.substring(0, classPath.length() - 6).replace('/', '.');
    // 修改后的代码
    String className = classPath.substring(0, classPath.length() - 6).replace(File.separatorChar, '.');
    
  • 执行mvn clean install -DskipTests, 将修改后的presto-maven-plugin-0.3安装到本地仓库

3. 编译Presto源码

  • 通过git clone下载presto源码,并导入IDEA

3.1 修改根目录下的pom.xml文件

3.1.1 注释掉多余模块

  • 修改根目录下的pom.xml文件,注释掉presto-docpresto-server-rpm模块。这两个模块用于生成doc和rpm安装包,一般使用不到

    <!--<module>presto-server-rpm</module>-->
    <!--<module>presto-docs</module>-->
    
  • 注意: 也可以注释掉其他含有Java代码的模块,但为了避免编译出错,暂不建议

  • 也有博客(Presto 官方版使用 Windows 编译源码)说,需要修改与git有关的配置,自己没做修改能成功编译
    在这里插入图片描述

3.1.2 解决RequireUpperBoundDeps failed错误

  • 编译过程中,当变异到presto-druid模块时,出现 org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed的错误

    [WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
    Failed while enforcing RequireUpperBoundDeps. The error(s) are [
    Require upper bound dependencies error for org.apache.httpcomponents:httpclient:4.5.5 paths to dependency are:
    +-com.facebook.presto:presto-druid:0.240
      +-org.apache.druid:druid-core:0.19.0
        +-org.apache.httpcomponents:httpclient:4.5.5 (managed) <-- org.apache.httpcomponents:httpclient:4.5.10
    and
    +-com.facebook.presto:presto-druid:0.240
      +-com.facebook.presto:presto-tests:0.240
        +-com.facebook.presto:presto-client:0.240
          +-com.google.auth:google-auth-library-oauth2-http:0.12.0
            +-com.google.http-client:google-http-client:1.27.0
              +-org.apache.httpcomponents:httpclient:4.5.5 (managed) <-- org.apache.httpcomponents:httpclient:4.5.10
    
  • 解决办法: 修改父模块presto-root的pom.xml的maven-enforcer-plugin配置,去除对org.apache.httpcomponents:httpclient<requireUpperBoundDeps>配置

    <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-enforcer-plugin</artifactId>
         <configuration>
             <rules>
                 <requireUpperBoundDeps>
                     <excludes combine.children="append">
                         ...
                         <exclude>org.apache.httpcomponents:httpclient</exclude>
                     </excludes>
                 </requireUpperBoundDeps>
             </rules>
         </configuration>
     </plugin>
    

3.2 修改presto-checks.xml

  • 修改根目录下的src/checkstyle/presto-checks.xml,注释掉与\r有关的RegexpMultiline规则

    <!--<module name="RegexpMultiline">
        <property name="format" value="\r" />
        <property name="message" value="Line contains carriage return" />
    </module>-->
    
  • 如果不去除,编译时将会报错

    [ERROR] src\main\resources\com\facebook\presto\common\type\zone-index.properties:[403] (regexp) RegexpMultiline: Line contains carriage return
    [ERROR] src\main\resources\com\facebook\presto\common\type\zone-index.properties:[404] (regexp) RegexpMultiline: Line contains carriage return
    [ERROR] src\main\resources\com\facebook\presto\common\type\zone-index.properties:[405] (regexp) RegexpMultiline: Line contains carriage return
    

3.3 修改Presto源码

  • 修改PrestoSystemRequirements

  • Presto要求系统环境为Linux或mac OS,如果为windows程序会运行失败。

  • 这时,需要将其改为warn并非fail

    // 修改前
    failRequirement("Presto requires Linux or Mac OS X (found %s)", osName);
    // 修改后
    warnRequirement("Presto requires Linux or Mac OS X (found %s)", osName);
    
  • 改为warn后,程序运行不会再失败
    在这里插入图片描述

  • 从系统获取你文件句柄数,改为使用固定值

    // 修改前
    Object maxFileDescriptorCount = mbeanServer.getAttribute(ObjectName.getInstance(OPERATING_SYSTEM_MXBEAN_NAME), "MaxFileDescriptorCount");
    // 修改后
    Object maxFileDescriptorCount = 10000;
    
  • 注意: 如果IDEA没有设置自动去除无用import,需要手动注释掉由于代码修改带来的无用import

    // import javax.management.ObjectName;
    ...
    import static com.google.common.collect.ImmutableList.toImmutableList;
    // import static java.lang.management.ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME;
    

3.4 编译源码

  • 执行如下命令,完成Presto源码的编译

    mvn clean install -DskipTests
    

4. 运行PrestoServer

4.1 配置Presto

4.1.1 配置config.properties

  • presto-main/etc目录下,找到config.properties文件,将其修改如下:

    # 默认为true,可以不用设置
    coordinator=true
    # 既是coordinator,又是worker
    node-scheduler.include-coordinator=true
    
    http-server.http.port=8080
    discovery-server.enabled=true
    # coordinator包含discovery server,所以discovery.uri就是coordinator的地址
    discovery.uri=http://localhost:8080
    
    # 加载plugin的方法:1. 直接加载plugin目录;2. 通过plugin.bundles,设置需要加载的plugin
    # 这里选择方法2,只保留需要加载的关键模块
    plugin.bundles=\
      ../presto-memory/pom.xml,\
      ../presto-jmx/pom.xml,\
      ../presto-raptor/pom.xml,\
      ../presto-hive-hadoop2/pom.xml,\
      ../presto-example-http/pom.xml,\
      ../presto-local-file/pom.xml, \
      ../presto-i18n-functions/pom.xml,\
      ../presto-function-namespace-managers/pom.xml,\
      ../presto-cluster-ttl-providers/pom.xml,\
      ../presto-node-ttl-fetchers/pom.xml,\
      ../presto-hive-function-namespace/pom.xml
    
    # 使用这种加载方式,一定要设置好maven命令对应的本地repo
    # maven.repo.local的默认值为~/.m2/repository,如果在settgins.xml中自定义了本地repo,这个默认值则不是本地repo
    maven.repo.local=/Users/xxx/repo
    

4.1.2 去除无用的catalog properties文件

  • 如果在config.propertis的plugin.bundles中,去除了一些暂时无用的plugin,则需要同步修改presto-main/etc/catalog

  • 将这些plugin对应的catalog配置文件,移动到临时目录catalog_unused;或者为catalog文件增加bak后缀,例如,hive.properties,改为hive.properties.bak

  • 因为Presto会先加载catalog配置文件,再根据配置文件中的connector.name去加载对应的catalog。如果plugin不加载,却配置了catalog文件,则出现如下类似错误:

    2023-03-07T15:47:54.422+0800	INFO	main	com.facebook.presto.metadata.StaticCatalogStore	-- Loading catalog properties etc/catalog/blackhole.properties --
    2023-03-07T15:47:54.428+0800	INFO	main	com.facebook.presto.metadata.StaticCatalogStore	-- Loading catalog blackhole --
    2023-03-07T15:47:54.428+0800	ERROR	main	com.facebook.presto.server.PrestoServer	No factory for connector blackhole
    java.lang.IllegalArgumentException: No factory for connector blackhole
    	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:216)
    	at com.facebook.presto.connector.ConnectorManager.createConnection(ConnectorManager.java:212)
    	at com.facebook.presto.metadata.StaticCatalogStore.loadCatalog(StaticCatalogStore.java:123)
    	at com.facebook.presto.metadata.StaticCatalogStore.loadCatalog(StaticCatalogStore.java:98)
    	at com.facebook.presto.metadata.StaticCatalogStore.loadCatalogs(StaticCatalogStore.java:80)
    	at com.facebook.presto.metadata.StaticCatalogStore.loadCatalogs(StaticCatalogStore.java:68)
    	at com.facebook.presto.server.PrestoServer.run(PrestoServer.java:151)
    	at com.facebook.presto.server.PrestoServer.main(PrestoServer.java:86)
    

4.2 设置Run Configuration

  • 新增一个Run Configuration,创建Presto的Application
    • Use classpath of module: presto-main
    • Main class: com.facebook.presto.server.PrestoServer
    • VM options: -ea -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+UseGCOverheadLimit -XX:+ExplicitGCInvokesConcurrent -Xmx2G -Dconfig=etc/config.properties -Dlog.levels-file=etc/log.properties
    • Working directory: $MODULE_DIR$
      在这里插入图片描述
  • 最后点击Run按钮,成功启动PrestoServer
  • 标志性的日志:com.facebook.presto.server.PrestoServer ======== SERVER STARTED ========
    在这里插入图片描述

5. 题外话

5.1 Hadoop native library问题 —— 最后放弃

  • 其实,Presto的众多connector中,使用最多的还是Hive connector

  • 原本已经配置好了hive.properties,但是启动以后报错:

    1) Error injecting constructor, java.lang.RuntimeException: failed to load Hadoop native library
      at com.facebook.presto.hive.HdfsEnvironment.<init>(HdfsEnvironment.java:47)
      at com.facebook.presto.hive.HiveClientModule.configure(HiveClientModule.java:167)
      while locating com.facebook.presto.hive.HdfsEnvironment
        for the 1st parameter of com.facebook.presto.hive.S3SelectRecordCursorProvider.<init>(S3SelectRecordCursorProvider.java:54)
      while locating com.facebook.presto.hive.S3SelectRecordCursorProvider
      at com.facebook.presto.hive.HiveClientModule.configure(HiveClientModule.java:121)
      while locating com.facebook.presto.hive.HiveRecordCursorProvider annotated with @com.google.inject.internal.Element(setName=,uniqueId=32, type=MULTIBINDER, keyType=)
    Caused by: java.lang.RuntimeException: failed to load Hadoop native library
    	at com.facebook.presto.hadoop.HadoopNative.requireHadoopNative(HadoopNative.java:58)
    	at com.facebook.presto.hive.HdfsEnvironment.<init>(HdfsEnvironment.java:52)
    	... # 省略细节
    	at com.facebook.presto.metadata.StaticCatalogStore.loadCatalogs(StaticCatalogStore.java:80)
    	at com.facebook.presto.server.PrestoServer.run(PrestoServer.java:138)
    	at com.facebook.presto.server.PrestoServer.main(PrestoServer.java:77)
    Caused by: java.lang.RuntimeException: library not found: /nativelib/Windows_10-amd64/hadoop.dll
    	at com.facebook.presto.hadoop.HadoopNative.loadLibrary(HadoopNative.java:88)
    	at com.facebook.presto.hadoop.HadoopNative.requireHadoopNative(HadoopNative.java:47)
    	... 46 more
    
  • 网上查阅资料,也咨询了同事,通用的解决方法:

    • 获取对应版本的(有人说,大版本一致就OK)、适合win10环境的Hadoop native library,包括hadoop.dllwinutils.exe
    • 将这两个文件放到C:\Windows\System32
  • 自己从github,下载了2.7.3版本的Hadoop的library放到C:\Windows\System32

  • 重启程序、重启IDEA、甚至重启电脑,都没有解决问题

  • 本来还想着上班了,找同事问问他是怎呢么实现HDFS、Spark在windows上运行的,结果同事说他的方法就是跟我一样的

  • 最后自己想通了,你看人家官网和源码都明确限制windows了,还费那个劲干啥,你又不是大神 😝 😝

5.2 参考链接

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值