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 /
hiveserver2的配置和使用
hive-site.xml配置hiveserver2的配置property>
name>hive.support.concurrencyname>
description>enable hive's tablelock manager servicedescription>
value>truevalue>
property>
property>
name>hive.zookeeper.quorumname>
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.hostname>
value>172.21.3.170value>
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.urisname>
value>thrift://172.21.1.56:9083value>
description>thrift uri for the remote metastore. used by metastoreclient to connect to remote metastore.description>
property>
property>
name>hive.metastore.localname>
value>falsevalue>
description>this is local store .description>
property>
shell交互bin/beeline
!connectjdbc:hive2://localhost:10000 e3basee3base123 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();
}
}