:node
一、安裝好mysql、Hadoop、oozie、hivemysql
二、上面安裝的軟件皆可正確執行web
開始:sql
用oozie調度sqoop1 Action 須要準備三個基本文件,workflow.xml、job.properties、hive-site.xml(其實也能夠不要,後面會說)文件app
一、在HDFS建立一個oozie的工做流應用保存路徑,我建立的是/user/oozieDemo/workflows/sq2hiveDemo,在此路徑下再建立一個lib目錄,以下圖所示oop
二、將mysql的驅動程序上傳到lib目錄下spa
三、編寫job.properties文件,文件內容以下:命令行
oozie.wf.application.path=hdfs://NODE3:8020/user/oozieDemo/workflows/sq2hiveDemoxml
#Shell Script to runip
EXEC=sq2hive.sh
jobTracker=NODE3:8032
nameNode=hdfs://NODE3:8020
queueName=default
oozie.use.system.libpath=true
oozie.libpath=/user/oozie/share/lib/lib_20150708191612
user.name=root
四、編寫workflow.xml文件,也就是sqoopAction的配置文件,此處能夠有兩種配置文件,一種是命令行模式,一種是參數模式
命令行模式的workflow.xml配置文件:
<workflow-app xmlns='uri:oozie:workflow:0.1' name='sq2hive-wf'>
<start to='sq2hive' />
<action name='sq2hive'>
<sqoop xmlns="uri:oozie:sqoop-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>
<property>
<name>hive.metastore.uris</name>
<value>thrift://172.17.20.2:9083</value>
</property>
</configuration>
<command>import --connect jdbc:mysql://172.17.20.4/scm --username root --password root --table ROLES --columns "ROLE_ID,NAME,HOST_ID" --delete-target-dir --hive-import --hive-overwrite --hive-table sun.roles -m 2</command>
</sqoop>
<ok to="end" />
<error to="fail" />
</action>
<kill name="fail">
<message>Script failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name='end' />
參數模式的workflow.xml配置文件:
<workflow-app xmlns='uri:oozie:workflow:0.1' name='sq2hive-wf'>
<start to='sq2hive' />
<action name='sq2hive'>
<sqoop xmlns="uri:oozie:sqoop-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>
<property>
<name>hive.metastore.uris</name>
<value>thrift://172.17.20.2:9083</value>
</property>
</configuration>
<arg>import</arg>
<arg>--connect</arg>
<arg>jdbc:mysql://172.17.20.4/scm</arg>
<arg>--username</arg>
<arg>root</arg>
<arg>--password</arg>
<arg>root</arg>
<arg>--table</arg>
<arg>ROLES</arg>
<arg>--columns</arg>
<arg>ROLE_ID,NAME,HOST_ID</arg>
<arg>--delete-target-dir</arg>
<arg>--hive-import</arg>
<arg>--hive-overwrite</arg>
<arg>--hive-table</arg>
<arg>sun.roles</arg>
<arg>-m</arg>
<arg>2</arg>
<file>/user/oozieDemo/workflows/sq2hiveDemo/hive-site.xml#hive-site.xml</file>
</sqoop>
<ok to="end" />
<error to="fail" />
</action>
<kill name="fail">
<message>Script failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name='end' />
</workflow-app>
5,將 workflow.xml文件上傳到HDFS上,即oozie工做流應用路徑/user/oozieDemo/workflows /sq2hiveDemo下,同時將job.properties(也能夠不用上傳,運行OOzie的job時指定的是本地的 job.properties)和hive-site.xml上傳到此路徑下,以下圖:
6,使用命令行方式提交併啓動剛剛寫好的工做流:命令以下:
oozie job --oozie http://node1:11000/oozie --config job.properties -run
此命令爲提交併啓動job
7,能夠經過oozie web界面或者 hue的workflow查看界面查看job執行狀況,hue下查看以下: