flink-1.10.0 源码编译(最详细)

采用maven命令编译源码。

0. 机器准备

购买某某云主机一台,节点最好选香港、新加坡等地,方便下载jar包。配置至少2核8G,按量付费。

1. 环境准备

1.1 安装jdk
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
mkdir /usr/java/
tar -zxvf jdk-8u141-linux-x64.tar.gz -C /usr/java/
cd /usr/java/
chown -R root:root jdk1.8.0_141/
1.2 安装maven
wget https://mirrors.aliyun.com/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

配置settings.xml文件,加入阿里云地址:
<localRepository>/bigdata/repo</localRepository>
<mirror>
     <id>aliyun</id>
     <mirrorOf>central</mirrorOf>
     <name>aliyun</name>
     <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>


配置环境:
vim /etc/profile
	export MAVEN_HOME=/app/apache-maven-3.6.3
	export PATH=$PATH:$MAVEN_HOME/bin

	export JAVA_HOME=/usr/java/jdk1.8.0_141
	export PATH=$JAVA_HOME/bin:$PATH
source /etc/profile
1.3 准备flink源码
yum install -y git
git clone https://github.com/apache/flink.git
cd flink/
git checkout release-1.10         //默认分支是Master,需要切换分支至社区发行版

在源码的pom.xml中加入,以便下载关于CDH的jar包:
<repositories>
 <repository>
     <id>cloudera-releases</id>
     <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
 </repository>
</repositories>

2. 编译源码

mvn clean install -DskipTests -Dfast -Drat.skip=true -Dhaoop.version=2.6.0-cdh5.15.1 -Pvendor-repos -Dinclude-hadoop -Dscala-2.11 -T2C
# -Dfast  #在flink根目录下pom.xml文件中fast配置项目中含快速设置,其中包含了多项构建时的跳过参数. #例如apache的文件头(rat)合法校验,代码风格检查,javadoc生成的跳过等,详细可阅读pom.xml
# install maven的安装命令
# -T2C #支持多处理器或者处理器核数参数,加快构建速度,推荐Maven3.3及以上
# -Pinclude-hadoop  将hadoop的 jar包,打入到lib/中
# -Pvendor-repos   # 如果需要指定hadoop的发行商,如CDH,需要使用-Pvendor-repos
# -Dscala-2.11     # 指定scala的版本为2.11
# -Dhadoop.version=2.6.0-cdh5.15.1  指定 hadoop 的版本

注意:这样编译必定会出现一个错误:

[ERROR] Failed to execute goal on project flink-hadoop-fs: Could not resolve dependencies for project org.apache.flink:flink-hadoop-fs:jar:1.10-SNAPSHOT: Could not transfer artifact org.apache.flink:flink-shaded-hadoop-2:jar:2.4.1-9.0 from/to nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public): GET request of: org/apache/flink/flink-shaded-hadoop-2/2.4.1-9.0/flink-shaded-hadoop-2-2.4.1-9.0.jar from nexus-aliyun failed: SSL peer shut down incorrectly -> [Help 1]

原因:Flink最近的新版本不像1.7版本一样,有编译好的指定的hadoop版本官网上可供下载,对于hadoop 版本的编译,需要先编译安装 flink-shaded 这个项目。注意缺少的项目也有版本区分,根据报错信息,这里缺少的是9.0版本。

下面就先安装编译flink-shaded

git clone https://github.com/apache/flink-shaded.git
git checkout release-9.0

在pom.xml中,把下面内容加入到<profiles></profiles> 里面去:
<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>

编译flink-shaded:

mvn -T2C clean install -DskipTests -Pvendor-repos -Dhadoop.version=2.6.0-cdh5.15.1 -Dscala-2.11 -Drat.skip=true

再次编译flink:

mvn clean install -DskipTests -Dfast -Drat.skip=true -Dhaoop.version=2.6.0-cdh5.15.1 -Pvendor-repos -Dinclude-hadoop -Dscala-2.11 -T2C
# 过程中可能遇到下载不下来的jar,这是手动到maven中心仓库去下载,拷贝到maven对应目录即可。

编译成功后,目标文件在 ./flink-dist/target/flink-1.10.0-bin/flink-1.10.0 文件夹下,将flink-1.10.0文件夹拷出即可使用。

你可能感兴趣的:(Flink)