博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
eclipse远程连接Hbase数据库
阅读量:7038 次
发布时间:2019-06-28

本文共 3658 字,大约阅读时间需要 12 分钟。

hot3.png

使用了二台机器,一台是win10,一台是ubuntu,eclipse运行于win10,hadoop和hbase支行于ubuntu。

一、环境

1.ubuntu:14.10

2.jdk:1.8.0_131

3.hadoop:2.7.3

4.hbase:1.1.2

二、配置

此处hadoop和hbase都是配置了伪分布式集群,具体如何配置可参考博客:http://dblab.xmu.edu.cn/blog/install-hbase/

三、问题:参照博客配置后,在win10上用eclipse远程连接ubuntu的hbase报错,现在原有配置上做一些修改。

1.修改hosts文件:sudo vim /etc/hosts

原始配置为:其中xj-Lenovo-IdeaPad-V450为ubuntu的机器名

127.0.0.1       localhost127.0.1.1    xj-Lenovo-IdeaPad-V450

修改为:其中192.168.1.105为ubuntu机器的IP

127.0.0.1       localhost192.168.1.105   xj-Lenovo-IdeaPad-V450

2.修改./conf/hbase_site.xml文件:vim ./conf/hbase-site.xml,此处配置都使用机器名,不要使用ip和localhost

hbase.rootdir
hdfs://xj-Lenovo-IdeaPad-V450:9000/hbase
hbase.cluster.distributed
true
hbase.master
hdfs://xj-Lenovo-IdeaPad-V450:60000
hbase.zookeeper.quorum
xj-Lenovo-IdeaPad-V450:2181

3.修改win10机器的hosts文件 

192.168.1.105  xj-Lenovo-IdeaPad-V450

三、java代码 

package com.xiaoxing.hadoop;import java.io.IOException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.HColumnDescriptor;import org.apache.hadoop.hbase.HTableDescriptor;import org.apache.hadoop.hbase.TableName;import org.apache.hadoop.hbase.client.Admin;import org.apache.hadoop.hbase.client.Connection;import org.apache.hadoop.hbase.client.ConnectionFactory;/** * HBase操作 *  * @author Administrator * */public class HBaseDemo {	/**	 * hadoop配置	 */	private static Configuration configuration;	/**	 * hbase客户端连接	 */	private static Connection connection;	private static Admin admin;	private static final String HBASE_ROOT_DIR = "hdfs://192.168.1.105:9000/hbase";	/**	 * HBase初始化,创建连接	 */	public static void init() {		configuration = HBaseConfiguration.create();		configuration.set("hbase.rootdir", HBASE_ROOT_DIR);		configuration.set("hbase.zookeeper.quorum", "192.168.1.105");		configuration.set("hbase.zookeeper.property.clientPort", "2181");		try {			// 创建连接			connection = ConnectionFactory.createConnection(configuration);			admin = connection.getAdmin();			System.out.println("创建连接成功");		} catch (IOException e) {			System.out.println("创建连接失败");			e.printStackTrace();		}	}	public static void close() {		if (null != admin) {			try {				admin.close();				System.out.println("关闭admin");			} catch (IOException e) {				e.printStackTrace();			}		}		if (null != connection) {			try {				connection.close();				System.out.println("关闭connection");			} catch (IOException e) {				e.printStackTrace();			}		}	}	/**	 * 创建表	 * 	 * @param tableName:表名	 * @param columnFamily:列簇	 */	public static void createTable(String tableName, String[] columnFamily) {		init();		TableName table = TableName.valueOf(tableName);		try {						if (admin.tableExists(table)) {				System.out.println("表:" + tableName + "存在");			} else {				HTableDescriptor hTableDescriptor = new HTableDescriptor(table);				for (String col : columnFamily) {					HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(col);					hTableDescriptor.addFamily(hColumnDescriptor);				}				admin.createTable(hTableDescriptor);				System.out.println("创建表:" + tableName + "成功");			}		} catch (IOException e) {			e.printStackTrace();		} finally {			//close();		}	}	public static void main(String[] args) {		// init();		String[] colFamily = { "sname", "course" };		createTable("Score", colFamily);		// close();	}}

 

转载于:https://my.oschina.net/u/729917/blog/911358

你可能感兴趣的文章
决策树
查看>>
cocos3.x新建项目
查看>>
2018-2019 20165208 网络对抗 Exp3 免杀原理与实践
查看>>
IBM区块链总经理谈区块链
查看>>
mongoose学习文档
查看>>
关于接口
查看>>
Mixin Messenger 源码解读 1 — — WCDB Swift
查看>>
PgwSlideshow-基于Jquery的图片轮播插件
查看>>
cookie、session、sessionid 与jsessionid
查看>>
一行 Shell 通过 Nginx access 日志实时统计单台机器QPS
查看>>
改变button上title和图片的位置
查看>>
C# 组件模组引用第三方组件问题
查看>>
WebForm 内置对象2
查看>>
使用Web.Config Transformation配置灵活的配置文件
查看>>
一个简单的sel server 函数的自定义
查看>>
linux文件权限详解
查看>>
必应词典桌面版 --- 基于大学生用户群体的软件评测与分析(与有道词典对比版 1功能篇)...
查看>>
转贴:Linq的Distinct太不给力了
查看>>
Duwamish深入剖析-结构篇
查看>>
ASP.NET Sprite and Image Optimization Framework 小demo
查看>>