1. 絮絮叨叨
- 从工作开始,同事就说你要领一个mac,这样方便你的开发工作
- 毕竟习惯了操作Linux服务器,在mac上使用常见的Linux命令,毫无障碍
- 哪里像windows,使用shell命令都要先上网查一下
- 最近不信邪,想在windows上、基于IDEA搭建Presto的开发环境
- 编译、导入IDEA都还很顺利,等到运行时,就傻眼了
2. 准备工作
2.1 JDK
2.2 maven 3.x
- 安装maven,自己选择的是maven3.8.2
- 安装教程,可以参考本人之前的博客:
- 年代久远,建议配置
settings.xml 的中本地仓库时,不要放在系统盘(C盘)
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_HOME 和Path -
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文件
-
修改根目录下的pom.xml 文件,注释掉presto-doc 和presto-server-rpm 两个用不着的模块
-
也有博客(Presto 官方版使用 Windows 编译源码)说,需要修改与git有关的配置,自己没做修改能成功编译 -
自己编译时,出现 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
-
最后通过修改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 规则
-
如果不去除,编译时将会报错 [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 static com.google.common.collect.ImmutableList.toImmutableList;
3.4 编译源码
4. 运行PrestoServer
4.1 配置Presto
-
在presto-main/etc 目录下,找到config.properties 文件,将其修改如下:
coordinator=true
node-scheduler.include-coordinator=true
http-server.http.port=8080
discovery-server.enabled=true
discovery.uri=http://localhost:8080
plugin.dir=../presto-server/target/presto-server-0.240/presto-server-0.240/plugin
-
修改presto-main/etc/catalog ,可以根据环境环境情况,保留一些catalog,其他的catalog文件增加bak后缀,避免其生效 -
例如,hive.properties 这个catalog文件,改为hive.properties.bak
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.dll 和winutils.exe - 将这两个文件放到
C:\Windows\System32 中 -
自己从github,下载了2.7.3版本的Hadoop的library放到C:\Windows\System32 中 -
重启程序、重启IDEA、甚至重启电脑,都没有解决问题 -
只能等到上班与同事一起排查,或者希望有大佬能指点一二
5.2 关于plugin的设置
-
在config.properties 中,除了可以使用plugin.dir 设置plugin信息 -
还可以使用plugin.bundles ,设置需要加载的plugin的pom文件,简单示例如下: plugin.bundles=\
../presto-blackhole/pom.xml,\
../presto-memory/pom.xml,\
../presto-jmx/pom.xml,\
../presto-raptor/pom.xml,\
-
原本自己在mac上玩Presto时,就是这样配置的 -
但是到了windows上,就行不行通了 😂 2022-07-15T22:54:50.333+0800 ERROR main com.facebook.presto.server.PrestoServer Error loading pom: D:\IdeaProjects\facebook-presto-0.223.1\presto-main\..\presto-memory\pom.xml
java.lang.RuntimeException: Error loading pom: D:\IdeaProjects\facebook-presto-0.223.1\presto-main\..\presto-memory\pom.xml
at io.airlift.resolver.ArtifactResolver.resolvePom(ArtifactResolver.java:143)
...
at com.facebook.presto.server.PrestoServer.main(PrestoServer.java:77)
Caused by: org.apache.maven.project.ProjectBuildingException: 1 problem was encountered while building the effective model for com.facebook.presto:presto-memory:0.240
[FATAL] Non-resolvable parent POM for com.facebook.presto:presto-root:0.240: Could not transfer artifact com.facebook.airlift:airbase:pom:99 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer http://repo.maven.apache.org/maven2/com/facebook/airlift/airbase/99/airbase-99.pom. Error code 501, HTTPS Required and 'parent.relativePath' points at wrong local POM @ com.facebook.presto:presto-root:0.240, D:\IdeaProjects\facebook-presto-0.223.1\pom.xml, line 5, column 13
for project com.facebook.presto:presto-memory:0.240 at D:\IdeaProjects\facebook-presto-0.223.1\presto-main\..\presto-memory\pom.xml
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:149)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:102)
at io.airlift.resolver.ArtifactResolver.resolvePom(ArtifactResolver.java:136)
... 6 more
Caused by: org.apache.maven.model.building.ModelBuildingException: 1 problem was encountered while building the effective model for com.facebook.presto:presto-memory:0.240
[FATAL] Non-resolvable parent POM for com.facebook.presto:presto-root:0.240: Could not transfer artifact com.facebook.airlift:airbase:pom:99 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer http://repo.maven.apache.org/maven2/com/facebook/airlift/airbase/99/airbase-99.pom. Error code 501, HTTPS Required and 'parent.relativePath' points at wrong local POM @ com.facebook.presto:presto-root:0.240, D:\IdeaProjects\facebook-presto-0.223.1\pom.xml, line 5, column 13
at org.apache.maven.model.building.DefaultModelProblemCollector.newModelBuildingException(DefaultModelProblemCollector.java:195)
at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:841)
at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:664)
at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:310)
at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:232)
at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:142)
... 8 more
-
从报错信息看,好像需要立即从maven中央仓库http://repo.maven.apache.org/maven2 下载com.facebook.airlift:airbase:pom:99 -
而这个仓库,已经从2020开始,改为使用https访问了 -
通过报错信息,定位到是maven-model-builder 依赖中使用的pom-4.0.0.xml ,配置的maven仓库地址过时了 <dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-builder</artifactId>
<version>3.0.4</version>
</dependency>
-
通过依赖分析,发现maven-model-builder 依赖是presto-main 模块因为使用io.airlift.resolver:resolver:1.4 ,传递导入的 -
exclued掉maven-model-builder ,还是不行,最后使用plugin.dir 设置plugin信息才算解决了问题
5.3 参考链接
|