[Hadoop]Sqoop 1.4.2中文文档(三)之SqoopJob与其外的操作

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:
一、sqoop job相关命令参数
usage: sqoop job [GENERIC-ARGS] [JOB-ARGS] [-- [<tool-name>] [TOOL-ARGS]]

Job management arguments:
   --create <job-id>            Create a new saved job
   --delete <job-id>            Delete a saved job
   --exec <job-id>              Run a saved job
   --help                       Print usage instructions
   --list                       List saved jobs
   --meta-connect <jdbc-uri>    Specify JDBC connect string for the
                                metastore
   --show <job-id>              Show the parameters for a saved job
   --verbose                    Print more information while working

Generic Hadoop command-line arguments:
(must preceed any tool-specific arguments)
Generic options supported are
-conf <configuration file>     specify an application configuration file
-D <property=value>            use value for given property
-fs <local|namenode:port>      specify a namenode
-jt <local|jobtracker:port>    specify a job tracker
-files <comma separated list of files>    specify comma separated files to be copied to the map reduce cluster
-libjars <comma separated list of jars>    specify comma separated jar files to include in the classpath.
-archives <comma separated list of archives>    specify comma separated archives to be unarchived on the compute machines.


简单第一眼望去,终于比导入和导出的参数少了很多,自然内容好说一些。 

Job存在的目的,是对频繁只用不变化的导入导出工作做自动化处理,例如创建一个Job每天做增量导入,导入最新的数据,这样的任务就可以使用Job来进行。 

举个例子: 
创建一个Job
$ sqoop job --create myjob -- import --connect jdbc:mysql://example.com/db \
    --table mytable


查询当前Job列表 
$ sqoop job --list
Available jobs:
  myjob



查看某个Job的详情:
 $ sqoop job --show myjob
 Job: myjob
 Tool: import
 Options:
 ----------------------------
 direct.import = false
 codegen.input.delimiters.record = 0
 hdfs.append.dir = false
 db.table = mytable
 ...


执行某个Job: 
$ sqoop job --exec myjob
10/08/19 13:08:45 INFO tool.CodeGenTool: Beginning code generation
...

执行时重写相关参数,例如你数据库的用户名和密码改变了:
$ sqoop job --exec myjob -- --username someuser -P
Enter password:
...

拥有--meta-connect私有存储空间的hadoop机器才能进行job操作,否则将会报如下错误:
[work@vm-nba01 ~]$ sqoop job --list
12/10/24 16:38:34 ERROR tool.JobTool: There is no JobStorage implementation available
12/10/24 16:38:34 ERROR tool.JobTool: that can read your specified storage descriptor.
12/10/24 16:38:34 ERROR tool.JobTool: Don't know where to save this job info! You may
12/10/24 16:38:34 ERROR tool.JobTool: need to specify the connect string with --meta-connect.

也就是说机器不知道你要的Job保存在哪里了,所以关于一切Job的操作都是徒劳的。 

二、Metastore connection options  
上面Joblist出错的问题这里就可以解决了,这里可以教你怎么创建Job的存储空间,相关参数:
Argument	 Description
--meta-connect <jdbc-uri>	 Specifies the JDBC connect string used to connect to the metastore

默认你会在$HOME/.sqoop目录下有一个私有的数据存储,你通过sqoop-metastore命令可以使用热数据存储来建立空间 
By default, a private metastore is instantiated in $HOME/.sqoop. If you have configured a hosted metastore with the sqoop-metastore tool, you can connect to it by specifying the --meta-connect argument. This is a JDBC connect string just like the ones used to connect to databases for import. 

In conf/sqoop-site.xml, you can configure sqoop.metastore.client.autoconnect.url with this address, so you do not have to supply --meta-connect to use a remote metastore. This parameter can also be modified to move the private metastore to a location on your filesystem other than your home directory. 

If you configure sqoop.metastore.client.enable.autoconnect with the value false, then you must explicitly supply --meta-connect.(上述位置待以后实际操作后再翻译) 

找到sqoop-site.xml的配置文件,发现如下配置:
<property>
    <name>sqoop.metastore.client.enable.autoconnect</name>
    <value>false</value>
    <description>If true, Sqoop will connect to a local metastore
      for job management when no other metastore arguments are
      provided.
    </description>
  </property>

看来这个值设置为了false,导致不能够使用Job相关操作了。
<property>
    <name>sqoop.metastore.client.record.password</name>
    <value>true</value>
    <description>If true, allow saved passwords in the metastore.
    </description>
  </property>

当这个值为真的时候才会保存密码。 

sqoop-metastore命令可以检查你配置sqoop数据连接的正确性,当然这些配置还是在sqoop-site.xml中。 

sqoop-merge命令可以允许你合并2个数据集到1个数据集。merge命令的相关参数: 
Argument	 Description
--class-name <class>	 Specify the name of the record-specific class to use during the merge job.
--jar-file <file>	 Specify the name of the jar to load the record class from.
--merge-key <col>	 Specify the name of a column to use as the merge key.
--new-data <path>	 Specify the path of the newer dataset.
--onto <path>	         Specify the path of the older dataset.
--target-dir <path>	 Specify the target path for the output of the merge job.

举例:
$ sqoop merge --new-data newer --onto older --target-dir merged \
    --jar-file datatypes.jar --class-name Foo --merge-key id

这样就会运行一个MapReduce的任务,新的数据集使用优先度高于老的数据集。 
它能被使用在both SequenceFile-, Avro- and text-based incremental imports.并且新老的数据类型时相同的。 

sqoop-codegen命令可以还原的你的java类,如果你的源码java丢失了,但是数据没有丢失,可以使用这样的命令: 
$ sqoop codegen --connect jdbc:mysql://db.example.com/corp \
    --table employees


sqoop-create-hive-table可以创建一个Hive表,复制某一个数据源的数据存储格式,例如:
$ sqoop create-hive-table --connect jdbc:mysql://db.example.com/corp \
    --table employees --hive-table emps


sqoop-eval命令可以让用户快速做一个操作,结果显示在控制台中。例如: 
$ sqoop eval --connect jdbc:mysql://db.example.com/corp \
    --query "SELECT * FROM employees LIMIT 10"


$ sqoop eval --connect jdbc:mysql://db.example.com/corp \
    -e "INSERT INTO foo VALUES(42, 'bar')"


sqoop-list-databases查看某个数据源的数据库列表,例如:
$ sqoop list-databases --connect jdbc:mysql://database.example.com/
information_schema
employees


sqoop-list-tables查看某个数据源的表列表,例如: 
$ sqoop list-tables --connect jdbc:mysql://database.example.com/corp
employees
payroll_checks
job_descriptions
office_supplies


sqoop现在支持的数据库:
Database	 version	--direct support?	 connect string matches
HSQLDB	 1.8.0+	 No	jdbc:hsqldb:*//
MySQL	 5.0+	 Yes	jdbc:mysql://
Oracle	 10.2.0+	 No	jdbc:oracle:*//
PostgreSQL	 8.3+	 Yes (import only)	jdbc:postgresql://


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4月前
|
Java Shell 分布式数据库
【大数据技术Hadoop+Spark】HBase数据模型、Shell操作、Java API示例程序讲解(附源码 超详细)
【大数据技术Hadoop+Spark】HBase数据模型、Shell操作、Java API示例程序讲解(附源码 超详细)
84 0
|
6月前
|
分布式计算 Hadoop 大数据
大数据Hadoop之——Apache Hudi 数据湖实战操作(Spark,Flink与Hudi整合)
大数据Hadoop之——Apache Hudi 数据湖实战操作(Spark,Flink与Hudi整合)
|
4月前
|
分布式计算 大数据 Scala
【大数据技术Hadoop+Spark】Spark RDD创建、操作及词频统计、倒排索引实战(超详细 附源码)
【大数据技术Hadoop+Spark】Spark RDD创建、操作及词频统计、倒排索引实战(超详细 附源码)
92 1
|
3月前
|
分布式计算 关系型数据库 Hadoop
使用Sqoop将数据从Hadoop导出到关系型数据库
使用Sqoop将数据从Hadoop导出到关系型数据库
|
3月前
|
分布式计算 Hadoop 关系型数据库
使用Sqoop将数据导入Hadoop的详细教程
使用Sqoop将数据导入Hadoop的详细教程
|
3月前
|
分布式计算 Hadoop 关系型数据库
Hadoop中的Sqoop是什么?请解释其作用和用途。
Hadoop中的Sqoop是什么?请解释其作用和用途。
34 0
|
4月前
|
分布式计算 Hadoop Java
简单操作hadoop
简单操作hadoop
39 2
|
8月前
|
分布式计算 Hadoop Shell
Hadoop的Shell操作
Hadoop的Shell操作
83 0
|
8月前
|
存储 机器学习/深度学习 分布式计算
Hadoop基础学习---3、HDFS概述、HDFS的Shell操作、HDFS的API操作
Hadoop基础学习---3、HDFS概述、HDFS的Shell操作、HDFS的API操作
|
11月前
|
分布式计算 Hadoop Shell
开启hadoop后对文件执行shell操作
开启hadoop后对文件执行shell操作