集羣版本
源集羣: Hadoop-2.7.3、Hive-1.2.1(均爲Apache開源版本)
目標集羣: Hadoop-2.6.0、Hive-1.1.0(均爲CDH-5.15.0版本)
遷移步驟
第一步:Hive export命令導出表到HDFS指定目錄
hive -e "export table test.user_info to '/hive_export/test.user_info';
import和export命令的基本用法可以參考:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ImportExport
默認配置參數情況下,如果表中單個文件大於32M,導出時會報錯:
Failed with exception Cannot get DistCp constructor: org.apache.hadoop.tools.DistCp.<init>()
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.CopyTask
原因:由於export命令相當於拷貝hive表數據到指定目錄,拷貝文件的默認最大值爲hive.exec.
copyfile.maxsize=33554432(32M),超過了這個閾值,會報上述錯誤。解決辦法就是給參數hive.
exec.copyfile.maxsize設置一個適合你表文件大小的值,例如set hive.exec.copyfile.maxsize = 335544320(320M)。
第二步:傳輸數據到目標集羣
hadoop distcp hftp://host:50070/hive_export/test.user_info/* hdfs://nameservice1/hive_import/test.user_info
distcp基本用法可參考:http://hadoop.apache.org/docs/current/hadoop-distcp/DistCp.html
注意: 此命令要在目標集羣的Namenode節點執行
如果你的源集羣和目標集羣版本不一致會報以下錯誤信息:
Caused by: java.io.IOException: Couldn't run retriable-command
Caused by: java.io.IOException: Check-sum mismatch between
解決方法:可以在distcp後面跟上 -Ddfs.checksum.type=CRC32 或 -pb
第三步:Hive import命令將數據導入到Hive表
hive -e "import table test.user_info from '/hive_import/test.user_info';"
可以給表重命名,也可以導出爲外部表。可參考:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ImportExport
第四步:修改hive表存儲路徑
只有在源集羣和目標集羣的NameNode別名不一致時才執行,否則Spark SQL無法訪問Hive表。
hive -e "alter table test.user_info set serdeproperties ('path' = 'hdfs://nameservice1/user/hive/warehouse/test.db/user_info');“