【参考官网:http://archive.cloudera.com/cdh5/cdh/5/oozie-4.1.0-cdh5.7.0/DG_ShellActionExtension.html】
一、实现功能
使用oozie调度运行本地shell脚本,实现脚本shell脚本自动化执行。
二、步骤
1.拷贝官方自带实例模板
cp -r examples/apps/shell/ oozie-apps
2.修改job.properties
nameNode=hdfs://hadoop:8020
jobTracker=hadoop:8032
queueName=default
examplesRoot=oozie-apps
oozie.wf.application.path=${nameNode}/user/hadoop/${examplesRoot}/shell
EXEC=mem.sh #放一个脚本文件,脚本文件名称
3.修改workflow.xml
<start to="shell-node"/>
<action name="shell-node">
<shell xmlns="uri:oozie:shell-action:0.2">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<exec>${EXEC}</exec>
<file>${nameNode}/user/hadoop/${examplesRoot}/shell/${EXEC}#${EXEC}</file>
</shell>
<ok to="end"/>
<error to="fail"/>
</action>
<kill name="fail">
<message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
4.在shell目录下创建mem.sh
#!/bin/sh
/usr/bin/date -R >> /opt/modules/oozie-4.1.0-cdh5.7.0/oozie-apps/shell/1.log
/usr/bin/free -m >> /opt/modules/oozie-4.1.0-cdh5.7.0/oozie-apps/shell/1.log
/usr/bin/df -lh >> /opt/modules/oozie-4.1.0-cdh5.7.0/oozie-apps/shell/1.log
echo ------------------- >> /opt/modules/oozie-4.1.0-cdh5.7.0/oozie-apps/shell/1.log
备注:/usr/bin/date为命令绝对路径,可以通过which date获得
5.上传到hdfs
bin/hdfs dfs -put /opt/modules/oozie-4.1.0-cdh5.7.0/oozie-apps/shell /user/hadoop/oozie-apps/
6.执行:
bin/oozie job -oozie http://hadoop:11000/oozie -config oozie-apps/shell/job.properties -run
7.检查结果
/opt/modules/oozie-4.1.0-cdh5.7.0/oozie-apps/shell下
cat 1.log
结果:
[root@hadoop shell]# cat 1.log
Thu, 06 Dec 2018 21:32:33 +0800
total used free shared buff/cache available
Mem: 7822 3789 3050 8 982 3729
Swap: 0 0 0
Filesystem Size Used Avail Use% Mounted on
/dev/vda2 39G 17G 21G 45% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.8M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 976M 146M 764M 17% /boot
tmpfs 783M 0 783M 0% /run/user/0