zoukankan      html  css  js  c++  java
  • HiveServer2的配置使用

    HiveServer2的配置和使用

    hive-site.xml配置

    hiveserver2的配置

    <property>

        <name>hive.support.concurrency</name>

        <description>Enable Hive's TableLock Manager Service</description>

        <value>true</value>

    </property>

    <property>

        <name>hive.zookeeper.quorum</name>

        <description>

           Zookeeper quorum used by Hive's Table Lock Manager

        </description>

        <value>

           e3basestorage1:2181,e3basestorage2:2181,e3basestorage3:2181

        </value>

    </property>

    <property>

        <name>hive.server2.thrift.bind.host</name>

        <value>172.21.3.170</value>

        <description>

           Bind host on which to run the HiveServer2 Thrift interface.Can

           be overridden by setting $HIVE_SERVER2_THRIFT_BIND_HOST

        </description>

    </property>

    远程访问元数据的配置

           <property>

      <name>hive.metastore.uris</name>

      <value>thrift://172.21.1.56:9083</value>

      <description>Thrift uri for the remote metastore. Used by metastoreclient to connect to remote metastore.</description>

    </property>

    <property>

      <name>hive.metastore.local</name>

      <value>false</value>

      <description>this is local store .</description>

    </property>

    shell交互

    bin/beeline

    !connectjdbc:hive2://localhost:10000 e3base e3base123 org.apache.hive.jdbc.HiveDriver  (红字为当前的用户名和密码

    )

    Jdbc连接

    远程启动元数据服务:

    nohup bin/hive --servicemetastore&

    启动hiveserver2服务

    nohup bin/hive --servicehiveserver2  &  以后台进程的方式启动

     

    Java客户端访问

    示例代码:

    package com.sitech;

     

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.sql.Statement;

     

    import org.apache.log4j.Logger;

     

    public class T1 {

       private static Logger log = Logger.getLogger(T1.class);

     

       private static String driverName = "org.apache.hive.jdbc.HiveDriver";

     

       public boolean run() {

     

          try {

            Class.forName(driverName);

            Connection con = null;

            con = DriverManager.getConnection(

                  "jdbc:hive2://172.21.3.170:10000/hivedb", "", "");

            Statement stmt = con.createStatement();

            ResultSet res = null;

     

            String sql = "selectcount(*) from test";

     

            System.out.println("Running:" + sql);

            res = stmt.executeQuery(sql);

            System.out.println("ok");

            while (res.next()) {

               System.out.println(res.getString(1));

     

            }

            return true;

          } catch (Exception e) {

            e.printStackTrace();

            log.error("Connection:" + e.getMessage());

            System.out.println("error");

            return false;

          }

     

       }

     

       public static void main(String[] args) throws SQLException {

          HiveJdbcClienthiveJdbcClient = new HiveJdbcClient();

          hiveJdbcClient.run();

       }

     

    }

     

  • 相关阅读:
    C# Debugger.IsAttached 调试启动浏览器 VS if DEBUG 启动调试内容
    【转载】如何三个月从零基础到C#中级程序员
    【转载】如何成为一个高级程序员
    如何找回QQ聊天记录、语音、图片?
    hexo博客yili主题个性化自定义教程(1) ——借鉴中学习,初认yili主题
    2019hexo博客部署到coding该绕的坑-奥怪的小栈
    2019Hexo博客Next主题深度美化 打造一个炫酷博客(2)-奥怪的小栈
    2019软件工程专业大学排名附官网-奥怪的小栈
    浅谈互联网+足球
    2019基于Hexo快速搭建个人博客,打造一个炫酷博客(1)-奥怪的小栈
  • 原文地址:https://www.cnblogs.com/jamesf/p/4751449.html
Copyright © 2011-2022 走看看