TOP

HiveServer2 的几种连接方式
2019-02-13 13:00:24 】 浏览:939
Tags:HiveServer2 连接 方式

hive只是一个客户端,没有集群的概念

Hive常用的客户端:hive/webui/beeline/Java API
beeline/Java API连上HiveServer2(HS2)就可以操作hive
1.beeline和HiveServer2配合使用

[hadoop@hadoop001 ~]$ cd $HIVE_HOME/bin
[hadoop@hadoop001 bin]$ ./hiveserver2
which: no hbase in (/home/hadoop/app/scala-2.11.8/bin:/home/hadoop/app/sqoop-1.4.6-cdh5.7.0/bin:/usr/local/protobuf/bin:/home/hadoop/app/findbugs-1.3.9/bin:/home/hadoop/app/apache-maven-3.3.9/bin:/home/hadoop/app/hive-1.1.0-cdh5.7.0/bin:/home/hadoop/app/hadoop-2.6.0/bin:/usr/java/jdk1.8.0_45/bin:/usr/java/jdk1.7.0_80/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/bin)

打开另一个session
1)第一种方法

[hadoop@hadoop001 ~]$ cd $HIVE_HOME/bin
[hadoop@hadoop001 bin]$ ./beeline
which: no hbase in (/home/hadoop/app/scala-2.11.8/bin:/home/hadoop/app/sqoop-1.4.6-cdh5.7.0/bin:/usr/local/protobuf/bin:/home/hadoop/app/findbugs-1.3.9/bin:/home/hadoop/app/apache-maven-3.3.9/bin:/home/hadoop/app/hive-1.1.0-cdh5.7.0/bin:/home/hadoop/app/hadoop-2.6.0/bin:/usr/java/jdk1.8.0_45/bin:/usr/java/jdk1.7.0_80/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/bin)
Beeline version 1.1.0-cdh5.7.0 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000 hadoop
scan complete in 17ms
Connecting to jdbc:hive2://localhost:10000
Enter password for jdbc:hive2://localhost:10000: 
Connected to: Apache Hive (version 1.1.0-cdh5.7.0)
Driver: Hive JDBC (version 1.1.0-cdh5.7.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10000>

2)第二种方法

[hadoop@hadoop001 ~]$ cd $HIVE_HOME/bin
[hadoop@hadoop001 bin]$ ./beeline -u jdbc:hive2://localhost:10000 -n hadoop
which: no hbase in (/home/hadoop/app/scala-2.11.8/bin:/home/hadoop/app/sqoop-1.4.6-cdh5.7.0/bin:/usr/local/protobuf/bin:/home/hadoop/app/findbugs-1.3.9/bin:/home/hadoop/app/apache-maven-3.3.9/bin:/home/hadoop/app/hive-1.1.0-cdh5.7.0/bin:/home/hadoop/app/hadoop-2.6.0/bin:/usr/java/jdk1.8.0_45/bin:/usr/java/jdk1.7.0_80/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/bin)
scan complete in 13ms
Connecting to jdbc:hive2://localhost:10000
Connected to: Apache Hive (version 1.1.0-cdh5.7.0)
Driver: Hive JDBC (version 1.1.0-cdh5.7.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.1.0-cdh5.7.0 by Apache Hive
0: jdbc:hive2://localhost:10000> 

查看信息

0: jdbc:hive2://localhost:10000> show tables;
+------------------+--+
|     tab_name     |
+------------------+--+
| hive_rownumber   |
| hive_wc          |
| rating_json      |
| user_click1      |
| user_click_tmp1  |
| zh               |
+------------------+--+
6 rows selected (12.5 seconds)
INFO  : Compiling command(queryId=hadoop_20180729143030_89696039-274b-40e5-b93f-cd7ee1ea1bfb): show tables
INFO  : Semantic Analysis Completed
INFO  : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:tab_name, type:string, comment:from deserializer)], properties:null)
INFO  : Completed compiling command(queryId=hadoop_20180729143030_89696039-274b-40e5-b93f-cd7ee1ea1bfb); Time taken: 8.538 seconds
INFO  : Concurrency mode is disabled, not creating a lock manager
INFO  : Executing command(queryId=hadoop_20180729143030_89696039-274b-40e5-b93f-cd7ee1ea1bfb): show tables
INFO  : Starting task [Stage-0:DDL] in serial mode
INFO  : Completed executing command(queryId=hadoop_20180729143030_89696039-274b-40e5-b93f-cd7ee1ea1bfb); Time taken: 1.025 seconds
INFO  : OK

关掉正在运行的服务

[hadoop@hadoop001 bin]$ jps
11168 RunJar
3362 SecondaryNameNode
3682 NodeManager
3237 DataNode
3590 ResourceManager
3144 NameNode
11418 Jps
11292 RunJar
[hadoop@hadoop001 bin]$ kill -9 11168 11292
[hadoop@hadoop001 bin]$ jps
3362 SecondaryNameNode
3682 NodeManager
11428 Jps
3237 DataNode
3590 ResourceManager
3144 NameNode
[1]+  Killed                  ./beeline -u jdbc:hive2://localhost:10000 -n hadoop

修改默认端口

[hadoop@hadoop001 bin]$ hiveserver2 --hiveconf hive.server2.thrift.port=14000
which: no hbase in (/home/hadoop/app/scala-2.11.8/bin:/home/hadoop/app/sqoop-1.4.6-cdh5.7.0/bin:/usr/local/protobuf/bin:/home/hadoop/app/findbugs-1.3.9/bin:/home/hadoop/app/apache-maven-3.3.9/bin:/home/hadoop/app/hive-1.1.0-cdh5.7.0/bin:/home/hadoop/app/hadoop-2.6.0/bin:/usr/java/jdk1.8.0_45/bin:/usr/java/jdk1.7.0_80/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/bin)
[hadoop@hadoop001 bin]$ ./beeline -u jdbc:hive2://localhost:14000 -n hadoop 
which: no hbase in (/home/hadoop/app/scala-2.11.8/bin:/home/hadoop/app/sqoop-1.4.6-cdh5.7.0/bin:/usr/local/protobuf/bin:/home/hadoop/app/findbugs-1.3.9/bin:/home/hadoop/app/apache-maven-3.3.9/bin:/home/hadoop/app/hive-1.1.0-cdh5.7.0/bin:/home/hadoop/app/hadoop-2.6.0/bin:/usr/java/jdk1.8.0_45/bin:/usr/java/jdk1.7.0_80/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hadoop/bin)
scan complete in 29ms
Connecting to jdbc:hive2://localhost:14000
Connected to: Apache Hive (version 1.1.0-cdh5.7.0)
Driver: Hive JDBC (version 1.1.0-cdh5.7.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.1.0-cdh5.7.0 by Apache Hive
0: jdbc:hive2://localhost:14000>

2.Java API 操作Hive

import java.sql.DriverManager

object JdbcApp {
  val driverName = "org.apache.hive.jdbc.HiveDriver"
  def main(args: Array[String]): Unit = {
    try {
      Class.forName(driverName)
    } catch {
      case e : ClassNotFoundException =>
      e.printStackTrace()
      System.exit(1)
    }
    val con = DriverManager.getConnection("jdbc:hive2://hadoop000:10000/default", "hadoop", "")
    val stmt = con.createStatement()
    val tableName = "emp"
    val sql = "select * from " + tableName
    println("Running: " + sql)
    val res = stmt.executeQuery(sql)
    while (res.next()) {
      println(res.getInt(1) + "\t" + res.getString(2) + "\t" + res.getString(3) + "\t"
        + res.getInt(4) + "\t" + res.getString(5) + "\t" + res.getString(6) + "\t"
        + res.getString(7) + "\t" + res.getString(8))
    }
  }
}

3.WEB UI

  1. Hive官方的不建议使用
  2. HUE(Hadoop User Experience)
    http://github.com/cloudera/hue
  3. Zeppelin
    功能很强大,支持的东西很多

HiveServer2 的几种连接方式 https://www.cppentry.com/bencandy.php?fid=117&id=208356

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Hadoop_常用存储与压缩格式 下一篇004.课程环境搭建:Hive 0.13.0安..