文章目录

  • hadoop大数据
    • 一、hadoop连不上网解决:
    • 二、Xshell6连接
    • 三、启动服务
    • 4、hdfs的shell操作
      • 相关的命令:
    • 五、使用java去操纵hdfs
      • 首先新建一个maven项目
      • 添加maven依赖
      • 新建测试类
        • 1、新建一个文件夹
        • 2、创建文件
        • 3、重命名文件
        • 4、查看文件
        • 5、上传文件
        • 6、下载文件
    • 六、可视化yarn和MapReauce
      • 词频统计案例
        • 1、先停止hadoop
        • 2、启动所有
        • 3、输入访问8088端口
        • 实现代码
        • 打包
        • 放进hadoop中
        • 运行jar
        • 查看文件内容
    • 七、ECharts
      • 首先创建一个html
      • 引入ECharts的js文件
      • 为ECharts准备一个具备大小(宽高)的Dom
      • 柱状图
      • 饼图

hadoop大数据

一、hadoop连不上网解决:

重启虚拟机即可。


二、Xshell6连接

连接成功!

三、启动服务

重新编辑本机的hosts文件

sudu vim /etc/hosts

按insert进入编辑模式

完成修改

按esc键,退出

:wq 保存

查看是否修改成功:cat /etc/hosts

cd ~ 回车

ls

pwd 当前目录

cd … 退回上一级目录

cd app

ls

cd hadoop-2.6.0-cdh5.7.0/

ls

cd sbin

ls

./start-dfs.sh

连接成功

jps 查看进程

测试连接

用浏览器访问:http://192.168.234.128:50070/

出现这个页面就表示成功

4、hdfs的shell操作

hadoop fs 设置环境变量

相关的命令:

hadoop fs -ls /

touch taigongyuan.txt 在本机创建一个文件

vim taigongyuan.txt 写文件内容

cat taigongyuan.txt 查看文件内容

hadoop fs -mkdir -p /hadooptaiyuan/test 在hadoop创建一个文件夹

将本地创建的文件传入Hadoop中

hadoop fs -put taigongyuan.txt /hadooptaiyuan/test

查看hadoop中的文件中的内容

hadoop fs -cat /hadooptaiyuan/test/taigongyuan.txt

将hadoop的文件的下载到本地,并且命名为haha.txt

hadoop fs -get /hadooptaiyuan/test/taigongyuan.txt haha.txt

将文件移动一个位置

hadoop fs -mv /hadooptaiyuan/test/taigongyuan.txt /user 我这里是移动到user目录下面

删除一个文件

hadoop fs -rm /user/taigongyuan.txt

五、使用java去操纵hdfs

首先新建一个maven项目

添加maven依赖

<dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>2.6.0</version>
</dependency>

新建测试类

private Configuration configuration = null;
private static final String HDFS_PATH = "hdfs://192.168.234.128:8020";/*** java连接hdfs首先需要建立一个连接*/
@Before
public void setUp() {System.out.println("开启连接");configuration = new Configuration();
}/*** 释放资源*/
@After
public void tearDown() {System.out.println("关闭连接");configuration = null;
}

1、新建一个文件夹

 /*** 新建文件夹*/@Testpublic void mkdir() {FileSystem fileSystem = null;try {fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, "hadoop");fileSystem.mkdirs(new Path("/liufeng666/test1"));} catch (Exception e) {e.printStackTrace();} finally {if (fileSystem != null) {try {fileSystem.close();} catch (IOException e) {e.printStackTrace();}}}}

2、创建文件

@Test
public void create() {FileSystem fileSystem = null;FSDataOutputStream fsDataOutputStream = null;try {fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, "hadoop");fsDataOutputStream = fileSystem.create(new Path("/liufeng666/test1/hello.txt"));fsDataOutputStream.write("hello liufeng jisuanji".getBytes());fsDataOutputStream.flush();} catch (Exception e) {e.printStackTrace();} finally {if (fileSystem != null) {try {fileSystem.close();} catch (IOException e) {e.printStackTrace();}}if (fsDataOutputStream != null) {try {fsDataOutputStream.close();} catch (IOException e) {e.printStackTrace();}}}
}

3、重命名文件

/*** 重命名文件*/
@Test
public void rename() {FileSystem fileSystem = null;Path oldPath = new Path("/liufeng666/test1/hello.txt");Path newPath = new Path("/liufeng666/test1/hehe.txt");try {fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, "hadoop");fileSystem.rename(oldPath, newPath);} catch (Exception e) {e.printStackTrace();} finally {if (fileSystem != null) {try {fileSystem.close();} catch (IOException e) {e.printStackTrace();}}}
}

4、查看文件

/*** 查看文件*/
@Test
public void cat() {FileSystem fileSystem = null;Path path = new Path("/liufeng666/test1/hehe.txt");try {fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, "hadoop");FSDataInputStream is = fileSystem.open(path);IOUtils.copyBytes(is, System.out, 1024);is.close();} catch (Exception e) {e.printStackTrace();} finally {if (fileSystem != null) {try {fileSystem.close();} catch (IOException e) {e.printStackTrace();}}}
}

5、上传文件

/*** 上传文件*/
@Test
public void uplode() {FileSystem fileSystem = null;Path localPath = new Path("src/jiachenxia.pdf");Path path = new Path("/liufeng666/test1");try {fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, "hadoop");fileSystem.copyFromLocalFile(localPath, path);} catch (Exception e) {e.printStackTrace();} finally {if (fileSystem != null) {try {fileSystem.close();} catch (IOException e) {e.printStackTrace();}}}
}

6、下载文件

/*** 下载文件*/
@Test
public void download() {FileSystem fileSystem = null;Path hdfspath = new Path("/liufeng666/test1/jiachenxia.pdf");Path localPath = new Path("src/download/jiachenxia.pdf");try {fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, "hadoop");fileSystem.copyToLocalFile(false, hdfspath, localPath, true);} catch (Exception e) {e.printStackTrace();} finally {if (fileSystem != null) {try {fileSystem.close();} catch (IOException e) {e.printStackTrace();}}}
}

六、可视化yarn和MapReauce

词频统计案例

1、先停止hadoop

./stop-dfs.sh

2、启动所有

./start-all.sh

3、输入访问8088端口

实现代码

 /*** map阶段*/public static class MyMapper extends Mapper<LongWritable, Text, Text, LongWritable> {LongWritable one = new LongWritable(1);@Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {// 分String line = value.toString();// 拆分String[] s = line.split(" ");for (String word : s) {// 输出context.write(new Text(word), one);}}}
/*** reduce阶段*/public static class MyReduce extends Reducer<Text, LongWritable, Text, LongWritable> {@Overrideprotected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {long sum = 0;// 合并统计for (LongWritable value : values) {sum += value.get();}context.write(key, new LongWritable(sum));}}
 public static void main(String[] args) throws Exception {Configuration configuration = new Configuration();Job job = Job.getInstance(configuration, "wordcount");job.setJarByClass(WordCountApp.class);FileInputFormat.setInputPaths(job, new Path(args[0]));job.setMapperClass(MyMapper.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(LongWritable.class);job.setReducerClass(MyReduce.class);Path outPath = new Path(args[1]);FileSystem fileSystem = FileSystem.get(configuration);if (fileSystem.exists(outPath)) {// 删除文件fileSystem.delete(outPath, true);System.out.println("输出路径存在,已经被我删除了");}FileOutputFormat.setOutputPath(job, outPath);// 控制台输出详细的信息System.out.println(job.waitForCompletion(true) ? 0 : 1);}

打包

放进hadoop中

运行jar

hadoop jar Desktop/bigdate-1.0-SNAPSHOT.jar neusoft.WordCountApp hdfs://hadoop000:8020/liufeng.txt hdfs://hadoop000:8020/output/wc

查看文件内容

hadoop fs -cat /output/wc/part-r-00000

七、ECharts

首先创建一个html

引入ECharts的js文件

<script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>

为ECharts准备一个具备大小(宽高)的Dom

<div id="main" style="width: 600px;height:400px;"></div>

柱状图

<script>var main = document.getElementById("main");var myChart = echarts.init(main);// 绘制图表var option = myChart.setOption({title: {text: 'ECharts '},tooltip: {},xAxis: {data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']},yAxis: {},series: [{name: '销量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]});myChart.setOption(option);
</script>

饼图

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script><!-- 引入主题 --><script src="https://www.runoob.com/static/js/wonderland.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script>var main = document.getElementById("main");var myChart = echarts.init(main, 'dark');// 绘制图表var option = myChart.setOption({title: {text: '饼图'},// 工具箱show: true,legend: {orient: 'vertical',left: 'right',data: ['视频广告', '联盟广告', '邮件营销', '直接访问', '搜索引擎']},tooltip: {trigger: 'item',formatter: "{a} <br/>{b} : {c} ({d}%)"},series: [{name: '访问来源',type: 'pie',    // 设置图表类型为饼图radius: '75%',  // 饼图的半径,外半径为可视区尺寸(容器高宽中较小一项)的 55% 长度。data: [          // 数据数组,name 为数据项名称,value 为数据项值{value: 235, name: '视频广告'},{value: 274, name: '联盟广告'},{value: 310, name: '邮件营销'},{value: 335, name: '直接访问'},{value: 400, name: '搜索引擎'}]}]});
</script>
</body>
</html>

hadoop大数据实践_刘锋的博客相关推荐

  1. MySQL_DQL数据查询语言_刘锋的博客

    文章目录 DQL数据查询语言 进阶一:基础查询 进阶二:条件查询 进阶三:排序查询 进阶四:常见函数 一.单行函数 二.分组函数(聚合函数) 进阶五.分组查询 进阶六:连接查询(多表查询) sql92 ...

  2. MySQL_TCL事务控制语言_刘锋的博客

    文章目录 TCL事务控制语言 一.事务的属性(ACIB) 原子性 一致性 隔离性 持久性 二.事务的创建 隐式的事务 显式的事务 三.事务的隔离级别 脏读: 不可重复度: 幻读: 四.delete和t ...

  3. MySQL_DDL数据定义语言_刘锋的博客

    文章目录 DDL数据定义语言 一.库的管理 创建 修改 删除 二.表的管理 创建 语法 修改 1.修改列名 2.修改列的列的类型或者约束 3.添加新列 4.删除列 5.修改表名 删除 复制 三.常见的 ...

  4. jsp中Ajax请求发送PUT、DELETE请求的方式_刘锋的博客

    jsp中Ajax请求发送PUT.DELETE请求的方式 方式一 首先配置pom.xml ,添加过滤器 <filter><filter-name>hiddenHttpMethod ...

  5. MySQL视图_刘锋的博客

    文章目录 视图 创建视图 视图修改 视图的删除 查看视图 视图的更新 对比视图和表 视图 就是一个虚拟的表,有行有列 虚拟表是5.1之后出现的新特性,是通过普通表动态生成的数据,具有临时性的特点. 创 ...

  6. Java线程池_刘锋的博客

    文章目录 线程和线程池的区别 线程池的七大参数 线程和线程池的区别 线程的join方法: 目的是使子线程去等待主线程执行完成的,具体的应用场景是,当主线程要使用子线程的计算结果的时候,但是子线程的运算 ...

  7. MySQL_DML数据操纵语言_刘锋的博客

    文章目录 DML数据操纵语言 插入:insert 一.经典的插入 语法 二.特殊的插入 语法 两种插入方式的区别 修改:updata 修改单表的记录 语法 修改多表的记录(级联更新) 语法 删除:de ...

  8. Mybatis逆向工程_刘锋的博客

    Mybatis逆向工程 说明文档网址 : http://mybatis.org/generator/ maven依赖导入 <!--mybatis生成器--><dependency&g ...

  9. SSM框架整合_刘锋的博客

    文章目录 SSM整合 一.MyBatis层 1.首先创建一个数据库 2.搭建环境 创建一个maven项目 添加依赖 静态资源 idea连接数据库 构造项目结构目录 mybatis-config.xml ...

最新文章

  1. 编程实现灰度处理函数
  2. JAVA EXCEL API详解
  3. 关于LBS坐标系与精度的问题
  4. Agilent RF fundamentals (4)- Impedance match and distortions
  5. LeetCode 12/13 罗马数字与整型互转(哈希,贪心)
  6. Microsoft SharePoint Server 2010 简体中文版及相关资源
  7. python批量制作ppt_实例25_批量生成PPT版荣誉证书
  8. PaaS建设有什么意义,能够给企业带来哪些价值?
  9. python并发编程gevent模块以及猴子补丁学习
  10. 计算机专硕都是数二英二吗,【专硕初试】大改革?英二、数二都不考了?
  11. 洛谷P3366【模板】最小生成树-克鲁斯卡尔Kruskal算法详解附赠习题
  12. 如何在所有流媒体服务中搜索电影或电视节目
  13. 远程办公实践丨需重视以人为本的员工激励设计
  14. vsc编辑器设置背景图
  15. SAP云集成 SAP Integration Suite启用过程,踩坑记
  16. ios 绕过 id 锁
  17. java后台图片大小压缩
  18. 个人简介网页设计作业 静态HTML个人介绍网页作业 DW个人网站模板下载 WEB静态大学生简单网页 个人网页作品代码 个人网页制作 学生个人网页
  19. ⭐算法入门⭐《堆》中等01 —— LeetCode 面试题 17.09. 第 k 个数
  20. 基于Java+Springboot+Vue+elememt美食论坛平台设计实现

热门文章

  1. Java:输入输出转换流
  2. 使用JEECG框架项目在linux 系统下启动及运行缓慢的问题追踪和解决办法
  3. AD无法打开 报错ad please wait a moment:解决方法
  4. Python本地录屏和系统声音
  5. (附源码)计算机毕业设计ssm高校运动会管理系统
  6. 全面详细的面试指南:数据结构与算法篇 (附答案)
  7. 【VMware vSAN 7.0】2.5 许可证要求 —我们有软硬件解决方案
  8. 常见射频同轴连接器类型
  9. 解决微信开发者工具最新版本的调试器中不显示AppData和Storage选项问题
  10. 公告栏自动滚动例子代码