从远程计算机

时间:2015-06-10 12:15:42

标签: hadoop hbase

我有安装了habse的VM。 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>

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

1 个答案:

答案 0 :(得分:0)

  

配置您的Windows计算机C:\Windows\System32\drivers\etc\hosts   用于解析HBase集群节点详细信息的文件。建议确保   DNS配置是对的!即所有地址   HBase Cluster的节点(Regionservers)是从windows解析的   机。