为媳妇写的极短时间入门hadoop的教程。(每一个阶段的时间都会在30s内结束) 本周就是使用python flask模仿一个简单的上传页面。
- 快速安装hadoop的套件
- 利用命令行创建、上传、下载文件
- 使用python上传下载文件
因为实际环境都使用一键安装。这里只提供单机节点的配置:
- 安装Oracle jdk
- 下载hadoop
- 配置hadoop
- 系统的一些必要配置(ssh免密、关掉防火墙和selinux)
在root下运行脚本 sh ./oneday/env_config.sh
- 在/etc/hosts下增加一个master对应本机IP
- 在hadoop目录下,修改etc/hadoop/core-site.xml文件
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://master:9000</value>
</property>
</configuration>
修改hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
修改mapred-site.xml文件
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
</configuration>
- 运行hadoop
sbin/start-dfs.sh
- 新建一个1.txt文件
- hdfs新建文件夹命令
- bin/hdfs dfs -mkdir /test
- 上传、下载、浏览
- bin/hdfs dfs -put 1.txt /test
- bin/hdfs dfs -get /test/1.txt
- bin/hdfs dfs -cat /test/1.txt
坑: 为什么会无法上传文件?
- pip install hdfs
- 运行 python ./oneday/simple_ops.py
python创建、浏览、查看、删除、上传等各类操作
文件名称为 [attribute]#[time].txt 如 test#2018-12-12-10-34.txt 需要使用python提取其中的时间
import re
data = 'test#2018-12-12-10-34.txt'
mat = re.search(r'(\d{4})-(\d{1,2})-(\d{1,2})-(\d{1,2})-(\d{1,2})', data)