1. sqoop数据迁移
1.1 概述
sqoop是apache旗下一款“Hadoop和关系数据库服务器之间传送数据”的工具。
导入数据:MySQL,Oracle导入数据到Hadoop的HDFS、HIVE、HBASE等数据存储系统;
导出数据:从Hadoop的文件系统中导出数据到关系数据库
1.2 工作机制
将导入或导出命令翻译成mapreduce程序来实现
在翻译出的mapreduce中主要是对inputformat和outputformat进行定制
1.3 sqoop实战及原理
1.3.1 sqoop安装
安装sqoop的前提是已经具备java和hadoop的环境
1、下载并解压
最新版下载地址http://ftp.wayne.edu/apache/sqoop/1.4.6/
比如:sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz
[root@hadoop1 sqoop]# tar -zxvf sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz
[root@hadoop1 sqoop]# mv sqoop-1.4.6.bin__hadoop-2.0.4-alpha sqoop
[root@hadoop1 sqoop]# ls
apache-hive-1.2.1-bin hadoop-2.7.4 hdfs pig-0.17.0 pig_1517170893185.log sqoop tmp
2、修改配置文件
在/etc/profile中配置sqoop_home,代码如下:
vim /etc/profile
export SQOOP_HOME=/usr/local/hadoop/sqoop
追加path
export PATH=$PATH:$SQOOP_HOME/bin
[root@hadoop1 sqoop]# source /etc/profile
$ cd $SQOOP_HOME/conf
$ mv sqoop-env-template.sh sqoop-env.sh
打开sqoop-env.sh并编辑下面几行: ## 去掉前面的##
export HADOOP_COMMON_HOME=/usr/local/hadoop/hadoop-2.7.4/
export HADOOP_MAPRED_HOME=/usr/local/hadoop/hadoop-2.7.4/
export HIVE_HOME=/usr/local/hadoop/apache-hive-1.2.1-bin/
配置后的界面效果如下:
这里写图片描述
3.1 加入oracle的驱动包
将 ojdbc6.jar 放到 $SQOOP_HOME/lib/ 下。
3.2 加入mysql的jdbc驱动包
将mysql-connector-java-5.1.38.jar 放到 $SQOOP_HOME/lib/ 下。
4、验证启动
$ cd $SQOOP_HOME/bin
$ sqoop-version
预期的输出:
[root@hadoop1 sqoop]# sqoop-version
Warning: /usr/local/hadoop/sqoop/../hbase does not exist! HBase imports will fail.
Please set $HBASE_HOME to the root of your HBase installation.
Warning: /usr/local/hadoop/sqoop/../hcatalog does not exist! HCatalog jobs will fail.
Please set $HCAT_HOME to the root of your HCatalog installation.
Warning: /usr/local/hadoop/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
Warning: /usr/local/hadoop/sqoop/../zookeeper does not exist! Accumulo imports will fail.
Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.
18/01/29 19:09:34 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6
Sqoop 1.4.6
git commit id c0c5a81723759fa575844a0a1eae8f510fa32c25
Compiled by root on Mon Apr 27 14:38:36 CST 2015
[root@hadoop1 sqoop]#
到这里,整个Sqoop安装工作完成。