目录
Azkaban使用实例
Azkaba内置的任务类型支持command、java。
单一job案例
针对于不存在依赖的单一任务需求。
(1)创建job文件:
[root@bigdata111 opt]# vi test1.job
#test1.job
type=command
command=mkdir -p /opt/azkaban_test
command.1=touch /opt/azkaban_test/test1_result.txt
command.2=echo 'test1_result' >> test1_result.txt
(2)将job文件打包成zip文件
目前,Azkaban上传的工作流文件只支持xxx.zip文件。zip应包含xxx.job运行作业所需的文件和任何文件(文件名后缀必须以.job结尾,否则无法识别)。作业名称在项目中必须是唯一的。
(3)通过azkaban的web平台创建project,并且上传job中的zip包
创建工程:
上传zip包
执行工作流
设置2分钟后执行job,
之后我们可以看到
结果:
多job工作流案例
创建有依赖关系的多个job描述。
(1)创建job1描述
#将test1_result上传到HDFS
type=command
command= hdfs dfs -put /opt/azkaban_test/test1_result.txt /
(2)job2,依赖于job1
##词频分析
type=command
command=hadoop jar /opt/module/hadoop-2.8.4/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8.4.jar wordcount /test1_result.txt /test2_result
dependencies=test2_1
(3)打包上传并运行
结果:
java操作任务
azkaban也支持java程序,但是需要将其打成jar包,然后压缩成zip格式上传。
(1)编写java程序
import java.io.FileOutputStream;
import java.io.IOException;
public class AzkabanTest {
public void run() throws IOException {
// 根据需求编写具体代码
FileOutputStream fos = new FileOutputStream("/opt/module/azkaban/output.txt");
fos.write("this is a java progress".getBytes());
fos.close();
}
public static void main(String[] args) throws IOException {
AzkabanTest azkabanTest = new AzkabanTest();
azkabanTest.run();
}
}
(2)将java程序打成jar包,编写job文件
#azkabanJava.job
type=javaprocess
java.class=AzkabanTest(全类名)
classpath=/opt/module/azkaban/lib/*
(3)压缩后上传。
Hadoop操作任务
其实在多job任务中已经使用了hadoop命令,步骤参上。
Hive脚本任务
(1)创建job描述文件和hive脚本
#Hive脚本
use default;
drop table student;
create table student(id int, name string)
row format delimited fields terminated by '\t';
load data local inpath '/opt/module/datas/student.txt' into table student;
insert overwrite local directory '/opt/module/datas/student'
row format delimited fields terminated by '\t'
select * from student;
(2)编写job命令
#hive job
type=command
command=/opt/module/hive/bin/hive -f /opt/module/azkaban/jobs/student.sql
(3)压缩并上传。