• 经过前几天的学习,基本上能够小试牛刀编写一些小程序玩一玩了,在此之前做几项准备工作
  1. 明白我要用hadoop干什么
  2. 大体学习一下mapreduce
  3. ubuntu重新启动后,再启动hadoop会报连接异常的问题
  • 答:
  1. 数据提炼、探索数据、挖掘数据
  2. map=切碎,reduce=合并
  3. 重新启动后会清空tmp目录,默认namenode会存在这里,须要在core-site.xml文件里添加(别忘了创建目录,没权限的话,须要用root创建并把权限改成777):
    <property>
    <name>hadoop.tmp.dir</name>
    <value>/usr/local/hadoop/tmp</value>
    </property>
  • 大数据,我的第一反应是现有关系型数据库中的数据怎么跟hadoop结合使用,网上搜了一些资料,使用的是DBInputFormat,那就简单编写一个从数据库读取数据,然后经过处理后,生成文件的小样例吧
  • 数据库弄的简单一点吧,id是数值整型、test是字符串型,需求非常easy,统计TEST字段出现的数量



  • 数据读取类:
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable; public class DBRecoder implements Writable, DBWritable{
String test;
int id;
@Override
public void write(DataOutput out) throws IOException {
out.writeUTF(test);
out.writeInt(id);
}
@Override
public void readFields(DataInput in) throws IOException {
test = in.readUTF();
id = in.readInt();
}
@Override
public void readFields(ResultSet arg0) throws SQLException {
test = arg0.getString("test");
id = arg0.getInt("id");
}
@Override
public void write(PreparedStatement arg0) throws SQLException {
arg0.setString(1, test);
arg0.setInt(2, id);
}
}
  • mapreduce操作类
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.db.DBConfiguration;
import org.apache.hadoop.mapreduce.lib.db.DBInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser; public class DataCountTest {
public static class TokenizerMapper extends Mapper<LongWritable, DBRecoder, Text, IntWritable> {
public void map(LongWritable key, DBRecoder value, Context context) throws IOException, InterruptedException {
context.write(new Text(value.test), new IntWritable(1));
}
} public static class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable(); public void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
} public static void main(String[] args) throws Exception {
args = new String[1];
args[0] = "hdfs://192.168.203.137:9000/user/chenph/output1111221"; Configuration conf = new Configuration(); DBConfiguration.configureDB(conf, "oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:@192.168.101.179:1521:orcl", "chenph", "chenph"); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); Job job = new Job(conf, "DB count"); job.setJarByClass(DataCountTest.class);
job.setMapperClass(TokenizerMapper.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
String[] fields1 = { "id", "test"};
DBInputFormat.setInput(job, DBRecoder.class, "t1", null, "id", fields1); FileOutputFormat.setOutputPath(job, new Path(otherArgs[0])); System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

--------------------------------------------------------------------------------------------------

开发过程中遇到的问题:
  1. Job被标记为已作废,那应该用什么我还没有查到
  2. 乱码问题,hadoop默认是utf8格式的,假设读取的是gbk的须要进行处理
  3. 这类样例网上挺少的,有也是老版的,新版的资料没有,我全然是拼凑出来的,非常多地方还不甚了解,须要进一步学习官方资料
  4. 搜索资料时,有资料说不建议採用这样的方式处理实际的大数据问题,原因就是并发过高,会瞬间秒杀掉数据库,一般都会採用导成文本文件的形式

Win7中使用Eclipse连接虚拟机中的Ubuntu中的Hadoop2.4&lt;3&gt;的更多相关文章

  1. 通过win下的eclipse连接虚拟机中伪分布的hadoop进行调试

    VMware虚拟机配置Ubuntu桥接方式(Bridged)使虚拟机和宿主机能互相ping通, 通过win下的eclipse连接虚拟机中伪分布的hadoop进行调试 1.设置Bridged上网方式 V ...

  2. win7中配置eclipse连接Ubuntu内的hadoop

    Hadoop java 分布式 云计算 数据库 目录[-] 1.设置Ubuntu静态IP: 1)配置网卡参数到interfaces文件: 2)重启网卡: 2.配置Ubuntu的hosts: 3.配置V ...

  3. win10 eclipse连接虚拟机ubuntu中的hdfs

    1.eclipse安装连接hadoop的插件hadoop-eclipse-plugin-2.6.0(注意自己hadoop的版本) 将该插件放在eclipse安装路径的plugins文件夹中. ps:我 ...

  4. windows中eclipse连接虚拟机hdfs

    1.修改配置文件core-site.xml,将其中localhost改为虚拟机的ip地址: 在Ubuntu中,打开控制台,使用命令ifconfig查看虚拟机ip,如图: 修改[hadoop安装路径]/ ...

  5. 如何在Windows中使用Eclipse访问虚拟机Linux系统中的hadoop(伪分布式)

    因为计算机配置过低,在虚拟机里几乎无法使用Eclipse,效率极低! 所以现在尝试使用Windows下Eclipse操作虚拟机中Hadoop,步骤如下: 开发环境:Hadoop2.7.1,Ubuntu ...

  6. Win7环境下Eclipse连接Hadoop2.2.0

    准备: 确保hadoop2.2.0集群正常运行 1.eclipse中建立java工程,导入hadoop2.2.0相关jar包 2.在src根目录下拷入log4j.properties,通过log4j查 ...

  7. [开发]Win7环境下Eclipse连接Hadoop2.2.0

    准备: 确保hadoop2.2.0集群正常运行 1.eclipse中建立mven工程,并编辑pom文件如下 <dependencies> <dependency> <gr ...

  8. Window10中利用Windbg与虚拟机(window7)中调试驱动建立方法

    想起自己的windbg配置就转载:eqera的windows内核调试配置,真的是获益良多希望他不会介意我转载他的博客,帮了我很多,记录下来给我也给大家, 其中我主要看的是VMWare的pipe建立,而 ...

  9. 无法将 Ethernet0 连接到虚拟网络”VMnet0″ 详细信息可以在 vmware.log 文件中找到未能连接虚拟机Ethernet0

    在 vmware“编辑->虚拟网络设置”里面,点“恢复默认”可解决.  

随机推荐

  1. Spring工厂方式创建Bean实例

    创建Bean实例的方式: 1) 通过构造器(有参或无参) 方式: <bean id="" class=""/> 2) 通过静态工厂方法 方式: &l ...

  2. reCAPTCHA 简单分析

    CAPTCHA项目是Completely Automated Public Turing Test to Tell Computers and Humans Apart (全自动区分计算机和人类的图灵 ...

  3. C语言练习代码

    1.运用for循环根据输入的金字塔层数,输出金字塔 eg: #include <stdio.h>int main(void){ int i,j,num; printf("请输入三 ...

  4. AngularJS自定义指令(Directives)在IE8下的一个坑

    在项目中,由于要兼容到IE8,我使用1.2.8版本的angularJS.这个版本是支持自定义指令的.我打算使用自定义指令将顶部的header从其他页面分离.也就是实现在需要header的页面只用在&l ...

  5. CMDB反思4

    CMDB模型设计2 http://blog.vsharing.com/xqscool/A1275233.html 估计大家看到破子的这两篇都有点晕哈,我也有点晕. 两篇对比来看.   第1处,属性部分 ...

  6. 详解centos下vi的用法

    vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的任何版本,vi编辑器是完全相 ...

  7. 前端技能汇总 Frontend Knowledge Structure

    Frontend Knowledge Structure 项目起源 还记得@jayli 的这幅前端知识结构图么. 图片的形式具有诸多的不便.缺失源图的我们,无法为此图贡献些什么,随着时间的迁移,或许有 ...

  8. Netmask v. Address Prefix Length

    Netmask Address Prefix Length Hosts / Class C's / Class B's / Class A's (Class C) / / , / , / , / , ...

  9. 15+ 易响应的CSS框架快速开启你的敏捷网站项目

    由 于移动互联用户的快速增加,现在数量已经超出10亿,几乎可以肯定的是你的网站每天都会有移动用户访问.如果你组织计划创建一个对移动用户友好的浏览体 验,有多个方面需要考虑.响应快速的网站设计似乎现在很 ...

  10. 基于Heritrix的特定主题的网络爬虫配置与实现

    建议在了解了一定网络爬虫的基本原理和Heritrix的架构知识后进行配置和扩展.相关博文:http://www.cnblogs.com/hustfly/p/3441747.html 摘要 随着网络时代 ...