phoenix使用注意事项

使用phoenix的版本是5.0.0-HBase-2.0,DBeaver的版本是21.3(7.1.5版本也试过可以)

用DBeaver连接出现的问题处理

1.需要把已安装hbase服务器/opt/hbase/lib目录下的jar包全部下载来

1.1 常规配置

1.2 DBeaver编辑驱动把原来的库给删除掉,加入下载下来的/opt/hbase/lib的文件夹

配置驱动是为了处理以下这个错

Inconsistent constant pool data in classfile for class org/apache/hadoop/hbase/client/Row. Method 'int lambda$static$28(org.apache.hadoop.hbase.client.Row, org.apache.hadoop.hbase.client.Row)' at index 57 is CONSTANT_MethodRef and should be CONSTANT_InterfaceMethodRef

1.3 连接属性加入

phoenix.schema.isNamespaceMappingEnabled  true
phoenix.schema.mapSystemTablesToNamespace  true

2.测试链接时,一直在Connecting Main中,也没有报错。自已写了JAVA类去链接测试,也是等了很久才报错

JAVA测试类报的错

 

org.apache.phoenix.exception.PhoenixIOException: callTimeout=1200000, callDuration=1211099: Failed after attempts=16, exceptions:
Fri Dec 16 10:08:31 CST 2022, RpcRetryingCaller{globalStartTime=1671156511361, pause=100, maxAttempts=16}, java.net.UnknownHostException: can not resolve 93351cfe09da,160xx,16711168328xx

这个错误是因为hbase的服务器配置了hosts文件,路径在/etc/hosts文件

这个93351cfe09da刚好跟报错信息对的上,也可以通过 http://39.xxx.xx.xx:16010/ 来查看

猜测可能是配置了别名,在本地的机器上(要连接phoneix的本地机器)修改hosts文件 

路径是C:\Windows\System32\drivers\etc\hosts

 39.xxx.xx.xx为安装hbase的服务器地址,93351cfe09da是从服务器的hosts文件中获得或从  http://39.xxx.xx.xx:16010/ 中的ServerName查看。

重新测试链接,就可以正常连接。

注:修改配置后,如果还报错,可以试着重启下DBeaver从重新链接


3.自已写的JAVA类做测试

pom文件

    <dependencies>
        <dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-core</artifactId>
            <version>5.0.0-HBase-2.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.9.2</version>
        </dependency>
    </dependencies>
    public static void main(String[] args) {
        Properties props = new Properties();
        props.setProperty("phoenix.query.timeoutMs", "3200");
        props.setProperty("hbase.rpc.timeout", "3200");
        props.setProperty("hbase.client.scanner.timeout.period", "3200");

        try {
            Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
            // 这里配置zookeeper的地址,可单个,也可多个。可以是域名或者ip
            String     url       = "jdbc:phoenix:39.xxx.xx.xx:2181/hbase";
            Connection conn      = DriverManager.getConnection(url,props);
            System.out.println(conn);
            Statement statement = conn.createStatement();

            String    sql  = "select count(1) from hxds.order_gps limit 10";
            long      time = System.currentTimeMillis();
            ResultSet rs   = statement.executeQuery(sql);
            while (rs.next()) {
                int count = rs.getInt(1);
                System.out.println("row count is " + count);
            }
            long timeUsed = System.currentTimeMillis() - time;
            System.out.println("time " + timeUsed + "mm");
            // 关闭连接
            rs.close();
            statement.close();
            conn.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

注:需要把服务器的/opt/hbase/conf/hbase-site.xml下载下来,放在resource目录下,如下图所示 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值