设备编号 | 主机名 | 系统 | IP地址 | 准备文件 |
---|---|---|---|---|
1 | master | centos7.2 | 10.0.0.10 | ----------------hadoop3.0.0.tar.gz -------------------------jdk-8u161-linux-x64.tar.gz |
2 | node1 | centos7.2 | 10.0.0.11 | |
3 | node2 | centos7.2 | 10.0.0.12 |
软件包下载地址:
链接: https://pan.baidu.com/s/1dvf4o8i9J02fmUu3SMRyDw 提取码: 3dk3
[root@master ~]# vi /etc/hosts
添加如下内容
10.0.0.10 master
10.0.0.11 node1
10.0.0.12 node2
ssh-keygen
[root@master ~]# ssh-keygen
[root@master ~]# ssh-copy-id master
[root@master ~]# ssh-copy-id node1
[root@master ~]# ssh-copy-id node2
[root@master ~]# ssh master
[root@master ~]# ssh node1
[root@master ~]# ssh node2
#systemctl stop firewalld;systemctl disable firewalld;setenforce 0
mkdir /opt/bigdata
[root@master ~]# mkdir /opt/bigdata
[root@master ~]# mv hadoop-3.0.0.tar.gz jdk-8u161-linux-x64.tar.gz /opt/bigdata/
[root@master ~]#
[root@master bigdata]# tar -zxf hadoop-3.0.0.tar.gz -C /opt/bigdata/
[root@master bigdata]# tar -zxf jdk-8u161-linux-x64.tar.gz -C /opt/bigdata/
[root@master bigdata]# ll
total 484528
drwxr-xr-x 9 centos centos 139 Dec 8 2017 hadoop-3.0.0
-rw-r--r-- 1 root root 306392917 Mar 11 08:50 hadoop-3.0.0.tar.gz
drwxr-xr-x 8 10 143 4096 Dec 20 2017 jdk1.8.0_161
-rw-r--r-- 1 root root 189756259 Mar 11 08:50 jdk-8u161-linux-x64.tar.gz
#vi /etc/profile添加如下内容
export JAVA_HOME=/opt/bigdata/jdk1.8.0_161
export PATH=$JAVA_HOME/bin:$PATH
export HADOOP_HOME=/opt/bigdata/hadoop-3.0.0
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
source /etc/profile
# hadoop version
# java -version
[root@master ~]# cd /opt/bigdata/hadoop-3.0.0/etc/hadoop
[root@master hadoop]# pwd
/opt/bigdata/hadoop-3.0.0/etc/hadoop
[root@master hadoop]# ls
[root@master hadoop]# vi hadoop-env.sh
移动到第54行,删除前面的 '#' 和空格,并修改成如下内容
export JAVA_HOME=/opt/bigdata/jdk1.8.0_161
[root@master hadoop]# vi core-site.xml
fs.default.name</name>
hdfs://master:9000</value>
</property>
hadoop.temp.dir</name>
/opt/bigdata/hadoop-3.0.0/tmp</value>
</property>
[root@master hadoop]# vi hdfs-site.xml
dfs.replication</name>
2</value>
</property>
dfs.namenode.name.dir</name>
/opt/bigdata/hadoop-3.0.0/hdfs/name</value>
</property>
dfs.datanode.data.dir</name>
/opt/bigdata/hadoop-3.0.0/hdfs/data</value>
</property>
dfs.namenode.secondary.http-address</name>
node1:9001</value>
</property>
dfs.http.address</name>
0.0.0.0:50070</value>
</property>
[root@master hadoop]# vi mapred-site.xml
mapreduce.framework.name</name>
yarn</value>
</property>
mapred.job.tracker.http.address</name>
0.0.0.0:50030</value>
</property>
mapred.task.tracker.http.address</name>
0.0.0.0:50060</value>
</property>
mapreduce.applicaton.classpath</name>
/opt/bigdata/hadoop-3.0.0/etc/hadoop,
/opt/bigdata/hadoop-3.0.0/share/hadoop/common/*,
/opt/bigdata/hadoop-3.0.0/share/hadoop/common/lib/*,
/opt/bigdata/hadoop-3.0.0/share/hadoop/hdfs/*,
/opt/bigdata/hadoop-3.0.0/share/hadoop/hdfs/lib/*
/opt/bigdata/hadoop-3.0.0/share/hadoop/mapreduce/*,
/opt/bigdata/hadoop-3.0.0/share/hadoop/yarn/*,
/opt/bigdata/hadoop-3.0.0/share/hadoop/yarn/lib/*
</value>
</property>
[root@master hadoop]# vi yarn-site.xml
yarn.resourcemanager.hostname</name>
master</value>
</property>
yarn.resourcemanager.webapp.address</name>
master:8099</value>
</property>
yarn.application.classpath</name>
/opt/bigdata/hadoop-3.0.0/etc/hadoop:/opt/bigdata/hadoop-3.0.0/share/hadoop/common/lib/*:/opt/bigdata/hadoop-3.0.0/share/hadoop/common/*:/opt/bigdata/hadoop-3.0.0/share/hadoop/hdfs:/opt/bigdata/hadoop-3.0.0/share/hadoop/hdfs/lib/*:/opt/bigdata/hadoop-3.0.0/share/hadoop/hdfs/*:/opt/bigdata/hadoop-3.0.0/share/hadoop/mapreduce/*:/opt/bigdata/hadoop-3.0.0/share/hadoop/yarn:/opt/bigdata/hadoop-3.0.0/share/hadoop/yarn/lib/*:/opt/bigdata/hadoop-3.0.0/share/hadoop/yarn/*
</value>
</property>
yarn.nodemanager.vmem-check-enabled</name>
false</value>
</property>
yarn.nodemanager.aux-services</name>
mapreduce_shuffle</value>
</property>
yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
[root@master hadoop]# vi workers
添加node1 node2
[root@master ~]# vi /opt/bigdata/hadoop-3.0.0/sbin/start-dfs.sh
[root@master ~]# vi /opt/bigdata/hadoop-3.0.0/sbin/stop-dfs.sh
HDFS_DATANODE_USER=root
HADOOP_SECURE_DN_USER=hdfs
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root
编辑配置文件,都添加如下内容
[root@master ~]# vi /opt/bigdata/hadoop-3.0.0/sbin/start-yarn.sh
[root@master ~]# vi /opt/bigdata/hadoop-3.0.0/sbin/stop-yarn.sh
YARN_RESOURCEMANAGER_USER=root
HADOOP_SECURE_DN_USER=yarn
YARN_NODEMANAGER_USER=root
[root@node1 ~]# mkdir /opt/bigdata
[root@node2 ~]# mkdir /opt/bigdata
[root@master ~]# scp -r /opt/bigdata/hadoop-3.0.0 node1:/opt/bigdata
[root@master ~]# scp -r /opt/bigdata/hadoop-3.0.0 node2:/opt/bigdata
[root@master ~]# scp -r /opt/bigdata/jdk1.8.0_161/ node1:/opt/bigdata/
[root@master ~]# scp -r /opt/bigdata/jdk1.8.0_161/ node2:/opt/bigdata/
[root@master ~]# scp /etc/profile node1:/etc/
[root@master ~]# scp /etc/profile node2:/etc/
[root@node2 ~]# source /etc/profile
[root@node2 ~]# java -version
[root@node2 ~]# hadoop version
[root@master ~]# hadoop namenode -format
[root@master ~]# start-all.sh
[root@master ~]# jps
[root@node1 ~]# jps
[root@node2 ~]# jps
网页端访问master节点ip地址
http://Master_IP:50072
例:
http://10.0.0.10:50070
网页端查看HDFS文件系统
[root@master ~]# vi mapper.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import sys
for line in sys.stdin:
line = line.strip()
words = line.split()
for word in words:
print '%s\t%s' % (word, 1)
[root@master ~]# vi reducer.py
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
#from operator import itemgetter
import sys
current_word = None
current_count = 0
word = None
for line in sys.stdin:
line = line.strip()
word, count = line.split('\t', 1)
try:
count = int(count)
except ValueError:
continue
if current_word == word:
current_count += count
else:
if current_word:
print '%s\t%s' % (current_word, current_count)
current_count = count
current_word = word
if current_word == word:
print '%s\t%s' % (current_word, current_count)
[root@master ~]# chmod a+x mapper.py
[root@master ~]# chmod a+x reducer.py
[root@master ~]# echo “hello world hell hi word” | python mapper.py |sort|python reducer.py
yarn.nodemanager.aux-services</name>
mapreduce_shuffle</value>
</property>
yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
[root@master ~]# vi mapreduce.sh
hadoop jar /opt/bigdata/hadoop-3.0.0/share/hadoop/tools/lib/hadoop-*streaming*.jar -mapper "python mapper.py" -reducer "python reducer.py" -input /user_test/
data.txt -output /output_dir -file /opt/bigdata/mapreduce/mapper.py -file /opt/bigdata/mapreduce/reducer.py
#streaming可以执行任意语言写的mapper,reducer程序
-mapper "python mapper.py" #执行mapper程序
-reducer "python reducer.py" #执行reducer程序
-input /user_test/data.txt -output /output_dir #导入文件及导出文件地址
-file /opt/bigdata/mapreduce/mapper.py #mapper程序路径
-file /opt/bigdata/mapreduce/reducer.py #reducer程序路径
[root@master ~]# mkdir /opt/bigdata/mapreduce
[root@master ~]# mv mapper.py reducer.py /opt/bigdata/mapreduce/
[root@master ~]# ls /opt/bigdata/mapreduce/
[root@master ~]# vi data.txt
java
java
python
ruby
ruby
mongo
ruby
java
python
java
python
python
java
python
python
java
python
python
java
java
[root@master ~]# hdfs dfs -mkdir /user_test
[root@master ~]# hdfs dfs -chmod -R 777 /user_test ##给目录添加权限
[root@master ~]# hdfs dfs -put /root/data.txt /user_test
[root@master ~]# hdfs dfs -ls /user_test
[root@master ~]# hdfs dfs -ls /
[root@master ~]# source mapreduce.sh
[root@master ~]# hdfs dfs -ls /output_dir
[root@master ~]# hdfs dfs -cat /output_dir/part-00000
也可以在Web端查看
http://Master_I:50070
点击下载会提示网页无法访问,请将node1或者node2替换成相应的IP地址即可
pip install wordcloud(执行下载woedcloud)
pip install matplotlib(执行下载matplotlib)
# -*-coding:UTF-8 -*-
# 导入相关的库
import matplotlib #导入matplotlib
matplotlib.use('Agg')
from os import path
import matplotlib.pyplot as plt
from wordcloud import WordCloud #从wordcloud导入WordCloud
# 获取当前文件路径
# __file__ 为当前文件, 在ide中运行此行会报错,可改为
# d = path.dirname('.')
d = path.dirname('.') ##选择文件路径
# 读取整个文件
text = open(path.join(d, 'E:\part-00000')).read() #打开文件并赋值给变量text
#wordcloud = WordCloud().generate(text)
wc = WordCloud().generate(text)
wc.to_file('Word Cloud.png') #命名生成的图片
# 绘图
plt.imshow(wc)
plt.axis("off")