oozie与sqoop的简单案例

 

1:拷贝模板

2:拷贝hive用的jar包

 

方式一:

3:编辑job.properties

 1 #
 2 # Licensed to the Apache Software Foundation (ASF) under one
 3 # or more contributor license agreements.  See the NOTICE file
 4 # distributed with this work for additional information
 5 # regarding copyright ownership.  The ASF licenses this file
 6 # to you under the Apache License, Version 2.0 (the
 7 # "License"); you may not use this file except in compliance
 8 # with the License.  You may obtain a copy of the License at
 9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 
19 nameNode=hdfs://hadoop:8020
20 jobTracker=hadoop:8032
21 queueName=default
22 oozieAppsRoot=user/root/oozie-apps
23 oozieDataRoot=user/root/oozie/datas
24 
25 oozie.use.system.libpath=true
26 
27 oozie.wf.application.path=${nameNode}/${oozieAppsRoot}/sqoop-import-user
28 
29 outputDir=sqoop-import-user/output

4.编辑workflow.xml   

      注意 在这里如果要指定sqoop导出数据的格式  要用双引号 单引号没效果的 

      而且只识别单字符 不识别多字符 这里的$$$ 导出的数据格式 是 $

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!--
 3   Licensed to the Apache Software Foundation (ASF) under one
 4   or more contributor license agreements.  See the NOTICE file
 5   distributed with this work for additional information
 6   regarding copyright ownership.  The ASF licenses this file
 7   to you under the Apache License, Version 2.0 (the
 8   "License"); you may not use this file except in compliance
 9   with the License.  You may obtain a copy of the License at
10 
11        http://www.apache.org/licenses/LICENSE-2.0
12 
13   Unless required by applicable law or agreed to in writing, software
14   distributed under the License is distributed on an "AS IS" BASIS,
15   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   See the License for the specific language governing permissions and
17   limitations under the License.
18 -->
19 <workflow-app xmlns="uri:oozie:workflow:0.5" name="sqoop-wf">
20     <start to="sqoop-node"/>
21 
22     <action name="sqoop-node">
23         <sqoop xmlns="uri:oozie:sqoop-action:0.3">
24             <job-tracker>${jobTracker}</job-tracker>
25             <name-node>${nameNode}</name-node>
26             <prepare>
27                 <delete path="${nameNode}/${oozieDataRoot}/${outputDir}"/>
28             </prepare>
29             <configuration>
30                 <property>
31                     <name>mapred.job.queue.name</name>
32                     <value>${queueName}</value>
33                 </property>
34             </configuration>
35             <command>import --connect jdbc:mysql://172.16.71.27:3306/babasport --username root --password root --table bbs_buyer --target-dir /user/root/oozie/datas/sqoop-import-user/output --fields-terminated-by "$$$" --num-mappers 1</command>
36         </sqoop>
37         <ok to="end"/>
38         <error to="fail"/>
39     </action>
40 
41     <kill name="fail">
42         <message>Sqoop failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
43     </kill>
44     <end name="end"/>
45 </workflow-app>

5:上传到hdfs

1 bin/hdfs dfs -put /opt/cdh-5.3.6/oozie-4.0.0-cdh5.3.6/oozie-apps/sqoop-import-user /user/root/oozie-apps

 

6:启动测试

1  bin/oozied.sh start
2 
3  export OOZIE_URL=http://localhost:11000/oozie
4  
5  bin/oozie job -config oozie-apps/sqoop-import-user/job.properties -run

 

 

 

 

 

方式二 : 简化版

配置workflow.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!--
 3   Licensed to the Apache Software Foundation (ASF) under one
 4   or more contributor license agreements.  See the NOTICE file
 5   distributed with this work for additional information
 6   regarding copyright ownership.  The ASF licenses this file
 7   to you under the Apache License, Version 2.0 (the
 8   "License"); you may not use this file except in compliance
 9   with the License.  You may obtain a copy of the License at
10 
11        http://www.apache.org/licenses/LICENSE-2.0
12 
13   Unless required by applicable law or agreed to in writing, software
14   distributed under the License is distributed on an "AS IS" BASIS,
15   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   See the License for the specific language governing permissions and
17   limitations under the License.
18 -->
19 <workflow-app xmlns="uri:oozie:workflow:0.5" name="sqoop-wf">
20     <start to="sqoop-node"/>
21 
22     <action name="sqoop-node">
23         <sqoop xmlns="uri:oozie:sqoop-action:0.3">
24             <job-tracker>${jobTracker}</job-tracker>
25             <name-node>${nameNode}</name-node>
26             <prepare>
27                 <delete path="${nameNode}/${oozieDataRoot}/${outputDir}"/>
28             </prepare>
29             <configuration>
30                 <property>
31                     <name>mapred.job.queue.name</name>
32                     <value>${queueName}</value>
33                 </property>
34             </configuration>
35             <command>import --options-file imp-user.sql</command>
36         </sqoop>
37         <ok to="end"/>
38         <error to="fail"/>
39     </action>
40 
41     <kill name="fail">
42         <message>Sqoop failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
43     </kill>
44     <end name="end"/>
45 </workflow-app>

编辑sql脚本

 1 --connect
 2 jdbc:mysql://172.16.71.27:3306/babasport
 3 --username
 4 root
 5 --password
 6 root
 7 --table
 8 bbs_buyer
 9 --target-dir
10 /user/root/oozie/datas/sqoop-import-user/output
11 --fields-terminated-by
12 "\t"
13 --num-mappers
14 1

下列步骤和上述一致

 

转载于:https://www.cnblogs.com/xuyou551/p/8064784.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值