软件包

  • 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. 获取镜像

  1. # 查看可用的稳定版本
  2. sudo docker search centos
  3. # centos-7.7(镜像:204MB)
  4. sudo docker pull centos:centos7.7.1908
  5. sudo docker image ls |grep centos

2. 创建镜像并启动容器

  1. 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
  2. sudo docker ps |grep azkaban-compile
  3. sudo docker start azkaban-compile
  4. sudo docker restart azkaban-compile
  5. sudo docker stop azkaban-compile
  6. sudo docker rm azkaban-compile

参数说明:

  • —name:为容器命名。
  • -p:为端口映射,主要是为了方便主机和docker容器内通信。
  • -v:为文件映射,主要是为了方便docker容器与主机文件传输。
  • -d:为镜像的Id。

    3. 安装Azkaban

    1. 下载源码包

    1. sudo docker exec -it azkaban-compile /bin/bash
    2. # 安装git
    3. yum install git
    4. cd /usr/local/include
    5. # 克隆源码
    6. git clone https://github.com/azkaban/azkaban.git
    7. # GitHub克隆速度太慢时可先同步至码云
    8. git clone https://gitee.com/mygiteepolaris/azkaban.git
    9. cd azkaban
    10. # 查看源码当前版本
    11. git tag
    12. # 切换源码版本(当前最新tag为:3.90.0,而本次要编译3.91.0,故此处不需要checkout,如果编译其他版本请切换)
    13. #git checkout 3.91.0

    2. 安装JDK

    1. # 宿主机执行
    2. sudo docker cp /root/docker/jdk-8u221-linux-x64.tar.gz azkaban-compile:/usr/local/include/
  1. 解压

    1. # 进入容器
    2. sudo docker exec -it azkaban-compile /bin/bash
    3. cd /usr/local/include
    4. mkdir -p ~/modules/
    5. tar -zxvf jdk-8u221-linux-x64.tar.gz -C ~/modules/
  2. 环境变量设置

    1. vi /etc/profile

    配置如下:

    1. export JAVA_HOME=/root/modules/jdk1.8.0_221
    2. export PATH=$JAVA_HOME/bin:$PATH
    3. export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/tools.jar

    环境变量生效:

    1. source /etc/profile
  3. 验证

    1. java -version

    3. Gradle配置

    1. sudo docker exec -it azkaban-compile /bin/bash
    2. # 版本查看(gradle-*.*-all.zip)
    3. cat /usr/local/include/azkaban/gradle/wrapper/gradle-wrapper.properties
    4. mkdir -p ~/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg/
    5. # 宿主机执行
    6. cd ~/docker/
    7. wget https://services.gradle.org/distributions/gradle-4.6-all.zip
    8. sudo docker cp /root/docker/gradle-4.6-all.zip azkaban-compile:/root/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg/

    1. 修改仓库配置

    1. sudo docker exec -it azkaban-compile /bin/bash
    2. vi ~/.gradle/init.gradle

    配置如下(新增):

    1. allprojects{
    2. repositories {
    3. def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
    4. def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
    5. all { ArtifactRepository repo ->
    6. if(repo instanceof MavenArtifactRepository){
    7. def url = repo.url.toString()
    8. if (url.startsWith('https://repo1.maven.org/maven2')) {
    9. project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
    10. remove repo
    11. }
    12. if (url.startsWith('https://jcenter.bintray.com/')) {
    13. project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
    14. remove repo
    15. }
    16. }
    17. }
    18. maven {
    19. url ALIYUN_REPOSITORY_URL
    20. url ALIYUN_JCENTER_URL
    21. }
    22. }
    23. }

    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/