1.3.7.4 Impala
优质
小牛编辑
142浏览
2023-12-01
impala服务开放端口
描述 | 端口 |
---|---|
JDBC | 32404 |
impala shell | 32400 |
impala-shell方式
用户登录到master节点后, impala-shell客户端已经准备完毕, 环境变量$IMPALA_HOME设置完毕. 具体使用步骤如下:
impala-shell
> // 进入交互式的impala-shell界面
>connect ${impalad_server_ip}:32400; // 连接impala server beeswax端口
>select 1+1; // 执行用户自定义的命令.
JDBC方式
用户需要先和master节点建立SSH隧道, 然后配置java的系统属性以实现JDBC over SSH Tunnel.
与master节点建立ssh隧道 具体过程见建立SSH隧道
配置系统属性
通过java执行时的-D选项指定系统属性
java -cp ${classpath} -DsocksProxyHost="127.0.0.1" -DsocksProxyPort="1080" JdbcTest
通过在代码中指定系统属性
package com.xiaomi.infra.galaxy.test.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class JDBCTest { private static final int jdbc_port = 32404; private static String jdbc_host = "172.31.0.249"; private static String socks_port = "1080"; private static String socks_host = "127.0.0.1"; private static String SOCKS_VERSION = "5"; public void testJdbc() { Statement statement = null; Connection conn = null; try { System.setProperty("socksProxyHost", socks_host); System.setProperty("socksProxyPort", socks_port); System.setProperty("socksProxyVersion", SOCKS_VERSION); Class.forName("org.apache.hive.jdbc.HiveDriver"); String url = "jdbc:hive2://" + jdbc_host + ":" + jdbc_port + "/;auth=noSasl"; conn = DriverManager.getConnection(url); statement = conn.createStatement(); String sql = "select 1+1"; ResultSet rs = statement.executeQuery(sql); while (rs.next()) { int count = rs.getInt(1); System.out.println(count); } } catch (Exception e) { e.printStackTrace(); } finally { if (statement != null) { try { statement.close(); } catch (SQLException e) { // ignore } } if (conn != null) { try { conn.close(); } catch (SQLException e) { // ignore } } } } public static void main(String[] args) { JDBCTest test = new JDBCTest(); test.testJdbc(); } }
NOTE: 在pom中需要依赖hive-jdbc
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>0.13.1-cdh5.3.0</version>
</dependency><dependency>