资源规划
组件 | LTSR003 | LTSR005 | LTSR006 | LTSR007 | LTSR008 |
---|---|---|---|---|---|
OS | centos7.6 | centos7.6 | centos7.6 | centos7.6 | centos7.6 |
JDK | jvm | jvm | jvm | jvm | jvm |
Azkaban | ExecutorServer | ExecutorServer | ExecutorServer | ExecutorServer | ExecutorServer/WebServer |
安装介质
版本:azkaban-3.47.0.tar.gz
下载:https://codeload.github.com/azkaban/azkaban/tar.gz/3.47.0
安装:https://www.cnblogs.com/bujunpeng/p/9093124.html
部署模式
模式 | 名称 | 描述 |
---|---|---|
solo-server | 独立部署模式 | 使用内置h2存储元数据 |
two-server | 两个服务器模式 | 1个webServer,1个execServer,在同一服务器上,使用mysql存储元数据 |
multiple-executor | 多执行器模式 | 1个webServer,多个execServer分布在不同服务上,使用mysql存储元数据 |
构建
cd ~/software
git clone https://github.com/azkaban/azkaban.git
cd azkaban
######################### 构建特定版本,否则将构建最新版 #########################
# git tag -l -n # 查看所有tag
# git branch -vv # 查看当前分支
# git describe --abbrev=0 --tags # 查看当前分支对应tag
# git checkout 3.47.0
######################### END #########################
./gradlew build -x test
如果构建过程特别慢或者下载失败,可以直接下载: gradle(https://services.gradle.org/distributions/gradle-4.6-all.zip) ,并放置于~/.gradle/wrapper/dists/gradle-.-all/*/下。(下载gradle的版本从~/software/azkaban/gradle/wrapper/gradle-wrapper.properties中查找)
可以通过给gradle添加国内源加快构建速度:
cd ~/.gradle
vi 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
}
}
}
每次重新开启构建过程前请清理之前的缓存:
rm -rf ~/.gradle/caches/build-cache-1/*
rm -rf ~/software/azkaban/.gradle/vcsWorkingDirs/*
./gradlew clean
./gradlew build -x test
查看构建版本:
for tar in ~/software/azkaban/azkaban-*/build/distributions/*.tar.gz; do echo $tar; done
解压待用:
cd ~/software/azkaban
# 解压到当前目录(执行以下shell的目录)
for tar in ~/software/azkaban/azkaban-*/build/distributions/*.tar.gz; do tar xvf $tar; done
元数据初始化
前提条件:需要有一个mysql服务器。
# LTSR006(MySQL安装节点)
mysql -h LTSR006 -P 3306 -u root -plonton
创建azkaban库,azkaban用户密码,并赋予远程连接,并初始化元数据。
CREATE DATABASE azkabandb;
CREATE USER 'azkauser'@'%' IDENTIFIED BY 'azkauser';
CREATE USER 'azkauser'@'localhost' IDENTIFIED BY 'azkauser';
grant all privileges on azkabandb.* to 'azkauser'@'%' identified by 'azkauser';
grant all privileges on azkabandb.* to 'azkauser'@'localhost' identified by 'azkauser';
flush privileges;
-- 初始化元数据
use azkabandb;
source ~/software/azkaban/azkaban-db-3.84.0/create-all-sql-3.84.0.sql
MySQL相关参数配置:
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
配置如下:
# 修改接受数据包大小,防止写入或更新失败(默认:1024/1KB,可用show VARIABLES like '%max_allowed_packet%';进行查看)
max_allowed_packet = 1024M
重启MySQL服务:
sudo service mysql restart
安装Azkaban-web-server
根据资源规划,Azkaban-web-server将安装于LTSR008节点。
生成密钥对和证书
Keytool是java数据证书的管理工具,使用户能够管理自己的公/私钥对及相关证书。
参数 | 功能描述 |
---|---|
-keystore | 指定密钥库的名称及位置(产生的各类信息将存在.keystore文件中) |
-genkey/-genkeypair | 生成密钥对 |
-alias | 为生成的密钥对定别名,如果没有默认是mykey |
-keyalg | 指定密钥的算法RSA/DSA,默认是DSA |
执行命令如下:
cd ~/software/azkaban/azkaban-web-server-3.84.0
keytool -keystore keystore -alias jetty -genkey -keyalg RSA
操作过程如下:
Enter keystore password: 输入密码【000000】
Re-enter new password: 再次输入密码【000000】
What is your first and last name?
[Unknown]: 直接回车
What is the name of your organizational unit?
[Unknown]: 直接回车
What is the name of your organization?
[Unknown]: 直接回车
What is the name of your City or Locality?
[Unknown]: 直接回车
What is the name of your State or Province?
[Unknown]: 直接回车
What is the two-letter country code for this unit?
[Unknown]: 直接回车
Is CN=YY, OU=YY, O=YY, L=shanghai, ST=shanghai, C=CN correct?
[no]: y
配置azkaban.properties
vi ~/software/azkaban/azkaban-web-server-3.84.0/conf/azkaban.properties
配置如下:
################## 个性化设置
# 服务器UI名称,用于服务器上方显示的名字(Unicode:龙通科技)
azkaban.name=\u9f99\u901a\u79d1\u6280
# 描述(Unicode:作业调度系统,http://www.bejson.com/convert/unicode_chinese)
azkaban.label=\u4f5c\u4e1a\u8c03\u5ea6\u7cfb\u7edf
# UI颜色
azkaban.color=#33ccff
# 默认Web文件目录
web.resource.dir=/home/lonton/software/azkaban/azkaban-web-server-3.84.0/web/
# 默认时区
default.timezone.id=Asia/Shanghai
################## 用户权限管理
user.manager.xml.file=/home/lonton/software/azkaban/azkaban-web-server-3.84.0/conf/azkaban-users.xml
################## Global配置
executor.global.properties=/home/lonton/software/azkaban/azkaban-web-server-3.84.0/conf/global.properties
################## MySQL配置
database.type=mysql
mysql.port=3306
mysql.host=LTSR006
mysql.database=azkabandb
mysql.user=azkauser
mysql.password=azkauser
mysql.numconnections=100
################## SSL配置
jetty.use.ssl=true
jetty.maxThreads=25
jetty.port=8081
jetty.ssl.port=8443
jetty.keystore=/home/lonton/software/azkaban/azkaban-web-server-3.84.0/keystore
jetty.password=000000
jetty.keypassword=000000
jetty.truststore=/home/lonton/software/azkaban/azkaban-web-server-3.84.0/keystore
jetty.trustpassword=000000
################## 邮件配置
mail.sender=450733605@qq.com
mail.host=smtp.qq.com
mail.user=450733605@qq.com
mail.password=ktzwkmykjrbpbjjc
job.failure.email=450733605@qq.com
job.success.email=450733605@qq.com
################## 执行器端口设置
executor.port=12321
添加管理员
vi ~/software/azkaban/azkaban-web-server-3.84.0/conf/azkaban-users.xml
配置如下:
<azkaban-users>
<user username="azkaban" password="azkaban" roles="admin" groups="azkaban"/>
<user username="metrics" password="metrics" roles="metrics"/>
<!-- 自定义管理员(lonton/lonton) -->
<user username="lonton" password="lonton" roles="admin,metrics" />
<role name="admin" permissions="ADMIN" />
<role name="metrics" permissions="METRICS"/>
</azkaban-users>
安装Azkaban-exec-server
配置azkaban.properties
vi ~/software/azkaban/azkaban-exec-server-3.84.0/conf/azkaban.properties
配置如下:
################## 个性化设置
# 默认时区
default.timezone.id=Asia/Shanghai
################## Global配置
executor.global.properties=/home/lonton/software/azkaban/azkaban-exec-server-3.84.0/conf/global.properties
################## azkaban Web Server URL
azkaban.webserver.url=https://LTSR008:8443
################## 插件配置
azkaban.jobtype.plugin.dir=/home/lonton/software/azkaban/azkaban-exec-server-3.84.0/plugins/jobtypes
################## MySQL配置
database.type=mysql
mysql.port=3306
mysql.host=LTSR006
mysql.database=azkabandb
mysql.user=azkauser
mysql.password=azkauser
mysql.numconnections=100
################## 执行器端口设置
executor.port=12321
配置commonprivate.properties
vi ~/software/azkaban/azkaban-exec-server-3.84.0/plugins/jobtypes/commonprivate.properties
配置如下:
execute.as.user=false
azkaban.native.lib=false
添加derby.jar
由于jdk-8u121-linux-x64.tar.gz之后很多版本中不含db\lib\derby.jar,则运行Azkaban工程将抛出如下异常:Exception in thread “main” java.lang.NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.AutoloadedDriver40
解决方法:
解压jdk-8u121-linux-x64.tar.gz,找到derby.jar,然后上传到${Web-Server-HOME}/lib和${Exec-Server-HOME}/lib中,然后重新启动。
derby.jar
分发
xsync ~/software/azkaban/azkaban-exec-server-*
启动验证
先启动executor,再启动web,避免Web Server会因为找不到执行器而启动失败。
启动executor
cd ~/software/azkaban/azkaban-exec-server-3.84.0/bin
# 启动
./start-exec.sh
# 示例:LTSR008节点,激活executor
curl http://LTSR008:12321/executor?action=activate
curl http://LTSR003:12321/executor?action=activate
curl http://LTSR005:12321/executor?action=activate
curl http://LTSR006:12321/executor?action=activate
curl http://LTSR007:12321/executor?action=activate
# 停止
./shutdown-exec.sh
启动Web Server
cd ~/software/azkaban/azkaban-web-server-3.84.0/bin
# 启动
./start-web.sh
# 停止
./shutdown-web.sh
验证服务
https://ltsr008:8443 (lonton/lonton)
改进执行器
在使用Azkaban时我们会面临将某些任务放到指定的executor上去运行的情况,我们通过executor的id(useExecutor)来指定executor服务器去执行任务。
可通过查看数据库的方式,获取exec_id:
-- mysql -h LTSR006 -P 3306 -u root -plonton
use azkabandb;
select * from executors;
但是,当集群由于某些原因挂掉,executor重启后exec_id默认是自增长的,这就产生一个很麻烦的问题,我们需要将所有任务重新进行配置。
可通过以下思路解决:在启动executor后,executor会向元数据库executors表注册,shell脚本(start-exec-upgrade.sh)中,首先判断executor是否启动,如果启动就执行更改数据库的操作。
#!/bin/bash
# Start service for azkaban
# Base Env
SCRIPTS_DIR=$(dirname $0)
HOSTNAME=`hostname -f`
# User Env For MySQL
PORT="3306"
USERNAME="azkauser"
PASSWORD="azkauser"
DBNAME="azkabandb"
HOST="LTSR006"
# Azkaban activate status
ACTIVE=1
# Get the IP address the last (custom DIY)
ID=3
# pass along command line arguments to the internal launch script.
${SCRIPTS_DIR}/internal/internal-start-executor.sh "$@" >executorServerLog__`date +%F+%T`.out 2>&1 &
# MySQL Exc
MYSQL="mysql -u${USERNAME} -p${PASSWORD} -h${HOST} ${DBNAME}"
select_sql="select count(1) from executors where host='${HOSTNAME}'"
update_sql="update executors set id=${ID},active=${ACTIVE} where host='${HOSTNAME}';"
while true
do
res=`$MYSQL -e "$select_sql" 2>/dev/null | sed '1d'`
if [ $res -eq 1 ];then
break
fi
sleep 3
echo -e "...."
done
# Update
$MYSQL -e "$update_sql" 2>/dev/null
[ $? -eq 0 ] && echo "start ......" || {
echo "stop ......"
}
将start-exec-upgrade.sh分发至各个excutor节点,并修改对应的id,之后重新启动并激活。
# 分发
xsync ~/software/azkaban/azkaban-exec-server-*
# 脚本赋权
xcall chmod 755 ~/software/azkaban/azkaban-exec-server-3.84.0/bin/start-exec-upgrade.sh
# 修改节点对应exec_id
cd ~/software/azkaban/azkaban-exec-server-3.84.0/bin
vi start-exec-upgrade.sh
############ LTSR003
# ID=3
############ LTSR005
# ID=5
############ LTSR006
# ID=6
############ LTSR007
# ID=7
############ LTSR008
# ID=8
# 启动
bash start-exec-upgrade.sh
# 激活(未激活作业执行抛异常:executor became inactive before setting up the flow xx)
curl http://LTSR008:12321/executor?action=activate
curl http://LTSR003:12321/executor?action=activate
curl http://LTSR005:12321/executor?action=activate
curl http://LTSR006:12321/executor?action=activate
curl http://LTSR007:12321/executor?action=activate
# 停止
./shutdown-exec.sh