Centos7安裝Sqoop(CentOS7+Sqoop1.4.6+Hadoop2.8.0+Hive2.1.1)


  注意:本文只講Sqoop1.4.6的安裝。和hive一樣,sqoop只需要在hadoop的namenode上安裝即可。本例安裝sqoop的機器上已經安裝了hdoop2.8.0和hive2.1.1,hadoop2.8.0的安裝請參考博文:

       http://blog.csdn.net/pucao_cug/article/details/71698903

hive2.1.1的安裝請參考博文:

      http://blog.csdn.net/pucao_cug/article/details/71773665

 

1下載Sqoop

         因為官方並不建議在生產環境中使用1.99.7版本,所以我們還是等2.0版本出來在用新的吧,現在依然使用1.4.6版本

打開官網:

http://sqoop.apache.org/

 

      如圖:

 

 

 

點擊上圖的nearby  mirror

相當於是直接打開:http://www.apache.org/dyn/closer.lua/sqoop/

如圖:

   

 

 

  我選擇的是http://apache.communilink.net/sqoop/

  如圖:

    

 

點擊1.4.7,相當於是直接打開地址:

http://apache.communilink.net/sqoop/1.4.7/

如圖:

 

    

 

2上載和解壓縮

   

            在opt目錄下新建一個名為sqoop的目錄,將下載得到的文件

sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz

上載到該目錄內

   如圖:

     

 

  進入到該目錄下,執行解壓縮,也就是執行命令:

  cd    /opt/sqoop

  tar   -xvf    sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz

  命令執行完成后得到了/opt/sqoop/sqoop-1.4.7.bin__hadoop-2.6.0目錄

3一系列配置

3.1 配置環境變量

         編輯/etc/profile文件,添加SQOOP_HOME變量,並且將$SQOOP_HOME/bin添加到PATH變量中,編輯方法很多,可以將profile文件下載到本地編輯,也可以直接用vim命令編輯。

 

    添加的內容如下:

 

export  JAVA_HOME=/opt/java/jdk1.8.0_121

export  HADOOP_HOME=/opt/hadoop/hadoop-2.8.0

export  HADOOP_CONF_DIR=${HADOOP_HOME}/etc/hadoop

export  HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_HOME}/lib/native

export  HADOOP_OPTS="-Djava.library.path=${HADOOP_HOME}/lib"

export  HIVE_HOME=/opt/hive/apache-hive-2.1.1-bin

export  HIVE_CONF_DIR=${HIVE_HOME}/conf

export  SQOOP_HOME=/opt/sqoop/sqoop-1.4.7.bin__hadoop-2.6.0

export  CLASS_PATH=.:${JAVA_HOME}/lib:${HIVE_HOME}/lib:$CLASS_PATH

export  PATH=.:${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin: ${HIVE_HOME}/bin:${SQOOP_HOME}/bin:$PATH

 

 /etc/profile文件編輯完成后,執行命令:

   source    /etc/profile

3.2   Sqoop配置文件修改

3.2.1  sqoop-env.sh文件

3.2.1.1 新建

       進入到/opt/sqoop/sqoop-1.4.7.bin__hadoop-2.6.0/conf目錄下,也就是執行命令:

cd     /opt/sqoop//sqoop-1.4.7.bin__hadoop-2.6.0/conf

      將sqoop-env-template.sh復制一份,並取名為sqoop-env.sh,也就是執行命令:

cp    sqoop-env-template.sh  sqoop-env.sh

  如圖:

     

 

3.2.1.2 編輯內容

      編輯這個新建的sqoop-env.sh文件,編輯方法有很多,可以下載到本地編輯,也可是使用vim命令編輯。

       在該文件末尾加入下面的配置:

export  HADOOP_COMMON_HOME=/opt/hadoop/hadoop-2.8.0

export  HADOOP_MAPRED_HOME=/opt/hadoop/hadoop-2.8.0

export  HIVE_HOME=/opt/hive/apache-hive-2.1.1-bin

 

       說明:上面的路徑修改為自己的hadoop路徑和hive路徑。

3.3 將MySQL驅動包上載到Sqoop的lib下

         將MySQL的驅動包上載到Sqoop安裝目錄的lib子目錄下

如圖:

     

 

 

           說明:該驅動不是越舊越好,也不是越新越好,5.1.31我這里測試是可以的。

 

4  使用sqoop

       sqoop是一個工具,安裝完成后,如果操作的命令不涉及hive和hadoop的,可以實現不啟動hive和hadoop,直接輸入sqoop命令即可,例如sqoop help命令。要使用hive相關的命令,必須事先啟動hive和hadoop。

hadoop的安裝和啟動可以參考該博文:

           http://blog.csdn.net/pucao_cug/article/details/71698903

hive的安裝和啟動可以參考該博文:

          http://blog.csdn.net/pucao_cug/article/details/71773665

4.1  使用help命令

         首先看看sqoop都有哪些命令,在終上輸入命令:

sqoop  help

如圖:

   

 

 

 

上圖中的內容是:

 


 
  1. [root@hserver1 ~]# sqoop  help  
  2. Warning:/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../hbase does not exist! HBaseimports will fail.  
  3. Please set $HBASE_HOME to the root of yourHBase installation.  
  4. Warning:/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../hcatalog does not exist! HCatalogjobs will fail.  
  5. Please set $HCAT_HOME to the root of yourHCatalog installation.  
  6. Warning:/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../accumulo does not exist!Accumulo imports will fail.  
  7. Please set $ACCUMULO_HOME to the root ofyour Accumulo installation.  
  8. Warning:/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../zookeeper does not exist!Accumulo imports will fail.  
  9. Please set $ZOOKEEPER_HOME to the root ofyour Zookeeper installation.  
  10. 17/05/14 16:21:30 INFO sqoop.Sqoop: RunningSqoop version: 1.4.6  
  11. usage: sqoop COMMAND [ARGS]  
  12.    
  13. Available commands:  
  14.  codegen            Generate codeto interact with database records  
  15.  create-hive-table  Import a tabledefinition into Hive  
  16.  eval               Evaluate a SQLstatement and display the results  
  17.   export             Export an HDFS directory to adatabase table  
  18.  help               List availablecommands  
  19.  import             Import a tablefrom a database to HDFS  
  20.  import-all-tables  Import tablesfrom a database to HDFS  
  21.  import-mainframe   Import datasetsfrom a mainframe server to HDFS  
  22.  job                Work with savedjobs  
  23.  list-databases     List availabledatabases on a server  
  24.  list-tables        List availabletables in a database  
  25.  merge              Merge resultsof incremental imports  
  26.  metastore          Run astandalone Sqoop metastore  
  27.  version            Display versioninformation  
  28.    
  29. See 'sqoop help COMMAND' for information ona specific command.  
  30. [root@hserver1 ~]#  

 

 

      說明:因為我們沒有基於hadoop安裝HBase,所以HBase相關的命令不能用,但是操作hadoop分布式文件系統的命令是可以用的。

4.2  使用Sqoop查看MySQL中的數據表

          下面是使用命令查看MySQL數據庫中的數據表list,命令是(命令中不能有回車,必須是在同一行,復制粘貼時候請注意):

       


 
  1. sqoop   list-tables  --username  root   --password  'cj'     --connect     jdbc:mysql://192.168.27.132:3306/hello?characterEncoding=UTF-8  

 

 

如圖:

 

      

4.3  基於MySQL的表創建hive表

4.3.1  創建

       注意:hive是基於hadoop的HDFS的,在運行下面的導入命令請,請確保hadoop和hive都在正常運行。

       現在MySQL數據庫服務器上有一個數據庫名為 hello,下面有一張表名為people

如圖:

       

 

 

       執行命令,在已經存在的db_hive_deu這個庫中創建名為place的表:


 

 
  1. sqoop              create-hive-table    --connect    jdbc:mysql://192.168.119.132:3306/hello?characterEncoding=UTF-8    --table  people     --username   root   -password 'cj'     --hive-database  db_hive_edu  

 

 

如圖:

 

    

 

上圖中的內容是:

 

[plain]  view plain  copy
 
  1. [root@hserver1 ~]# sqoop  create-hive-table   --connect jdbc:mysql://192.168.119.132:3306/hello?characterEncoding=UTF-8  --table people    --username  root -password 'cj'   --hive-database  db_hive_edu  
  2. Warning: /opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../hbasedoes not exist! HBase imports will fail.  
  3. Please set $HBASE_HOME to the root of your HBase installation.  
  4. Warning: /opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../hcatalogdoes not exist! HCatalog jobs will fail.  
  5. Please set $HCAT_HOME to the root of your HCatalog installation.  
  6. Warning: /opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../accumulodoes not exist! Accumulo imports will fail.  
  7. Please set $ACCUMULO_HOME to the root of your Accumulo installation.  
  8. Warning: /opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../zookeeperdoes not exist! Accumulo imports will fail.  
  9. Please set $ZOOKEEPER_HOME to the root of your Zookeeperinstallation.  
  10. 17/05/14 21:06:06 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6  
  11. 17/05/14 21:06:06 WARN tool.BaseSqoopTool: Setting your password onthe command-line is insecure. Consider using -P instead.  
  12. 17/05/14 21:06:06 INFO tool.BaseSqoopTool: Using Hive-specificdelimiters for output. You can override  
  13. 17/05/14 21:06:06 INFO tool.BaseSqoopTool: delimiters with--fields-terminated-by, etc.  
  14. 17/05/14 21:06:07 INFO manager.MySQLManager: Preparing to use aMySQL streaming resultset.  
  15. 17/05/14 21:06:09 INFO manager.SqlManager: Executing SQL statement:SELECT t.* FROM `people` AS t LIMIT 1  
  16. 17/05/14 21:06:09 INFO manager.SqlManager: Executing SQL statement:SELECT t.* FROM `people` AS t LIMIT 1  
  17. 17/05/14 21:06:11 WARN util.NativeCodeLoader: Unable to loadnative-hadoop library for your platform... using builtin-java classes whereapplicable  
  18. 17/05/14 21:06:16 INFO hive.HiveImport: Loading uploaded data intoHive  
  19. 17/05/14 21:06:26 INFO hive.HiveImport: which: no hbase in (.:/opt/java/jdk1.8.0_121/bin:/opt/hadoop/hadoop-2.8.0/bin:/opt/hadoop/hadoop-2.8.0/sbin:/opt/hive/apache-hive-2.1.1-bin/bin:/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)  
  20. 17/05/14 21:06:29 INFO hive.HiveImport: SLF4J: Class path containsmultiple SLF4J bindings.  
  21. 17/05/14 21:06:29 INFO hive.HiveImport: SLF4J: Found binding in[jar:file:/opt/hive/apache-hive-2.1.1-bin/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]  
  22. 17/05/14 21:06:29 INFO hive.HiveImport: SLF4J: Found binding in[jar:file:/opt/hadoop/hadoop-2.8.0/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]  
  23. 17/05/14 21:06:29 INFO hive.HiveImport: SLF4J: Seehttp://www.slf4j.org/codes.html#multiple_bindings for an explanation.  
  24. 17/05/14 21:06:58 INFO hive.HiveImport:  
  25. 17/05/14 21:06:58 INFO hive.HiveImport: Logging initialized usingconfiguration injar:file:/opt/hive/apache-hive-2.1.1-bin/lib/hive-common-2.1.1.jar!/hive-log4j2.propertiesAsync: true  
  26. 17/05/14 21:07:32 INFO hive.HiveImport: OK  
  27. 17/05/14 21:07:32 INFO hive.HiveImport: Time taken: 6.657 seconds  
  28. 17/05/14 21:07:32 INFO hive.HiveImport: Hive import complete.  
  29. [root@hserver1 ~]#  

 

     注意:create-hive-table只是創建hive表,並沒有導入數據,導入數據的命令在4.4中講到。

 

4.3.2  測試

        在hive命令模式下,輸入以下命令,切換到db_hive_edu數據庫中,命令是:

use  db_hive_edu;

      如圖:

    

 

 

      在hive命令模式下,輸入以下命令:

show  tables;

       如圖:

   

 

 

4.4  將MySQL中的數據導入到hive中

4.4.1  執行導入命令

         注意:hive是基於hadoop的HDFS的,在運行下面的導入命令請,請確保hadoop和hive都在正常運行。需要額外說明的是,下面的命令不需要以4.3為前提,也就是說直接執行下面的命令即可,不需要事先在hive上創建對應的表。

 

       執行下面的命令(下面的命令在同一行內):

 


 
  1. sqoop    import     --connect     jdbc:mysql://192.168.119.132:3306/hello?characterEncoding=UTF-8        --table    place    --username   root  -password  'cj'    --fields-terminated-by   ','    --hive-import      --hive-database  db_hive_edu     -m  1  


   

 

如圖:

 

     

         上圖中的內容是(完整的):

 


 
  1. [root@hserver1~]# sqoop import --connect jdbc:mysql://192.168.119.132:3306/hello?characterEncoding=UTF-8  --table place    --username root  -password 'cj'  --fields-terminated-by   ',' --hive-import   --hive-databasedb_hive_edu   -m 1  
  2. Warning: /opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../hbasedoes not exist! HBase imports will fail.  
  3. Please set $HBASE_HOME to the root of yourHBase installation.  
  4. Warning:/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../hcatalog does not exist!HCatalog jobs will fail.  
  5. Please set $HCAT_HOME to the root of yourHCatalog installation.  
  6. Warning:/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../accumulo does not exist!Accumulo imports will fail.  
  7. Please set $ACCUMULO_HOME to the root ofyour Accumulo installation.  
  8. Warning: /opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../zookeeperdoes not exist! Accumulo imports will fail.  
  9. Please set $ZOOKEEPER_HOME to the root ofyour Zookeeper installation.  
  10. 17/05/14 20:44:07 INFO sqoop.Sqoop: RunningSqoop version: 1.4.6  
  11. 17/05/14 20:44:08 WARN tool.BaseSqoopTool:Setting your password on the command-line is insecure. Consider using -Pinstead.  
  12. 17/05/14 20:44:08 INFOmanager.MySQLManager: Preparing to use a MySQL streaming resultset.  
  13. 17/05/14 20:44:08 INFO tool.CodeGenTool:Beginning code generation  
  14. 17/05/14 20:44:10 INFO manager.SqlManager:Executing SQL statement: SELECT t.* FROM `place` AS t LIMIT 1  
  15. 17/05/14 20:44:10 INFO manager.SqlManager:Executing SQL statement: SELECT t.* FROM `place` AS t LIMIT 1  
  16. 17/05/14 20:44:10 INFOorm.CompilationManager: HADOOP_MAPRED_HOME is /opt/hadoop/hadoop-2.8.0  
  17. Note:/tmp/sqoop-root/compile/382b047cc7e935d9ba3014747288b5f7/place.java uses oroverrides a deprecated API.  
  18. Note: Recompile with -Xlint:deprecation fordetails.  
  19. 17/05/14 20:44:18 INFOorm.CompilationManager: Writing jar file:/tmp/sqoop-root/compile/382b047cc7e935d9ba3014747288b5f7/place.jar  
  20. 17/05/14 20:44:18 WARNmanager.MySQLManager: It looks like you are importing from mysql.  
  21. 17/05/14 20:44:18 WARNmanager.MySQLManager: This transfer can be faster! Use the --direct  
  22. 17/05/14 20:44:18 WARNmanager.MySQLManager: option to exercise a MySQL-specific fast path.  
  23. 17/05/14 20:44:18 INFOmanager.MySQLManager: Setting zero DATETIME behavior to convertToNull (mysql)  
  24. 17/05/14 20:44:18 INFOmapreduce.ImportJobBase: Beginning import of place  
  25. 17/05/14 20:44:18 INFOConfiguration.deprecation: mapred.job.tracker is deprecated. Instead, usemapreduce.jobtracker.address  
  26. 17/05/14 20:44:20 WARNutil.NativeCodeLoader: Unable to load native-hadoop library for yourplatform... using builtin-java classes where applicable  
  27. 17/05/14 20:44:20 INFOConfiguration.deprecation: mapred.jar is deprecated. Instead, usemapreduce.job.jar  
  28. 17/05/14 20:44:24 INFOConfiguration.deprecation: mapred.map.tasks is deprecated. Instead, usemapreduce.job.maps  
  29. 17/05/14 20:44:25 INFO client.RMProxy:Connecting to ResourceManager at hserver1/192.168.119.128:8032  
  30. 17/05/14 20:44:41 INFO db.DBInputFormat:Using read commited transaction isolation  
  31. 17/05/14 20:44:42 INFOmapreduce.JobSubmitter: number of splits:1  
  32. 17/05/14 20:44:43 INFOmapreduce.JobSubmitter: Submitting tokens for job: job_1494764774368_0001  
  33. 17/05/14 20:44:49 INFO impl.YarnClientImpl:Submitted application application_1494764774368_0001  
  34. 17/05/14 20:44:49 INFO mapreduce.Job: Theurl to track the job:http://hserver1:8088/proxy/application_1494764774368_0001/  
  35. 17/05/14 20:44:49 INFO mapreduce.Job:Running job: job_1494764774368_0001  
  36. 17/05/14 20:45:40 INFO mapreduce.Job: Jobjob_1494764774368_0001 running in uber mode : false  
  37. 17/05/14 20:45:40 INFO mapreduce.Job:  map 0% reduce 0%  
  38. 17/05/14 20:46:21 INFO mapreduce.Job:  map 100% reduce 0%  
  39. 17/05/14 20:46:25 INFO mapreduce.Job: Jobjob_1494764774368_0001 completed successfully  
  40. 17/05/14 20:46:25 INFO mapreduce.Job:Counters: 30  
  41.        File System Counters  
  42.                 FILE: Number of bytes read=0  
  43.                 FILE: Number of byteswritten=154570  
  44.                 FILE: Number of readoperations=0  
  45.                 FILE: Number of large readoperations=0  
  46.                 FILE: Number of writeoperations=0  
  47.                 HDFS: Number of bytes read=87  
  48.                 HDFS: Number of byteswritten=10  
  49.                 HDFS: Number of readoperations=4  
  50.                 HDFS: Number of large readoperations=0  
  51.                 HDFS: Number of writeoperations=2  
  52.        Job Counters  
  53.                 Launched map tasks=1  
  54.                 Other local map tasks=1  
  55.                 Total time spent by all maps inoccupied slots (ms)=34902  
  56.                 Total time spent by all reducesin occupied slots (ms)=0  
  57.                Total time spent by all maptasks (ms)=34902  
  58.                 Total vcore-milliseconds takenby all map tasks=34902  
  59.                 Total megabyte-millisecondstaken by all map tasks=35739648  
  60.        Map-Reduce Framework  
  61.                 Map input records=2  
  62.                 Map output records=2  
  63.                 Input split bytes=87  
  64.                 Spilled Records=0  
  65.                 Failed Shuffles=0  
  66.                 Merged Map outputs=0  
  67.                 GC time elapsed (ms)=190  
  68.                 CPU time spent (ms)=2490  
  69.                 Physical memory (bytes)snapshot=102395904  
  70.                 Virtual memory (bytes)snapshot=2082492416  
  71.                 Total committed heap usage(bytes)=16318464  
  72.        File Input Format Counters  
  73.                 Bytes Read=0  
  74.         File Output Format Counters  
  75.                 Bytes Written=10  
  76. 17/05/14 20:46:25 INFOmapreduce.ImportJobBase: Transferred 10 bytes in 121.3811 seconds (0.0824bytes/sec)  
  77. 17/05/14 20:46:25 INFOmapreduce.ImportJobBase: Retrieved 2 records.  
  78. 17/05/14 20:46:26 INFO manager.SqlManager:Executing SQL statement: SELECT t.* FROM `place` AS t LIMIT 1  
  79. 17/05/14 20:46:26 INFO hive.HiveImport:Loading uploaded data into Hive  
  80. 17/05/14 20:48:25 INFO hive.HiveImport:which: no hbase in(.:/opt/java/jdk1.8.0_121/bin:/opt/hadoop/hadoop-2.8.0/bin:/opt/hadoop/hadoop-2.8.0/sbin:/opt/hive/apache-hive-2.1.1-bin/bin:/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)  
  81. 17/05/14 20:48:28 INFO hive.HiveImport:SLF4J: Class path contains multiple SLF4J bindings.  
  82. 17/05/14 20:48:28 INFO hive.HiveImport:SLF4J: Found binding in[jar:file:/opt/hive/apache-hive-2.1.1-bin/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]  
  83. 17/05/14 20:48:28 INFO hive.HiveImport:SLF4J: Found binding in[jar:file:/opt/hadoop/hadoop-2.8.0/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]  
  84. 17/05/14 20:48:28 INFO hive.HiveImport:SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for anexplanation.  
  85. 17/05/14 20:49:48 INFO hive.HiveImport:  
  86. 17/05/14 20:49:48 INFO hive.HiveImport:Logging initialized using configuration injar:file:/opt/hive/apache-hive-2.1.1-bin/lib/hive-common-2.1.1.jar!/hive-log4j2.propertiesAsync: true  
  87. 17/05/14 20:50:16 INFO hive.HiveImport: OK  
  88. 17/05/14 20:50:16 INFO hive.HiveImport:Time taken: 3.735 seconds  
  89. 17/05/14 20:50:18 INFO hive.HiveImport:Loading data to table db_hive_edu.place  
  90. 17/05/14 20:50:20 INFO hive.HiveImport: OK  
  91. 17/05/14 20:50:20 INFO hive.HiveImport:Time taken: 4.872 seconds  
  92. 17/05/14 20:50:21 INFO hive.HiveImport:Hive import complete.  
  93. 17/05/14 20:50:21 INFO hive.HiveImport:Export directory is contains the _SUCCESS file only, removing the directory.  
  94. [root@hserver1 ~]#  

 

 

 

4.4.2  執行hive命令測試上面的操作是否成功

          切換到剛才hive命令行(為了方便,我一般都是開了個連接,一個是普通的Linux命令模式,一個是啟動hive,用於執行hive命令)。

          在hive命令模式下,輸入以下命令,切換到db_hive_edu數據庫中,命令是:

use   db_hive_edu;

      如圖:

   

     在hive命令模式下,輸入以下命令:

show  tables;

如圖:

    

 

 

      在hive命令模式下,輸入以下命令查看people表里的數據:

select  * from   place;

    如圖:

    

 

5  報錯和解決

5.1   java.net.NoRouteToHostException: No route to host (Host unreachable)

        檢查你命令中的IP地址是否寫錯了,檢查命令中的--connect后面的IP地址,出現這個錯誤,往往是這個地方寫錯了。

5.2 ERROR tool.ImportTool: Error during import: Import job failed!

         在執行sqoop  import從MySql導出數據到hive時候報錯,完整報錯是:

java.lang.Exception:java.lang.RuntimeException: java.lang.ClassNotFoundException: Class place notfound

        atorg.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:489)

        atorg.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:549)

Caused by:java.lang.RuntimeException: java.lang.ClassNotFoundException: Class place notfound

        atorg.apache.hadoop.conf.Configuration.getClass(Configuration.java:2216)

        at org.apache.sqoop.mapreduce.db.DBConfiguration.getInputClass(DBConfiguration.java:403)

        atorg.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.createDBRecordReader(DataDrivenDBInputFormat.java:237)

        atorg.apache.sqoop.mapreduce.db.DBInputFormat.createRecordReader(DBInputFormat.java:263)

        atorg.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.<init>(MapTask.java:515)

        atorg.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:758)

        atorg.apache.hadoop.mapred.MapTask.run(MapTask.java:341)

        atorg.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:270)

        atjava.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

        atjava.util.concurrent.FutureTask.run(FutureTask.java:266)

        atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

        atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

        atjava.lang.Thread.run(Thread.java:745)

Caused by: java.lang.ClassNotFoundException:Class place not found

        atorg.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2122)

        atorg.apache.hadoop.conf.Configuration.getClass(Configuration.java:2214)

        ... 12 more

17/05/14 22:17:45 INFO mapreduce.Job:Job job_local612327026_0001 failed with state FAILED due to: NA

17/05/14 22:17:45 INFOmapreduce.Job: Counters: 0

17/05/14 22:17:46 WARNmapreduce.Counters: Group FileSystemCounters is deprecated. Useorg.apache.hadoop.mapreduce.FileSystemCounter instead

17/05/14 22:17:46 INFOmapreduce.ImportJobBase: Transferred 0 bytes in 19.1156 seconds (0 bytes/sec)

17/05/14 22:17:46 WARNmapreduce.Counters: Group org.apache.hadoop.mapred.Task$Counter is deprecated.Use org.apache.hadoop.mapreduce.TaskCounter instead

17/05/14 22:17:46 INFOmapreduce.ImportJobBase: Retrieved 0 records.

17/05/14 22:17:46 ERRORtool.ImportTool: Error during import: Import job failed!

 

原因:

      和hadoop的配置和有關系,需要啟用yar這個mapreduce框架。

解決方法:

      我的hadoop安裝路徑是/opt/hadoop/hadoop-2.8.0/。

      找到/opt/hadoop/hadoop-2.8.0/etc/hadoop/mapred-site.xml配置文件,加入配置:

<property>

 <name>mapreduce.framework.name</name>

       <value>yarn</value>

</property>

如圖:

     

 

 

    

    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM