#hivef.job
type=command
command=hive -f test.sql
#test.sql
use default;
drop table aztest;
create table aztest(id int,name string) row format delimited fields terminated by ",";
load data inpath '/home/lxl/b.txt' into table aztest;
create table azres as select * from aztest;
注意:因为azkaban是root用户安装的,所以在执行hivef.job文件时,里的command=su hdfs hive -f test.sql 需要写成这样,哈哈。
如果是root用户需要在hdfs配置中去掉权限,不然执行不了。 在HDFS配置页面,找到属性dfs.permissions,取消勾选即可。
1.先把把文件b.txt上传到hdfs服务器
/root/device-report
其中b.txt内容如下:
2,bb
3,cc
7,yy
9,pp
2.修改文件权限
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120344600-2059836495.png)
3.放到hdfs用户目录下:
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120402342-725897499.png)
4.切换到hdfs用户下:
su hdfs
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120419867-479946588.png)
5.把b.txt上传到hdfs服务器上:
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120433090-930086907.png)
6.把test.sql,hivef打包zip文件
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120445165-1601288028.png)
7.azkaban中创建计划项目,如下:
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120504743-1584090322.png)
8.上传zip文件:
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120524554-389991997.png)
9.添加执行计划:
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120544388-2049392653.png)
10.直接执行:
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120605144-2028811303.png)
11.执行后显示如下:
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120630641-22338199.png)
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120649531-1577106257.png)
12.看hive中是否有aztest和azres表
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120703506-606479496.png)
看是否都有数据:
![](https://img2018.cnblogs.com/blog/1490397/201809/1490397-20180914120717156-2001255314.png)
完美,但是还是建议在hdfs上安装azkaban。
以下是切换到hdfs用户下执行创建表等,以后请按这样的格式进行执行job。
#hivef.job
type=command
command=sudo -u hdfs hive -f test.sql
#test.sql
use default;
drop table aztest;
create table aztest(id int,name string) row format delimited fields terminated by ",";
load data inpath '/home/lxl/b.txt' into table aztest;
create table azres as select * from aztest;