前言:
在使用Hadoop2.4.0的时候,想用Sqoop导出数据到MySQL中,但是Sqoop-1.4.5会出现版本不兼容的问题,所以需要对其进行重新编译。
看了一下 README.txt文件,需要以下软件包:
* asciidoc
* make
* python 2.5+
* xmlto
* tar
* gzip
下面是在CentOS的安装的:
yum -y install asciidoc
yum -y install make
yum -y install xmlto
yum -y install tar
yum -y install gzip
-- python 自己去安装
如果是Ubuntu系统,请使用apt-get方式安装
Step01:下载sqoop-1.4.5.bin__hadoop-1.0.0.tar.gz
下载地址:http://www.apache.org/dyn/closer.cgi/sqoop/1.4.5
Step02:解压
cd /opt/software
tar -xvf sqoop-1.4.5.tar.gz
解压得到/opt/software/sqoop-1.4.5目录
进入$SQOOP_HOME/下,修改build.xml文件:
. . . . . .
<elseif>
<equals arg1="${hadoopversion}" arg2="200" />
<then>
<property name="hadoop.version" value="2.4.0" />
<property name="hbase.version" value="0.94.2" />
<property name="zookeeper.version" value="3.4.2" />
<property name="hadoop.version.full" value="2.4.0" />
<property name="hcatalog.version" value="0.11.0" />
</then>
</elseif>
修改:/usr/local/sqoop/ src/test/org/apache/sqoop/TestExportUsingProcedure.java文件
vi /usr/local/sqoop/ src/test/org/apache/sqoop/TestExportUsingProcedure.java
在命令模式下输入:set nu 显示行号,大概在244行的位置,修改内容如下:
sql.append(StringUtils.repeat("?", ", ",
修改为如下:
sql.append(StringUtils.repeat("?,",
如果不事先修改的话会报错:
[javac] /usr/share/sqoop-1.4.5.bin__hadoop-2.0.4/src/test/org/apache/sqoop/TestExportUsingProcedure.java:244: error: method repeat in class StringUtils cannot be applied to given types;
[javac] sql.append(StringUtils.repeat("?", ", ",
[javac] ^
[javac] required: String,int
[javac] found: String,String,int
[javac] reason: actual and formal argument lists differ in length
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
[javac] 1 warning
如果你没有修改,报了上上面的错误,那你就需要重新运行ant package了
执行下面的语句:
cd /out/software/sqoop-1.4.5
ant package
就会自动去下载了…… 这个过程非常漫长,需要耐心等待
直到出现BUILD SUCCESSFUL,就编译成功了。
编译成功后,会在/opt/software/sqoop-1.4.5/build目录下生成 sqoop-1.4.5.bin__hadoop-2.4.0的文件夹,这就是我们的安装文件。
将其压缩:
cd /opt/software/sqoop-1.4.5/build
tar -cvf sqoop-1.4.5.bin__hadoop-2.4.0.tar.gz ./sqoop-1.4.5.bin__hadoop-2.4.0
打包好的文件sqoop-1.4.5.bin__hadoop-2.4.0.tar.gz就是我们需要的安装包了。
Step01:解压到安装目录
将sqoop-1.4.5.bin__hadoop-2.4.0.tar.gz解压并cp到/usr/local
tar -xvf sqoop-1.4.5.bin__hadoop-2.4.0.tar.gz
mv sqoop-1.4.5.bin__hadoop-2.4.0 /usr/local
赋予执行权限并重命名
chown -R hadoop:hadoop /usr/local/sqoop-1.4.5.bin__hadoop-2.4.0
mv /usr/local/sqoop-1.4.5.bin__hadoop-2.4.0 /usr/local/sqoop
Step02: 添加环境变量
vi /etc/profile/
增加Sqoop环境变量
#sqoop
export SQOOP_HOME=/usr/local/sqoop
export PATH=${SQOOP_HOME}/bin:$PATH
立即生效
source ~/.bash_profile
Step03:修改配置文件
cd /usr/local/sqoop/conf
cp sqoop-env-template.sh sqoop-env.sh -- 将sqoop-env-template.sh文件复制为sqoop-env.sh
修改sqoop-env.sh
vi sqoop-env.sh
修改如下:
export HADOOP_COMMON_HOME=/usr/local/hadoop
export HADOOP_MAPRED_HOME=/usr/local/hadoop/share/hadoop/mapreduce
export HIVE_HOME=/usr/local/hive
如果没有装Hive的话,可以屏蔽hive的配置
我是用MySQL作为测试数据库的,所以需要上传mysql-connector-java-5.1.30-bin.jar到$SQOOP_HOME/lib下
测试很简单,执行:
sqoop list-databases --connect jdbc:mysql://haoop01:3306/ --username root --password 1234