sqoop的安装使用

傷城~ 2022-04-21 14:22 275阅读 0赞

[b][color=olive][size=large]散仙,在上篇文章中,简述了sqoop的的功能,作用,以及版本演进,那么本篇我们就来实战下,看下如下安装使用sqoop(注:散仙在这里部署的是sqoop1的环境搭建)。

首先,sqoop是基于Hadoop工作的,所以在这之前,确保你的Linux环境下,已经有可以正常工作的hadoop集群,当然伪分布式和完全分布式都可以。
[/size][/color][/b]

[b][color=green][size=large]其次,我们得下载一个sqoop的安全包,散仙在这里使用的是sqoop1,版本是sqoop1.4.4的版本。

最后,我们需要配置一些坏境变量,然后就可以以使用sqoop进行数据迁移了。

[/size][/color][/b]

[b][color=green][size=large]我们先启动hadoop集群,散仙的是伪分布式的截图如下:[/size][/color][/b]

[img]http://dl2.iteye.com/upload/attachment/0092/6449/d2d484f5-ed8e-3d0a-8f60-0025c2991788.jpg\[/img\]

[b][color=green][size=large]接下来,我们需要配置sqoop的环境变量,拷贝sqoop-env-template.sh改名为sqoop-env.sh,需要注意的是在这个配置文件里面,hadoop的环境变量是必须要配置的,否则将会导致连接失败,并出现警告,其他的如Hbase,和Hive的环境变量,则不是必要的,虽然会出现警告信息,但是只要不向它们上面导入数据,就没问题。当然如果我们的应用,需要向Hbase,或Hive里导入数据,那么则需要配置此环境变量,另外一个关于zookeeper的zoo.cfg的配置目录,这个可以不用配置,使用sqoop内置的zookeeper即可,当然如果我们使用的是外置的zookeeper,则可能需要配置一下,散仙的配置文件如下:[/size][/color][/b]

  1. # Licensed to the Apache Software Foundation (ASF) under one or more
  2. # contributor license agreements. See the NOTICE file distributed with
  3. # this work for additional information regarding copyright ownership.
  4. # The ASF licenses this file to You under the Apache License, Version 2.0
  5. # (the "License"); you may not use this file except in compliance with
  6. # the License. You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # included in all the hadoop scripts with source command
  16. # should not be executable directly
  17. # also should not be passed any arguments, since we need original $*
  18. # Set Hadoop-specific environment variables here.
  19. #Set path to where bin/hadoop is available
  20. #hadoop的环境信息必须
  21. export HADOOP_COMMON_HOME=/root/hadoop
  22. #Set path to where hadoop-*-core.jar is available
  23. #hadoop的mr存放目录的配置信息必须
  24. export HADOOP_MAPRED_HOME=/root/hadoop/tmp/mapred
  25. #set the path to where bin/hbase is available
  26. #hbase的配置信息非必须
  27. export HBASE_HOME=/root/hbase
  28. #Set the path to where bin/hive is available
  29. #hive的配置信息非必须
  30. export HIVE_HOME=/root/hive
  31. #Set the path for where zookeper config dir is
  32. #export ZOOCFGDIR=

[b][color=red][size=large]此外,还有一点必须要做的是,拷贝的一份hadoop的核心包到sqoop的lib里面,和以及相对应的数据库的连接包,如果你是oracle,就拷贝一份oracle的JDBC连接包到sqoop的lib,同样如果你是sql server的则一样,散仙在这里使用的是mysql,所以需要拷贝mysql的JDBC包到sqoop的lib里面,截图如下:[/size]
[/color][/b]

[img]http://dl2.iteye.com/upload/attachment/0092/6453/fee99489-cae3-3cb1-9bce-a493c22ac751.jpg\[/img\]
[b][color=olive][size=large]然后,我们就可以输入命令,测试数据库连接了:[/size][/color][/b]

  1. bin/sqoop list-databases --connect jdbc:mysql://192.168.
  2. 120.129 --username root --password root

[b][color=green][size=large]打印的信息如下:[/size][/color][/b]

  1. Warning: /usr/lib/hcatalog does not exist! HCatalog jobs will fail.
  2. Please set $HCAT_HOME to the root of your HCatalog installation.
  3. Warning: $HADOOP_HOME is deprecated.
  4. 13/12/30 06:58:40 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
  5. 13/12/30 06:58:40 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
  6. information_schema
  7. hive
  8. mysql
  9. test

[b][color=green][size=large]
1,将msyql中的数据导入HDFS命令如下
[/size][/color][/b]

  1. bin/sqoop import --connect jdbc:mysql://192.168.120.129/test --table student
  2. //将HDFS上的数据导入到mysql中
  3. bin/sqoop export --connect jdbc:mysql://192.168.120.129/test --username sqoop --password sqoop --table students --export-dir hdfs://masternode:9000/user/grid/students/part-m-00000

[b][color=green][size=large]
2,将msyql中的数据导入Hbase命令如下
[/size][/color][/b]

  1. bin/sqoop import --connect jdbc:mysql://192.168.120.129/test --table student --hbase-table qindongliang --hbase-create-table --hbase-row-key id --column-family dong

[b][color=green][size=large]
3,将msyql中的数据导入Hive命令如下
[/size][/color][/b]

  1. sqoop import --connect jdbc:mysql://192.168.120.129/test --table ST_Statistics --hive-import --create-hive-table
  2. //将Hive中的数据导出到mysql中
  3. bin/sqoop export --connect jdbc:mysql://192.168.120.129/test --username root --password admin --table uv_info --export-dir /user/hive/warehouse/uv/dt=mytable

[b][color=olive][size=large]关于将Hbase的数据导入到mysql里,sqoop并不是直接支持的,一般采用如下3种方法,将Hbase数据,扁平化成HDFS文件,然后再由sqoop导入,第二种,将Hbase数据导入Hive表中,然后再导入mysql,第三种直接使用Hbase的Java API读取表数据,直接向mysql导入,不需要使用sqoop。[/size][/color][/b]

发表评论

表情:
评论列表 (有 0 条评论,275人围观)

还没有评论,来说两句吧...

相关阅读

    相关 sqoop使用

    sqoop作用: 用于将hdfs上的数据导到关系数据库中,或将关系数据库中的数据导入到hdfs上,本文以mysql为例 一、安装 从官网上下载[http://mirrors

    相关 sqoop安装

    sqoop介绍: Sqoop是一个用来将Hadoop和关系型数据库中的数据相互转移的工具,可以将一个关系型数据库(例如 : MySQL ,Oracle ,Postgres等)

    相关 sqoop安装使用

    \[b\]\[color=olive\]\[size=large\]散仙,在上篇文章中,简述了sqoop的的功能,作用,以及版本演进,那么本篇我们就来实战下,看下如下安装使用s

    相关 sqoop安装

    安装sqoop的前提是已经具备java和hadoop的环境 1、下载并解压 最新版下载地址http://ftp.wayne.edu/apache/sqoop/1.4.6/