一、环境准备
1、环境:Jdk 1.8、centos7.6、Maven 3.6.3和Scala-2.12
2、源码和CDH 版本:Flink 1.9.0 、 CDH 6.1.1(Hadoop 3.0.0)
注:mvn版本、CDH版本和scala版本无所谓,理论上可根据自己的版本自行更改。
二、安装包准备;
1、maven版本不要太低,我用的是maven 3.6.3:
https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
2、不同的 Flink 版本使用的 Flink-shaded不同,1.9 版本使用 1.9 :
https://archive.apache.org/dist/flink/flink-shaded-9.0/flink-shaded-9.0-src.tgz
3、flink1.9.0tar包:
https://archive.apache.org/dist/flink/flink-1.9.0/flink-1.9.0-src.tgz
三、安装MAVEN并修改源:已安装maven的可跳过安装步骤,但要记得修改setting.xml
1、下载maven tar包,移动到安装目录(略过)。
2、解压tar
命令:tar -zxvf apache-maven-3.6.3-bin.tar.gz
3、配置环境变量(略过)
查看命令:mvn --version
4、修改setting.xml:
命令:vim apache-maven-3.6.3/conf/settings.xml
添加如下配置:
<mirrors>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>google-maven-central</id>
<name>Google Maven Central</name>
<url>https://maven-central.storage.googleapis.com
</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- 中央仓库在中国的镜像 -->
<mirror>
<id>maven.net.cn</id>
<name>oneof the central mirrors in china</name>
<url>http://maven.net.cn/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
四、编译对应的flink-shaded 版本
1、解压tar包
命令:tar -zxvf flink-shaded-9.0-src.tgz
2、修改pom.xml
命令:vim flink-shaded-9.0/pom.xml
添加如下配置:
<profile>
<id>vendor-repos</id>
<activation>
<property>
<name>vendor-repos</name>
</property>
</activation>
<!-- Add vendor maven repositories -->
<repositories>
<!-- Cloudera -->
<repository>
<id>cloudera-releases</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- Hortonworks -->
<repository>
<id>HDPReleases</id>
<name>HDP Releases</name>
<url>https://repo.hortonworks.com/content/repositories/releases/</url>
<snapshots><enabled>false</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
<repository>
<id>HortonworksJettyHadoop</id>
<name>HDP Jetty</name>
<url>https://repo.hortonworks.com/content/repositories/jetty-hadoop</url>
<snapshots><enabled>false</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
<!-- MapR -->
<repository>
<id>mapr-releases</id>
<url>https://repository.mapr.com/maven/</url>
<snapshots><enabled>false</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
</repositories>
</profile>
3、编译:
命令1:cd flink-shaded-9.0/
命令2: mvn -T2C clean install -DskipTests -Pvendor-repos -Dhadoop.version=3.0.0-cdh6.1.1 -Dscala-2.12 -Drat.skip=true
注:hadoop版本,cdh版本,scala版本根据自己的集群情况自行修改。
五、编译flink1.9.0源码
1、解压tar包;
命令:tar -zxvf flink-1.9.0-src.tgz
2、编译
命令1:cd flink-1.9.0/
命令2:mvn clean install -DskipTests -Dfast -Drat.skip=true -Dhaoop.version=3.0.0-cdh6.1.1 -Pvendor-repos -Dinclude-hadoop -Dscala-2.12 -T2C
注:注意修改成自己对应的版本
3、提取出flink1.9.0对应的二进制包到安装目录
目录地址:flink-1.9.0/flink-dist/target/flink-1.9.0-bin
4、测试
命令:./bin/flink run -m yarn-cluster -ynm test_wordcount ./examples/batch/WordCount.jar --input hdfs://cluster_name/tmp/words.txt
注:注意在hdfs上添加测试的words.txt
备注:编译时间视情况而定,一般时间不会太短。理论上本方法适用于cdh6.x(6.0,6.1,6.2,6.3)的版本
错误
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile
(default-compile) on project flink-table-api-java:
Compilation failure
java/src/main/java/org/apache/flink/table/operations/utils/OperationTreeBuilder.java:[560,85] 未报告的异常错误X; 必须对其进行捕获或声明以便抛出
当时使用JDK
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
更换JDK即可得到解决
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
之前报错的地方已经通过了,下面只是其中一个过程的截图,之前是在flink-table-api-java报的错误,现在ok了!
2.编译flink-runtime-web报错
打开flink-runtime-web的pom文件,添加node和npm镜像
https://registry.npm.taobao.org/dist/
https://registry.npmjs.org/npm/-/
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeDownloadRoot>https://registry.npm.taobao.org/dist/</nodeDownloadRoot>
<npmDownloadRoot>https://registry.npmjs.org/npm/-/</npmDownloadRoot>
<nodeVersion>v10.9.0</nodeVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>ci --cache-max=0 --no-save</arguments>
<environmentVariables>
<HUSKY_SKIP_INSTALL>true</HUSKY_SKIP_INSTALL>
</environmentVariables>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<workingDirectory>web-dashboard</workingDirectory>
</configuration>
</plugin>