软件包
- JDK
版本:jdk-8u251-linux-x64.tar.gz
下载:https://www.oracle.com/technetwork/pt/java/javase/downloads/jdk8-downloads-2133151.html?printOnly=1
- Azkaban
版本:azkaban-3.91.0
下载:https://github.com/azkaban/azkaban.git
- Gradle
版本:gradle-4.6-all.zip
下载:https://services.gradle.org/distributions/gradle-4.6-all.zip
1. 获取镜像
# 查看可用的稳定版本
sudo docker search centos
# centos-7.7(镜像:204MB)
sudo docker pull centos:centos7.7.1908
sudo docker image ls |grep centos
2. 创建镜像并启动容器
sudo docker run -itd --name azkaban-compile --privileged -e TZ="Asia/Shanghai" -p 8181:8081 -p 8443:8443 -e LANG=en_US.UTF-8 --restart=always -d centos:centos7.7.1908 /usr/sbin/init
sudo docker ps |grep azkaban-compile
sudo docker start azkaban-compile
sudo docker restart azkaban-compile
sudo docker stop azkaban-compile
sudo docker rm azkaban-compile
参数说明:
- —name:为容器命名。
- -p:为端口映射,主要是为了方便主机和docker容器内通信。
- -v:为文件映射,主要是为了方便docker容器与主机文件传输。
- -d:为镜像的Id。
3. 安装Azkaban
1. 下载源码包
sudo docker exec -it azkaban-compile /bin/bash
# 安装git
yum install git
cd /usr/local/include
# 克隆源码
git clone https://github.com/azkaban/azkaban.git
# GitHub克隆速度太慢时可先同步至码云
git clone https://gitee.com/mygiteepolaris/azkaban.git
cd azkaban
# 查看源码当前版本
git tag
# 切换源码版本(当前最新tag为:3.90.0,而本次要编译3.91.0,故此处不需要checkout,如果编译其他版本请切换)
#git checkout 3.91.0
2. 安装JDK
# 宿主机执行
sudo docker cp /root/docker/jdk-8u221-linux-x64.tar.gz azkaban-compile:/usr/local/include/
解压
# 进入容器
sudo docker exec -it azkaban-compile /bin/bash
cd /usr/local/include
mkdir -p ~/modules/
tar -zxvf jdk-8u221-linux-x64.tar.gz -C ~/modules/
环境变量设置
vi /etc/profile
配置如下:
export JAVA_HOME=/root/modules/jdk1.8.0_221
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/tools.jar
环境变量生效:
source /etc/profile
验证
java -version
3. Gradle配置
sudo docker exec -it azkaban-compile /bin/bash
# 版本查看(gradle-*.*-all.zip)
cat /usr/local/include/azkaban/gradle/wrapper/gradle-wrapper.properties
mkdir -p ~/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg/
# 宿主机执行
cd ~/docker/
wget https://services.gradle.org/distributions/gradle-4.6-all.zip
sudo docker cp /root/docker/gradle-4.6-all.zip azkaban-compile:/root/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg/
1. 修改仓库配置
sudo docker exec -it azkaban-compile /bin/bash
vi ~/.gradle/init.gradle
配置如下(新增):
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
2. 修改编译配置
vi /usr/local/include/azkaban/build.gradle
内容如下: ```bash buildscript { repositories { maven { url ‘https://maven.aliyun.com/nexus/content/groups/public/‘ } mavenCentral() } dependencies { classpath ‘com.cinnober.gradle:semver-git:2.2.3’ classpath ‘net.ltgt.gradle:gradle-errorprone-plugin:0.0.14’ } }
allprojects { apply plugin: ‘jacoco’
repositories { maven { url ‘https://maven.aliyun.com/nexus/content/groups/public/‘ } mavenLocal() mavenCentral() } }
/ 修改restli的版本号(28.3.11在阿里云仓库中没有)/ ext.versions = [hadoop: ‘2.6.1’, hive : ‘1.1.0’, pig : ‘0.11.0’, restli: ‘27.7.18’, slf4j : ‘1.7.18’,]
<a name="Lq7Sr"></a>
### 3. 源码修改(选)
此步骤根据实际情况需要进行操作,此处修改添加Azkaban Web UI登录时Post请求跳转和跨域功能。修改的Java类为:“azkaban.webapp.servlet.LoginAbstractAzkabanServlet”、“azkaban.webapp.servlet.StatusServlet”、“azkaban.webapp.APIMetricsFilter”。
```bash
# 1.上传修改后的Java源文件至宿主机
# 2.将Java源文件从宿主机上传至容器
sudo docker cp /root/docker/APIMetricsFilter.java azkaban-compile:/usr/local/include/azkaban/azkaban-web-server/src/main/java/azkaban/webapp/APIMetricsFilter.java
sudo docker cp /root/docker/LoginAbstractAzkabanServlet.java azkaban-compile:/usr/local/include/azkaban/azkaban-web-server/src/main/java/azkaban/webapp/servlet/LoginAbstractAzkabanServlet.java
sudo docker cp /root/docker/StatusServlet.java azkaban-compile:/usr/local/include/azkaban/azkaban-web-server/src/main/java/azkaban/webapp/servlet/StatusServlet.java
修改后的源码:azkaban-web-server-3.91.0-src-fix.zip
4. 构建源码
# 每次重新开启构建过程前请清理之前的缓存
rm -rf ~/.gradle/caches/build-cache-1/*
rm -rf /usr/local/include/azkaban/.gradle/vcsWorkingDirs/*
# 进入源码编译根目录
cd /usr/local/include/azkaban/
# 方式1(推荐)
./gradlew build installDist -x test
# 方式2
./gradlew clean
./gradlew build -x test
# 清理
rm -rf ~/.gradle/caches/modules-2/files-2.1
rm -rf ~/.gradle/caches/modules-2/metadata-2.*/descriptors
4. 启动
# Solo模式启动
sudo docker exec -it azkaban-compile /bin/bash
cd /usr/local/include/azkaban/azkaban-solo-server/build/install/azkaban-solo-server
source /etc/profile
./bin/start-solo.sh
./bin/shutdown-solo.sh
5. 端口暴露(可选)
注意:若启动容器时已经配置相关端口的暴露则可忽略如下操作。
# 查看容器IP
sudo docker inspect azkaban-compile| grep IPAddress
sudo docker port azkaban-compile
# 将主机8181映射到容器8081端口
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 8181 -j DNAT --to-destination 172.17.0.2:8081
# 保存iptables规则
iptables-save
# 查看iptables规则
iptables -t nat -nvL --line-number| grep 172.17.0.2
# 删除iptables规则
iptables -t nat -D PREROUTING 4
# 验证iptables规则
# 容器
curl http://172.17.0.2:8081
# 宿主机
curl http://192.168.216.100:8181
6. 验证
Web UI:http://192.168.216.100:8181
账户口令:azkaban/azkaban
7. 备份
# 备份azkaban编译后的结果
sudo docker exec -it azkaban-compile /bin/bash
cd /usr/local/include/azkaban/azkaban-solo-server/build/install
tar -cvf azkaban-3.91.0-solo-server.fix.build.tar azkaban-solo-server
# 将容器中的azkaban压缩包拷贝至宿主机(宿主机上执行)
docker cp azkaban-compile:/usr/local/include/azkaban/azkaban-solo-server/build/install/azkaban-3.91.0-solo-server.fix.build.tar /root/docker/