Rate This Document
Findability
Accuracy
Completeness
Readability

Starting and Verifying Hive

  1. Prepare for starting Hive.
    1. Download JDBC.
      Download the JDBC driver and save it to the /usr/local/hive/lib directory. In this example, mysql-connector-java.jar is used.
      tar -zxf mysql-connector-java-5.1.49.tar.gz
      mv mysql-connector-java-5.1.49.jar /usr/local/hive/lib/
    2. Create a directory in which the Hive data is stored.
      1
      2
      3
      4
      hdfs dfs -mkdir /tmp
      hdfs dfs -mkdir -p /user/hive/warehouse
      hdfs dfs -chmod g+w /tmp
      hdfs dfs -chmod g+w /user/hive/warehouse
      
    3. Create a Hive log directory.
      1
      2
      3
      mkdir -p /usr/local/hive/log/
      touch /usr/local/hive/log/hiveserver2.log
      touch /usr/local/hive/log/hiveserver2.err
      
  2. Initialize Hive.
    1
    schematool -dbType mysql -initSchema
    
  3. Start Hive Metastore.
    1
    nohup hive --service metastore -p 9083 &
    
  4. Start HiveServer2.
    1. Start it.
      1
      nohup hiveserver2 1>/usr/local/hive/log/hiveserver2.log 2>/usr/local/hive/log/hiveserver2.err &
      
    2. View the progress.
      1
      tail -f /usr/local/hive/log/hiveserver2.err
      
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      nohup: ignoring input
       which: no hbase in (/usr/local/hadoop/bin:/usr/local/hadoop/sbin:/usr/local/hive/bin:/usr/local/zookeeper/bin:/usr/local/jdk8u222-b10/bin:/usr/local/python3/bin:/usr/local/hadoop/bin:/usr/local/hadoop/sbin:/usr/local/hive/bin:/usr/local/zookeeper/bin:/usr/local/jdk8u222-b10/bin:/usr/local/python3/bin:/usr/local/hadoop/bin:/usr/local/hadoop/sbin:/usr/local/zookeeper/bin:/usr/local/jdk8u222-b10/bin:/usr/local/python3/bin:/usr/local/jdk8u222-b10/bin:/usr/local/python3/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
       2021-01-18 11:32:22: Starting HiveServer2
       SLF4J: Class path contains multiple SLF4J bindings.
       SLF4J: Found binding in [jar:file:/usr/local/apache-hive-3.1.0-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
       SLF4J: Found binding in [jar:file:/usr/local/hadoop-3.1.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
       SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
       SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
       Hive Session ID = 824030a3-2afe-488c-a2fa-7d98cfc8f7bd
       Hive Session ID = 1031e326-2088-4025-b2e2-c9bb1e81b03d
       Hive Session ID = 32203873-49ad-44b7-987c-da1aae8b3375
       Hive Session ID = d7be9389-11c6-46cb-90d6-a91a2d5199b8
       OK
      
    3. Query the port. The default port number of HiveServer2 is 10000.
      1
      netstat -anp|grep 10000
      

      If the following information is displayed, the startup is successful:

      1
      tcp6 0 0 :::10000 :::* LISTEN 27800/java
      
    4. Use beeline to connect to server1.
      1
      beeline -u jdbc:hive2://server1:10000 -n root
      

      The command output is as follows:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      SLF4J: Class path contains multiple SLF4J bindings.
       SLF4J: Found binding in [jar:file:/usr/local/apache-hive-3.1.0-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
       SLF4J: Found binding in [jar:file:/usr/local/hadoop-3.1.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
       SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
       SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
       Connecting to jdbc:hive2://server1:10000
       Connected to: Apache Hive (version 3.1.0)
       Driver: Hive JDBC (version 3.1.0)
       Transaction isolation: TRANSACTION_REPEATABLE_READ
       Beeline version 3.1.0 by Apache Hive
      0: jdbc:hive2://server1:10000>
      
  5. Check the created database.
    1
    show databases;
    

    If the following information is displayed, Hive is successfully started:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    0: jdbc:hive2://server1:10000> show databases;
     INFO : Compiling command(queryId=root_20210118113531_49c3505a-80e1-4aba-9761-c2f77a06ac5f): show databases
     INFO : Concurrency mode is disabled, not creating a lock manager
     INFO : Semantic Analysis Completed (retrial = false)
     INFO : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:database_name, type:string, comment:from deserializer)], properties:null)
     INFO : Completed compiling command(queryId=root_20210118113531_49c3505a-80e1-4aba-9761-c2f77a06ac5f); Time taken: 0.903 seconds
     INFO : Concurrency mode is disabled, not creating a lock manager
     INFO : Executing command(queryId=root_20210118113531_49c3505a-80e1-4aba-9761-c2f77a06ac5f): show databases
     INFO : Starting task [Stage-0:DDL] in serial mode
     INFO : Completed executing command(queryId=root_20210118113531_49c3505a-80e1-4aba-9761-c2f77a06ac5f); Time taken: 0.029 seconds
     INFO : OK
     INFO : Concurrency mode is disabled, not creating a lock manager
     +----------------+
     | database_name |
     +----------------+
     | default |
     +----------------+
     1 row selected (1.248 seconds)
    
  6. Verify the Tez function.
    1. Use the Tez engine.
      1
      set hive.execution.engine=tez;
      
    2. Create a student table.
      1
      create table student(id int, name string);
      
    3. Insert data to the table.
      1
      2
      insert into student values(1,"zhangsan");
      insert into student values(2,"lisi");
      
    4. Query the student table. If the query result is correct, the installation is successful. See the following figure.
      1
      select * from student;
      

  7. Quit Hive.
    1
    !quit
    
    • Run the beeline -u jdbc:hive2://agent1:10000 -n root command to access Hive, and type !quit to exit.
    • Run the hive command to access Hive, and type quit; to exit.