Hadoop是一种分析和处理海量数据的软件平台,基于java语言开发,可以提供一个分布式基础架构。
特点:高可靠性、高扩展性、高效性、高容错性、低成本
本案例要求安装单机模式Hadoop:
热词分析:
最低配置:2cpu,2G内存,10G硬盘
虚拟机IP:192.168.1.50 hadoop1
安装部署 hadoop
数据分析,查找出现次数最多的单词
1)配置主机名为hadoop1,ip为192.168.1.50,配置yum源(系统源)
2)安装java环境
[root@hadoop1 ~]# yum -y install java-1.8.0-openjdk-devel java-1.8.0-openjdk-devel
[root@hadoop1 ~]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
[root@hadoop1 ~]# jps
1235 Jps
3)安装hadoop
[root@hadoop1 ~]# cd hadoop/
[root@hadoop1 hadoop]# ls
hadoop-2.7.7.tar.gz kafka_2.12-2.1.0.tgz zookeeper-3.4.13.tar.gz
[root@hadoop1 hadoop]# tar -xf hadoop-2.7.7.tar.gz
[root@hadoop1 hadoop]# mv hadoop-2.7.7 /usr/local/hadoop
[root@hadoop1 hadoop]# chown -R 0.0 /usr/local/hadoop # 为了安全 修改所有者和所属组
[root@hadoop1 hadoop]# vim /etc/hosts
192.168.1.50 hadoop1
[root@hadoop1 hadoop]# vim /usr/local/hadoop/etc/hadoop-env.sh
25: export JAVA_HOME="/usr" # java安装路径
33: export HADOOP_CONF_DIR="/usr/local/hadoop/etc/hadoop" # hadoop配置文件命令
[root@hadoop1 hadoop]# /usr/local/hadoop/bin/hadoop version
[root@hadoop1 ~]# cd /usr/local/hadoop/
[root@hadoop1 hadoop]# ./bin/hadoop # 运行
5)词频统计
[root@hadoop1 hadoop]# mkdir /usr/local/hadoop/input
[root@hadoop1 hadoop]# ls
bin etc include lib libexec LICENSE.txt NOTICE.txt input README.txt sbin share
[root@hadoop1 hadoop]# cp *.txt /usr/local/hadoop/input
[root@hadoop1 hadoop]# ./bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.7.jar wordcount input output //wordcount为参数 统计input这个文件夹,存到output这个文件里面(这个文件不能存在,要是存在会报错,是为了防止数据覆盖)
[root@hadoop1 hadoop]# cat output/part-r-00000 //查看
HDFS是Hadoop体系中数据存储管理的基础,是一个高度容错的系统,用于在低成本的通用硬件上运行。
HDFS角色和概念:
准备集群环境
最低配置:2CPU,2G内存,10G硬盘
虚拟机IP:
192.168.1.50 hadoop1
192.168.1.51 node-0001
192.168.1.52 node-0002
192.168.1.53 node-0003
要求:禁用selinux、禁用firewalld (所有主机)
安装java-1.8.0-openjdk-devel,并配置 /etc/hosts(所有主机)
设置hadoop1 免密登录其他主机、并不用输入 yes
使所有节点能够ping通,配置SSH信任关系
节点验证
1)编辑/etc/hosts(四台主机同样操作,以hadoop1为例)
[root@hadoop1 ~]# vim /etc/hosts
192.168.1.50 hadoop1
192.168.1.51 node-0001
192.168.1.52 node-0002
192.168.1.53 node-0003
2)安装java环境,在node-0001,node-0002,node-0003上面操作(以node-0001为例)
[root@node-0001 ~]# yum -y install java-1.8.0-openjdk-devel
3)布置SSH信任关系
[root@hadoop1 ~]# vim /etc/ssh/ssh_config //第一次登陆不需要输入yes
Host *
GSSAPIAuthentication yes
StrictHostKeyChecking no
[root@hadoop1 .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Ucl8OCezw92aArY5+zPtOrJ9ol1ojRE3EAZ1mgndYQM root@hadoop1
The key's randomart image is:
+---[RSA 2048]----+
| o*E*=. |
| +XB+. |
| ..=Oo. |
| o.+o... |
| .S+.. o |
| + .=o |
| o+oo |
| o+=.o |
| o==O. |
+----[SHA256]-----+
[root@hadoop1 .ssh]# for i in hadoop1 node-{0001...0003};do ssh-copy-id -i /root/.ssh/id_ras.pub ${i} done
//部署公钥给hadoop1,node-0001,node-0002,node-0003
4)测试信任关系
[root@hadoop1 .ssh]# ssh node-0001
Last login: Fri Sep 7 16:52:00 2018 from 192.168.1.60
[root@node-0001 ~]# exit
logout
Connection to node-0001 closed.
[root@hadoop1 .ssh]# ssh node-0002
Last login: Fri Sep 7 16:52:05 2018 from 192.168.1.60
[root@node-0002 ~]# exit
logout
Connection to node-0002 closed.
[root@hadoop1 .ssh]# ssh node-0003
[root@hadoop1 ~]# cd /usr/local/hadoop/etc/hadoop
[root@hadoop1 hadoop]# vim slaves
node-0001
node-0002
node-0003
2)hadoop的核心配置文件core-site
[root@hadoop1 hadoop]# vim core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop1:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/var/hadoop</value>
</property>
</configuration>
[root@hadoop1 hadoop]# mkdir /var/hadoop //hadoop的数据根目录
3)配置hdfs-site文件
[root@hadoop1 hadoop]# vim hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.http-address</name>
<value>hadoop1:50070</value> # 主机名:端口号 查手册
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>hadoop1:50090</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value> # 副本数量
</property>
</configuration>
启动集群(以下操作仅在hadoop1上执行)
[root@hadoop1 ~]# for i in node-{0001..0001};do rsync -aXSH --delete /usr/local/hadoop ${i}:/usr/local/ done
[root@hadoop1 ~]# mkdir /var/hadoop
[root@hadoop1 ~]# /usr/local/hadoop/bin/hdfs namenode -format
[root@hadoop1 ~]# /usr/local/hadoop/sbin/start-dfs.sh
验证集群配置
[root@hadoop1 ~]# for i in hadoop1 node-{0001..0003};do echo ${i}; ssh ${i} jps; echo -e "\n"; done
[root@hadoop1 ~]# /usr/local/hadoop/bin/hdfs dfsadmin -report
日志文件夹在系统启动时会被自动创建
/usr/local/hadoop/logs
日志名称
1)配置mapred-site(hadoop1上面操作)
[root@hadoop1 ~]# cd /usr/local/hadoop/etc/hadoop/
[root@hadoop1 ~]# mv mapred-site.xml.template mapred-site.xml
[root@hadoop1 ~]# vim mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
在之前创建的 4 台虚拟机上部署 Yarn
在虚拟机上安装部署 Yarn
hadoop1 部署 resourcemanager
node(1,2,3) 部署 nodemanager
在之前创建的 4 台虚拟机上部署 Yarn
1)配置yarn-site(hadoop1上面操作)
[root@hadoop1 hadoop]# vim yarn-site.xml
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>hadoop1</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
2)同步配置(hadoop1上面操作)
[root@hadoop1 ~]# for i in node-{0001..0003}; do
rsync -axXSH --delete /usr/local/hadoop/etc ${i}:/usr/local/hadoop/
done
[root@hadoop1 ~]# /usr/local/hadoop/sbin/start-yarn.sh
3)验证配置(hadoop1上面操作)
[root@hadoop1 ~]# for i in hadoop1 node-{0001..0003}; do
echo ${i};
ssh ${i} jps;
echo -e "\n";
done
[root@hadoop1 ~]# /usr/local/hadoop/bin/yarn node -list
4)web访问hadoop
namenode: http://hadoop1:50070
firefox http://hadoop1:8088 (resourcemanager)
firefox http://node-0001:8042 (nodemanager)