zoukankan      html  css  js  c++  java
  • 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 "	"
    13 --num-mappers
    14 1

    下列步骤和上述一致

  • 相关阅读:
    Tomcat 中会话超时的相关配置
    Oracle10g任务调度创建步骤
    Oracle的三种高可用集群方案
    软/硬件负载均衡产品 你知多少?
    Nginx、LVS及HAProxy负载均衡软件的优缺点详解
    java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误
    TortoiseSVN客户端重新设置用户名和密码
    Linux下oracle数据库启动和关闭操作
    Linux下使用ps命令来查看Oracle相关的进程
    【Kill】两条Linux命令彻底杀死Oracle
  • 原文地址:https://www.cnblogs.com/xuyou551/p/8064784.html
Copyright © 2011-2022 走看看