如何启动hiveserver2作为服务

 1hhhhhhhhhhh0_196_217 发布于 2022-12-04 03:05

大家好我已经在我的网络中设置了多节点集群(即5节点),工作正常.现在我想插入和利用这样我已经设置不亦乐乎最新版本蜂巢从集群中检索数据的Apache蜂巢-0.14.0-bin.tar.gz (即0.14.0这里我的主节点上)在给定的这个文章.

我也编写了一个java客户端类,它将使jdbc连接到hive并使用hive将数据插入HDFS.

HiveJdbcClient.Java

public class HiveJdbcClient {

private static final String DRIVER_NAME = "org.apache.hive.jdbc.HiveDriver";
    private static final String HIVE_URL = "jdbc:hive2://x.x.x.x:10000/default";
    private static final String HIVE_UNAME = "";
    private static final String HIVE_PWD = "";
    private static Connection con;

    private HiveJdbcClient() {}

    public static Connection getConnection() {
        try {
            if (con == null) {
                synchronized (HiveJdbcClient.class) {
                    if (con == null) {
                        Class.forName(DRIVER_NAME);
                        con = DriverManager.getConnection(HIVE_URL,
                                HIVE_UNAME, HIVE_PWD);
                        System.out.println("Successfuly Connected to database...!");
                    }
                }// End of synchronized block.
            }// End of if block.
        } catch (SQLException e) {
            System.out.println("Can Not able to connect to database pls check your settings \n" + e);
        } catch (ClassNotFoundException e) {
            System.out.println("Can Not able to connect to database pls check your settings \n" + e);
        }// End of try-catch block. 
        return con;
    }// End of getConnection() Method.

    public static ResultSet executeQuery(String sql) {
        ResultSet set = null;
        try {
            if (sql != null) {
                set = getConnection().createStatement().executeQuery(sql);
            }
        } catch (SQLException e) {
            System.out.println("Error while executing query " + e);
        }// End of try-catch block.
        return set;
    }// End of executeQuery() Method.

    public static void main(String[] args) throws ParseException, SQLException {
        ResultSet res = executeQuery("SELECT * FROM mytable");
        while (res.next()) {
            System.out.println(String.valueOf(res.getString(1)) + '\t'
                    + String.valueOf(res.getFloat(2)) + '\t'
                    + String.valueOf(res.getString(3)));
        }
    }
}//End of HiveJdbcClient Class.

当我在终端中运行以下命令时,我的应用程序能够连接到服务器

$HIVE_HOME/bin/hiveserver2
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hadoop-2.6.0/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/apache-hive-0.14.0-bin/lib/hive-jdbc-0.14.0-standalone.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.slf4j.impl.Log4jLoggerFactory]
OK 

但是当我关闭此终端时,我的应用程序会出现以下错误

错误

java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://X.X.X.X:10000/default: java.net.ConnectException: Connection refused

这意味着我必须在我的主节点上运行hiveserver2作为服务.

任何人都可以帮我运行这个hiveserver2作为服务.或任何可以帮助我运行hiveserver2作为服务的链接.

2 个回答
  • 你试过 - 服务选项吗?

    $HIVE_HOME/bin/hive --service hiveserver2 &
    

    2022-12-11 02:06 回答
  • 对于1.2及更高版本,hive不推荐使用,并且hiveserver2应直接使用该命令.

    所以现在在后台启动hiveserver2的正确方法是:

    nohup hiveserver2 &
    

    或者输出到日志文件:

    nohup hiveserver2 > hive.log &
    

    来源:https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-BuildingHivefromSource - 它表示不推荐使用"调用配置单元".

    2022-12-11 02:14 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有