设为首页 收藏本站
查看: 1006|回复: 0

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

[复制链接]

尚未签到

发表于 2016-12-13 09:41:37 | 显示全部楼层 |阅读模式
一、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+ Nojdbc:hsqldb:*//
MySQL 5.0+ Yesjdbc:mysql://
Oracle 10.2.0+ Nojdbc:oracle:*//
PostgreSQL 8.3+ Yes (import only)jdbc:postgresql://

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-313608-1-1.html 上篇帖子: Hadoop学习三十六:使用BulkLoad时Bulk load operation did not find any files 下篇帖子: 第七章:小朱笔记hadoop之源码分析-hdfs分析 第四节:namenode-DecommissionManager
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表