惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

博客园 - Calendar

Hbase常用命令 CuteEditor测试 Windows 7使用问题 小问题之动态调用另一个程序集里的方法 GM的Hybrid MapPoint批量导入Pushpin的方法 - Calendar - 博客园 通过两个点的经纬度计算距离 地震了 下载试用IE 7.0 Beta 3.0 google maps可以支持地理信息查询了(附上功能介绍) - Calendar - 博客园 prototype理解 - Calendar - 博客园 google maps的脚本值得看看 - Calendar - 博客园 google卫星地图的url计算 linux下运行的eclipse的说明 用socket连接pop3服务器遇到的小问题 google maps又更新了 我是如何取得Reflector的真实程序的 对J2ME的想法 MiniQQ与LumaQQ
windows平台下用C#访问HBase
Calendar · 2013-08-08 · via 博客园 - Calendar

Hadoop中的HBase有多种数据访问方式,ubuntu里可以用hbase shell查看操作hbase数据库,但windows平台下需要用thrift对它进行访问。

例如hadoop安装在/usr/local/hadoop,hbase在/usr/local/hbase,thrift在/usr/local/thrift,则hbase.thrift文件应该使用 hbase/src/main/resources/org/apache/hadoop/hbase/thrift/hbase.thrift这个文件。thrift2目录下的hbase.thrift生成的方法不同,不好用。

1. 到thrift目录下,运行

bin/thrift -gen csharp /usr/local/hbasesrc/main/resources/org/apache/hadoop/hbase/thrift/hbase.thrift

会在当前目录生成gen-csharp文件夹,运行 zip -r cs.zip gen-csharp 打包到cs.zip,用ftp传输给windows。

2. 把thrift目录里的thrift c#访问类代码也打包传输到windows。

/usr/local/thrift/lib/csharp,src目录里有Thrift.csproj

3. 建立TestHbaseClient控制台程序,把Thrift项目加入solution。建立HBaseCommon项目,把gen-csharp里的文件都加入到此项目,最好给每个文件都加上命名空间。HBaseCommon引用Thrift,TestHbaseClient引用其它两个项目。

在Main函数里:

 1 TTransport transport = new TSocket("192.168.16.105", 9090);
 2 TProtocol tProtocol = new TBinaryProtocol(transport);
 3 var client = new Hbase.Client(tProtocol);
 4 transport.Open();
 5 
 6 List<byte[]> tbs =  client.getTableNames();
 7 foreach (byte[] tb in tbs)
 8 {
 9     string tn = Encoding.UTF8.GetString(tb);
10     Console.WriteLine("table:" + tn);
11 }
12 
13 List<TRowResult> reslut = client.getRow(Encoding.UTF8.GetBytes("case_info"), Encoding.UTF8.GetBytes("row1"), null);
14 foreach (var key in reslut)
15 {
16     Console.WriteLine(Encoding.UTF8.GetString(key.Row)); 
17     foreach (var k in key.Columns)
18     {
19         Console.Write(Encoding.UTF8.GetString(k.Key) + "\t");
20         Console.WriteLine(Encoding.UTF8.GetString(k.Value.Value));
21     }
22 }

4. 运行这段代码,会报错,连不上服务器,需要到hbase里设置一下,并启动thrift服务。

修改/usr/local/hbase/conf/hbase-site.xml,先加个伪分布式进行测试:

<property>

<name>hbase.rootdir</name>

<value>/home/hadoop/hbasedir</value>

</property>

到/usr/local/hbase目录下重启hbase服务

bin/hbase-start.sh

再运行bin/hbase-daemon.sh start thrift

现在就可以用C#去访问hbase数据库的内容了。