Hive – Start HiveServer2

HiveServer2 is the second generation of the Hive server, the first being HiveServer1 which has been deprecated and will be removed in future versions of Hive, so let’s start using HiveServer2.

In this Hive article, I will explain what is HiveServer2, how to start, accessing Web UI, benefits using HiveServer2, and finally using the Beeline Command Interface.

Prerequisites: Have Hive installed and setup to run on Hadoop cluster.

HiveServer2 a.k.a HS2 is a second-generation Hive server that enables

  • Remote clients to execute queries against the Hive server.
  • Multi-client concurrency and authentication
  • Better supports for API client like JDBC and ODBC
  • Related Articles

    Start HiverServer2

    Hive distribution comes with hiveserver2 which is located at $HIVE_HOME/bin/ directory, run this command without any arguments to start the HiveServer2.

    				
    					prabha@namenode:~/hive$ $HIVE_HOME/bin/hiveserver2
    				
    			

    In Order to run it as a service run the same command as nohup $HIVE_HOME/bin/hiveserver2 &. This creates a nohup.out file that contains the log.

    You can also start Hive server HS2 (HiveServer2) using hive --service command.

    				
    					prabha@namenode:~/hive$ $HIVE_HOME/bin/hive --service hiveserver2
    (or)
    # Start in nohup mode
    prabha@namenode:~/hive$ nohup $HIVE_HOME/bin/hive --service hiveserver2 & 
    				
    			

    By default HiveServer2 runs on port 10000, If you wanted to change the port, you can do it by changing the value for hive.server2.thrift.port  property on $HIVE_HOME/conf/hive-site.xml file.

    Check if the HiveServer2 service is running and listening on port 10000 using netstat command.

    				
    					prabha@namenode:~/hive$ netstat -anp | grep 10000
    (Not all processes could be identified, non-owned process info
     will not be shown, you would have to be root to see it all.)
    tcp6       0      0 :::10000                :::*                    LISTEN      17820/java
    				
    			

    Since Hive is written in Java, you can also use jps command to check HiveServer2 is running.

    				
    					prabha@namenode:~/hive$ jps
    18025 Jps
    17820 RunJar
    				
    			

    HiveServer2 Web UI

    HiveServer2 also starts a Jetty Http server on port 1002 which provides you with Web UI. This Web User Interface (UI) for HiveServer2 provides configuration, logging, metrics, and active session information. The Web UI is available at port 10002 (127.0.0.1:10002) by default.  

    HiveServer2 Web UI

    Using Beeline CLI

    HiveServer2 supports a command shell Beeline CLI that works with HiveServer2. It’s a JDBC client that is based on the SQLLine CLI. beeline is located at $HIVE_HOME/bin directory. For more information on Beeline check out Starting Beeline in Standalone Embedded and Remote modes.

    				
    					prabha@namenode:~/hive$ bin/beeline -u jdbc:hive2://127.0.0.1:10000 scott tiger
    Beeline version 2.3.7 by Apache Hive
    beeline>
    				
    			

    Hive by default provides user scott and password tiger.

    If you get a connection error User: is not allowed to impersonate, as shown below. set property hive.server2.enable.doAs to false on $HIVE_HOME/conf/hive-site.xml file. and, restart the HiveServer2 and try to run the beeline command again.

    Now, you should see beeline CLI prompt.

    Hope you like this article.

    Happy Learning !

    Take Your Learning To The Next Level.