Skip to content

Instantly share code, notes, and snippets.

@rajkrrsingh
Last active July 24, 2019 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajkrrsingh/626a4e57af9422abd75a7b48c1118d6d to your computer and use it in GitHub Desktop.
Save rajkrrsingh/626a4e57af9422abd75a7b48c1118d6d to your computer and use it in GitHub Desktop.
Running HiveServer2 and Beeline as docker containers

Create and run hiveserver2 docker container

mkdir hive-3-image
cd hive-3-image/
wget https://raw.githubusercontent.com/alanfgates/sqltest/master/dbs/hive/v3_1/Dockerfile
docker build . -t hive3-image
// Run it
docker run -it --net=myNetwork -p 10000:10000 hive3-image

You will see following logs on stdout if everything goes well

which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/grid/hadoop-3.1.1/bin:/grid/apache-hive-3.1.1-bin/bin)
2019-07-24 22:22:18: Starting HiveServer2
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/grid/apache-hive-3.1.1-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/grid/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 = 7ac431e6-9619-4cfc-a98d-00cb3cd6e9dc
Hive Session ID = cb5986e4-38dd-401c-aea6-d7f1032790ad
Hive Session ID = 525af947-9fc4-4445-a7c3-227ae861f513
Hive Session ID = ee73bf5e-4baa-420e-b409-55dabf67cf61

Now create and run beeline container

 mkdir beeline-docker
 wget https://raw.githubusercontent.com/alanfgates/sqltest/master/dbs/hive/v3_1/Dockerfile

I know this is a very naive approach but lets stick to it, get the hostname of hiveserver2 docker container using (by default container id is default hostname)

 docker ps -a | grep hive3-image
 CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS                            PORTS                      NAMES
0749ae15ece8        hive3-image                "hive --service hive…"   2 minutes ago       Up 2 minutes                      0.0.0.0:10000->10000/tcp   jovial_swartz

// get hostname 
docker inspect 0749ae15ece8 | grep -i host
"HostnamePath": "/var/lib/docker/containers/0749ae15ece81ae9e429d19f28c9f0bed52f7837f6984f9619aab6618f97a5f4/hostname",
       "HostsPath": "/var/lib/docker/containers/0749ae15ece81ae9e429d19f28c9f0bed52f7837f6984f9619aab6618f97a5f4/hosts",
       "HostConfig": {
                       "HostIp": "",
                       "HostPort": "10000"
           "ExtraHosts": null,
           "Hostname": "0749ae15ece8",
                       "HostIp": "0.0.0.0",
                       "HostPort": "10000"

Modify the CMD in Dockerfile

CMD ["beeline","-u","jdbc:hive2://0749ae15ece8:10000"]

Build docker beeline image for this definition

docker build . -t beeline_docker

Run it

docker run -it --net=myNetwork beeline_docker

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/grid/apache-hive-3.1.1-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/grid/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://0749ae15ece8:10000
Connected to: Apache Hive (version 3.1.1)
Driver: Hive JDBC (version 3.1.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 3.1.1 by Apache Hive
0: jdbc:hive2://0749ae15ece8:10000> show tables;
INFO  : Compiling command(queryId=hive_20190724222711_18df4f09-d690-4774-af47-abe0c63bf8b2): show tables
INFO  : Concurrency mode is disabled, not creating a lock manager
INFO  : Semantic Analysis Completed (retrial = false)
INFO  : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:tab_name, type:string, comment:from deserializer)], properties:null)
INFO  : Completed compiling command(queryId=hive_20190724222711_18df4f09-d690-4774-af47-abe0c63bf8b2); Time taken: 1.391 seconds
INFO  : Concurrency mode is disabled, not creating a lock manager
INFO  : Executing command(queryId=hive_20190724222711_18df4f09-d690-4774-af47-abe0c63bf8b2): show tables
INFO  : Starting task [Stage-0:DDL] in serial mode
INFO  : Completed executing command(queryId=hive_20190724222711_18df4f09-d690-4774-af47-abe0c63bf8b2); Time taken: 0.063 seconds
INFO  : OK
INFO  : Concurrency mode is disabled, not creating a lock manager
+-----------+
| tab_name  |
+-----------+
+-----------+
No rows selected (1.974 seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment