hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx

上传人:b****4 文档编号:16366826 上传时间:2022-11-23 格式:DOCX 页数:17 大小:87.03KB
下载 相关 举报
hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx_第1页
第1页 / 共17页
hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx_第2页
第2页 / 共17页
hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx_第3页
第3页 / 共17页
hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx_第4页
第4页 / 共17页
hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx

《hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx(17页珍藏版)》请在冰豆网上搜索。

hadoop和hbase分布式配置及整合eclipse开发Word格式文档下载.docx

四、配置hadoop

现在master上配置如下:

在/hadoop-0.20.2/conf/hadoop-env.sh中jdk的安装路径

#Thejavaimplementationtouse.Required.

exportJAVA_HOME="

C:

\Java\jdk1.6.0_02"

当然还有其中还有其他要配置的,测试用,明白了就行.

分别在/hadoop-0.20.2/conf/core-site.xml、hdfs-site.xml、mapred-site.xml中配置如下:

core-site.xml

<

property>

<

name>

fs.default.name<

/name>

value>

hdfs:

//master:

9001<

/value>

/property>

 

hdfs-site.xml

dfs.datanode.max.xcievers<

4096<

dfs.replication<

2<

mapred-site.xml

mapred.job.tracker<

master:

9002<

<

mapred.task.timeout<

0<

mapred.child.tmp<

/home/hadoop-0.20.2/temp<

在/hadoop-0.20.2/conf/masters、slavers文件中加入主机:

masters文件中加入:

master

slavers文件中加入:

master//将master也做为datanode

slaver

配置完成后将此copy到slaver1上去.

为了输入简单:

配置环境变量:

HADOOP_HOME=e:

/hadoop-0.20.2

并在/cygwin/etc/pofile中加入:

exportHADOOP_HOME=/cygdrive/e/hadoop-0.20.2

exportPATH=$PATH:

$HADOOP_HOME/bin

#xportHBASE_HOME=/cygdrive/e/hbase-0.90.3//先注释掉用的时候再取消

#xportPATH=$PATH:

$HBASE_HOME/bin

五、启动测试机器

$sshmaster

$cd$HADOOP_HOME

$bin/hadoopnamenode–format格式化主节点

$bin/start-all.sh

查看报告

$bin/hadoopdfsadmin–report

Web界面:

http:

50030/

50060/

50070

如有节点启动不起来的情况:

可以先stop-all.sh再删除临时文件/tmp和日志文件logs.再从新格式化节点,重新启动(start-all.sh)主机.

六、配置HBase

HBase是什么?

官网WIKI,英文看不懂,google翻译…

先配置环境变量吧.HBASE_HOME=e:

/habse-0.90.3

接着取消/cygwin/etc/pofile的注释

在hbase-0.90.3/conf/hbase-env.sh中修改jdk的安装路径

#Thejavaimplementationtouse.Java1.6required.

exportJAVA_HOME="

//当然这里有很多其他的配置,用的时候自行修改

修改hbase-site.xml

hbase.rootdir<

//如果是在单机下只保留这一项即可

9001/hbase<

//与hadoop中的core-site.xml配置一直

hbase.cluster.distributed<

true<

hbase.master<

60000<

hbase.zookeeper.quorum<

slaver1<

//这里配置的主机说是单数,参考wiki

hbase.zookeeper.property.dataDir<

/data/work/zookeeper<

修改regionservers文件:

slaver1

配置完成后copy到slaver1上去即可.注意要jdk的配置

七、启动Hbase

浏览主页

http:

60010

可以使用shell命令创建表

$bin/hbaseshell

create‘test’,’id’,’name’

put‘test’,’row1’,’id’,’1’

put‘test’,’row1’,’name’,’feng’

list

scan‘test’

get‘test’,’row1’

….andsoon

八、整合eclipse做开发

将hadoop-0.20.2的/hadoop-0.20.2/contrib/eclipse-plugin/hadoop-0.20.2-eclipse-plugin.jar插件以link的方式集成到myeclipise中,具体的操作自己查看.如果有问题,请将myeclipse升级到8.0以后的

重启myeclipse将会在右上放工程模式中看到蓝色

____

/\~~~/\

----(..)

/\____/

/|(\|(

^\/___\/\|

|__||__|-"

新建工程

新建map和reduce类,以及M/R驱动类:

一个Map/Reduce例子

importjava.io.IOException;

importorg.apache.hadoop.fs.Path;

importorg.apache.hadoop.io.*;

importorg.apache.hadoop.mapreduce.Job;

importorg.apache.hadoop.mapreduce.Mapper;

importorg.apache.hadoop.mapreduce.Reducer;

importorg.apache.hadoop.mapreduce.lib.input.FileInputFormat;

importorg.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

publicclassNewMaxTemperature{

staticclassNewMaxTemperatureMapperextendsMapper<

LongWritable,Text,Text,IntWritable>

{

//privatestaticfinalintMISSING=99;

publicvoidmap(LongWritablekey,Textvalue,Contextcontext)throwsIOException,InterruptedException{

Stringline=value.toString();

Stringyear=line.substring(2,6);

intairTemperature;

intstartIndex=line.indexOf("

+"

);

intendIndex=line.indexOf("

."

airTemperature=Integer.parseInt(line.substring(startIndex+1,endIndex));

//Stringquality=line.substring(0,2);

//if(airTemperature!

=MISSING&

&

quality.matches("

[00]"

)){

context.write(newText(year),newIntWritable(airTemperature));

//}

}

staticclassNewMaxTemperatureReducerextendsReducer<

Text,IntWritable,Text,IntWritable>

publicvoidreduce(Textkey,Iterable<

IntWritable>

values,Contextcontext)throwsIOException,InterruptedException{

intmaxValue=Integer.MIN_VALUE;

for(IntWritablevalue:

values){

maxValue=Math.max(maxValue,value.get());

}

context.write(key,newIntWritable(maxValue));

}

publicstaticvoidmain(String[]args)throwsException{

if(args.length!

=2){

System.err.println("

Usage:

NewMaxTemperature<

inputpath>

outputpath>

"

System.exit(-1);

Jobjob=newJob();

job.setJarByClass(NewMaxTemperature.class);

FileInputFormat.addInputPath(job,newPath("

/user/Administrator/input"

));

FileOutputFormat.setOutputPath(job,newPath("

/user/Administrator/output"

job.setMapperClass(NewMaxTemperatureMapper.class);

job.setReducerClass(NewMaxTemperatureReducer.class);

job.setOutputKeyClass(Text.class);

job.setOutputValueClass(IntWritable.class);

System.exit(job.waitForCompletion(true)?

0:

1);

}

一个HBASE的例子:

packageorg.hbase.feng;

importjava.util.ArrayList;

importjava.util.List;

importorg.apache.hadoop.conf.Configuration;

importorg.apache.hadoop.hbase.HBaseConfiguration;

importorg.apache.hadoop.hbase.HColumnDescriptor;

importorg.apache.hadoop.hbase.HTableDescriptor;

importorg.apache.hadoop.hbase.KeyValue;

importorg.apache.hadoop.hbase.MasterNotRunningException;

importorg.apache.hadoop.hbase.ZooKeeperConnectionException;

importorg.apache.hadoop.hbase.client.Delete;

importorg.apache.hadoop.hbase.client.Get;

importorg.apache.hadoop.hbase.client.HBaseAdmin;

importorg.apache.hadoop.hbase.client.HTable;

importorg.apache.hadoop.hbase.client.Put;

importorg.apache.hadoop.hbase.client.Result;

importorg.apache.hadoop.hbase.client.ResultScanner;

importorg.apache.hadoop.hbase.client.Scan;

importorg.apache.hadoop.hbase.util.Bytes;

publicclassTestHbase{

privatestaticConfigurationconf=HBaseConfiguration.create();

publicvoidputData(){

try{

HTabletable=newHTable(conf,"

test"

Putput=newPut(Bytes.toBytes("

rows1"

put.add(Bytes.toBytes("

id"

),Bytes.toBytes("

0"

feng"

table.put(put);

}catch(IOExceptione){

e.printStackTrace();

publicvoidputData1(){

String[]columns=newString[]{"

"

age"

name"

};

for(inti=0;

i<

columns.length;

i++){

Putput=newPut(Bytes.toBytes("

rows"

+(i+1)));

for(intj=0;

j<

3;

j++){

put.add(Bytes.toBytes(columns[j]),Bytes.toBytes(String.valueOf(i)),Bytes.toBytes("

n_"

+i));

table.put(put);

publicvoidcreateTable()throwsIOException{

Stringtablename="

;

String[]columns=newString[]{"

HBaseAdminadmin=newHBaseAdmin(conf);

if(admin.tableExists(tablename)){

System.out.println("

表已存在"

else{

HTableDescriptortableDesc=newHTableDescriptor(tablename);

for(inti=0;

tableDesc.addFamily(newHColumnDescriptor(columns[i]));

admin.createTable(tableDesc);

创建表成功!

publicvoiddelete()throwsIOException{

HBaseAdminadmin=newHBaseAdmin(conf);

admin.disableTable("

scores"

admin.deleteTable("

System.out.println("

表删除成功!

}catch(MasterNotRunningExceptione){

}catch(ZooKeeperConnectionExceptione){

publicvoidscaner(){

HTabletable=newHTable(conf,"

Scans=newScan();

ResultScannerrs=table.getScanner(s);

for(Resultr:

rs){

//System.out.println(newString(r.getRow()));

//byte[]b=r.getValue(Bytes.toBytes("

cf"

c"

//if(b!

=null){

//System.out.println(newString(b));

//}

KeyValue[]kv=r.raw();

for(inti=0;

kv.length;

System.out.print(newString(kv[i].getRow())+"

"

System.out.print(newString(kv[i].getFamily())+"

:

System.out.print(newString(kv[i].getQualifier())+"

System.out.print(kv[i].getTimestamp()+"

System.out.println(newString(kv[i].getValue()));

}

//scan'

test'

{COLUMNS=>

['

id'

],CACHE_BLOCKS=>

false}

publicvoidgetFamily(){

Getget=newGet(Bytes.toBytes("

Resultr=table.get(get);

byte[]b=r.getValue(Bytes.toBytes("

),Bytes.toBytes

(1));

if(b==null){

System.out.println("

值不存在!

检查簇是不是存在"

return;

}else{

System.out.println(newString(b));

/*

*删除某一行数据

**

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 动态背景

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1