簡體   English   中英

如何啟動hiveserver2作為服務

[英]How to start hiveserver2 as service

大家好我已經在我的網絡中設置了多節點集群(即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作為服務的鏈接。

你試過 - 服務選項嗎?

$HIVE_HOME/bin/hive --service hiveserver2 &

對於1.2及更高版本,不推薦使用hive ,應直接使用hiveserver2命令。

所以現在在后台啟動hiveserver2的正確方法是:

nohup hiveserver2 &

或者輸出到日志文件:

nohup hiveserver2 > hive.log &

來源: https//cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-BuildingHivefromSource - 它表示不推薦使用“調用配置單元”。

試試這個

nohup hive --service hiveserver2 &

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM