【Hbase】Java 远程连接 Hbase 并处理表数据
1、在你的window系统下 找到c:/window/system32/drivers/etc/hosts 在末尾添加 虚拟机IP 虚拟机的hostname(如 192.168.56.100 gg)2、在java代码中添加:Configuration config = HBaseConfiguration.create();config.set(“hbase.rootdir”,“hdfs:/...
·
1、在你的window系统下 找到c:/window/system32/drivers/etc/hosts 在末尾添加 虚拟机IP 虚拟机的hostname(如 192.168.56.100 gg)
2、在java代码中添加:
Configuration config = HBaseConfiguration.create();
config.set(“hbase.rootdir”,“hdfs://192.168.56.100:9000/hbase”);//和你的hadoop中core-site.xml中信息相同
config.set(“hbase.zookeeper.quorum”,“192.168.56.100”);//zookeeper地址
config.set(“hbase.zookeeper.property.clientPort”,“2181”);//zookeeper 端口
3、修改远程hbase中的hbase-site.xml文件末尾添加:
<property>
<name>hbase.zookeeper.quorum</name>
<value>192.168.56.100</value>
</property>
4、重启远程hbase
5、代码测试:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.zookeeper.server.ConnectionBean;
import java.io.IOException;
public class MyHbase {
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
config.set("hbase.rootdir","hdfs://192.168.56.100:9000/hbase");
config.set("hbase.zookeeper.quorum","192.168.56.100");
config.set("hbase.zookeeper.property.clientPort","2181");
Connection connection = ConnectionFactory.createConnection(config);
Table table = connection.getTable(TableName.valueOf("mtest:demo"));
Put put = new Put("1".getBytes());
put.addColumn("base".getBytes(),"name".getBytes(),"hehe".getBytes());
put.addColumn("base".getBytes(),"sex".getBytes(),"female".getBytes());
table.put(put);
}
}
6、远程hbase查看数据
更多推荐
已为社区贡献10条内容
所有评论(0)