java 如何启动 hiveserver2 作为服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27604267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start hiveserver2 as service
提问by Ashish Jagtap
Hi all I have setup multi node cluster (i.e 5 node) in my network which working fine. now I wanted to insert and retrieve data from cluster using hive thus I have setup hive latest release apache-hive-0.14.0-bin.tar.gz(i.e. 0.14.0from here) on my master node as given in thisarticle.
大家好我已经在我的网络中设置了多节点集群(即 5 个节点),它工作正常。现在我想插入和检索利用蜂巢因此我已经安装蜂箱最新版本的集群数据的Apache蜂巢-0.14.0-bin.tar.gz(即0.14.0从这里我的主节点上)在给定的这个文章。
also I have written a java client class which will make jdbc connection to hive and insert the data into HDFS using hive.
我还编写了一个 java 客户端类,它将使 jdbc 连接到 hive 并使用 hive 将数据插入到 HDFS 中。
HiveJdbcClient.Java
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.
my application able to connect to server when I run following command in terminal
当我在终端中运行以下命令时,我的应用程序能够连接到服务器
$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
but when I close this terminal then my application gives following error
但是当我关闭此终端时,我的应用程序会出现以下错误
ERROR
错误
java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://X.X.X.X:10000/default: java.net.ConnectException: Connection refused
that means I have to run hiveserver2 as a service on my master node.
这意味着我必须在我的主节点上将 hiveserver2 作为服务运行。
can any one help me to run this hiveserver2 as service. or any link which will help me to run hiveserver2 as service.
任何人都可以帮助我将此 hiveserver2 作为服务运行。或任何可以帮助我将 hiveserver2 作为服务运行的链接。
回答by Micha? D?bski
Have you tried --service option?
您是否尝试过 --service 选项?
$HIVE_HOME/bin/hive --service hiveserver2 &
回答by Nicomak
For versions 1.2 and above, hive
is deprecated and the hiveserver2
command should be used directly.
对于 1.2 及以上版本,hive
已弃用,hiveserver2
应直接使用该命令。
So the correct way to start hiveserver2 in background is now :
所以现在在后台启动 hiveserver2 的正确方法是:
nohup hiveserver2 &
Or with output to a log file :
或者输出到日志文件:
nohup hiveserver2 > hive.log &
Sources : https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-BuildingHivefromSource- It says that "invoking hive" is deprecated.
来源:https: //cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-BuildingHivefromSource- 它说“调用配置单元”已被弃用。
回答by Ashish Jagtap
Try this
试试这个
nohup hive --service hiveserver2 &