gpt4 book ai didi

hadoop - 从远程机器连接到 hbase

转载 作者:可可西里 更新时间:2023-11-01 14:23:56 27 4
gpt4 key购买 nike

我有安装了 habse 的虚拟机。IP:192.168.20.10我想尝试从我的桌面连接到 hbase:这是我正在尝试的>

public static void main(String[] args) throws IOException {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/hbase-beans.xml", HBaseConnection.class);
context.registerShutdownHook();
UserRepository userRepository = context.getBean(UserRepository.class);
List<User> users = userRepository.findAll();

System.out.println("Number of users = " + users.size());
System.out.println(users);
}






public List<User> findAll() {
return hbaseTemplate.find(tableName, "cfInfo", new RowMapper<User>() {

public User mapRow(Result result, int rowNum) throws Exception {
return new User(Bytes.toString(result.getValue(CF_INFO, qUser)),
Bytes.toString(result.getValue(CF_INFO, qEmail)),
Bytes.toString(result.getValue(CF_INFO, qPassword))

);
}
});

}

这是我的 bean.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:hadoop="http://www.springframework.org/schema/hadoop" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<context:component-scan base-package="com.hbase.dao"/>
<context:component-scan base-package="com.hbase.object"/>

<hadoop:configuration id="hadoopConfiguration">fs.default.name=hdfs://192.168.20.10:9000</hadoop:configuration>


<hadoop:hbase-configuration configuration-ref="hadoopConfiguration" zk-port="2181" zk-quorum="192.168.20.10"></hadoop:hbase-configuration>

<bean id="hbaseTemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate">
<property name="configuration" ref="hbaseConfiguration" />
</bean>

</beans>

当我直接在远程机器上运行时,这段代码工作正常。当我通过提供 hbase 的 ip 从我的 Windows 机器运行相同的代码时,它不会返回任何值。

最佳答案

Configure your windows machine C:\Windows\System32\drivers\etc\hosts file to resolve your HBase cluster node details. Recommended Make sure DNS configuration is right!. i.e. addresses of all nodes(Regionservers) of HBase Cluster is resolved from windows machine.

关于hadoop - 从远程机器连接到 hbase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30756096/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com