准备工作
1.创建hadoop用户
1.代码如下
$ sudo useradd -m hadoop -s /bin/bash
2.设置密码,添加管理员权限。
$ sudo passwd hadoop
$ sudo adduser hadoop sudo
3.更新apt
$ sudo apt-get update
4.安装配置文件VIM。
$ sudo apt-get install vim
5.安装SSH、配置SSH无密码登陆。
$ sudo apt-get install openssh-server
6.安装JAVA环境
下载文件jdk-8u162-linux-x64.tar.gz 使用Filezilla传输到“/home/linziyu/Downloads/”目录下。
$ cd /usr/lib
$ sudo mkdir jvm
$ cd ~ #进入hadoop用户的主目录
$ cd Downloads
$ sudo tar -zxvf ./jdk-8u162-linux-x64.tar.gz -C /usr/lib/jvm
7.设置环境变量
$ cd ~
$ vim ~/.bashrc
8.继续执行如下命令让.bashrc文件的配置立即生效
$ source ~/.bashrc
2.安装eclipse
在ubuntu软件中心中下载安装
在 Eclipse 中创建 MapReduce 项目
1.在Eclipse中创建项目
在弹出来的 General 选项面板中,General 的设置要与 Hadoop 的配置一致。
在 Eclipse 中操作 HDFS 中的文件
配置好后,点击左侧 Project Explorer 中的 MapReduce Location 就能直接查看 HDFS 中的文件列表
源代码
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
//*String[] otherArgs = (new GenericOptionsParser(conf, args)).getRemainingArgs();
String[] otherArgs=new String[]{
"input","outpu2"};
if(otherArgs.length < 2) {
System.err.println("Usage: wordcount <in> [<in>...] <out>"