安装镜像:centos6.7
jdk:1.8
1.CDH的下载地址:
http://archive.cloudera.com/cdh5/cdh/5/
HDFS:文件是以多副本的形式存放的
2.hadoop的官网
hadoop.apache.org
HDFS架构:
1.设计模式
一个master(NameNode)带N个slaves(DataNodes)
一个文件会被拆分成多个block
blocksize:128M
130M==>2个block:128M和2M
HDFS/YARN/HBASE
NameNode作用:
1)负责客户端请求的响应
2)负责元数据(文件的名称、副本系数、Block存放的DataNode)的管理
DateNode作用:
1)存储用户的文件对应的数据块(Block)
2)要定期向NameNode发送心跳信息,汇报本身及其所有的block信息、健康状况
A typical deployment has a dedicated machine that runs only the NameNode software。Each of the other machines in the cluster runs one instance of the DataNode software。
经典的部署架构:
一个机器单独部署一个NameNode,其他多台机器分别部署一个DataNode,也就是说NameNode和DataNode部署在不同的机器上。
The architecture does not preclude running multiple DataNodes on the same machine but in a real deployment that is rarely the case.
replication factor:副本系数 或者 副本因子
All blocks in a file except the last block are the same size。
一个文件中所有的blocks除了最后一个,其他的所有block的大小都是一样的
橙色代表:调用者程序
绿色代表:block副本
Hadoop的安装伪分布式
[if !supportLists]1) [endif]jdk安装
A.解压jdk的gz安装包
B.添加环境变量vi ~/bash_profile 添加的内容为
export JAVA_HOME=/usr/java/jdk1.8.0_181
export PATH=$JAVA_HOME/bin:$PATH
[if !supportLists]C. [endif]是环境变量生效
source ~/bash_profile
[if !supportLists]2) [endif]安装ssh
sudo yum install ssh
[if !supportLists]3) [endif]linux免密设置
ssh-keygen -t rsa
[if !supportLists]4) [endif]cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
[if !supportLists]5) [endif]下载并解压hadoop
A.去http://archive.cloudera.com/cdh5/cdh/5/网站下载tar.gz的安装包
B.解压 tar -xvf hadoop-2.6.0-cdh5.7.0.tar.gz
6) hadoop配置文件的修改(hadoop_home/etc/hadoop)
hadoop-env.sh
添加exprot JAVA_HOME=/usr/java/jdk1.8.0_181
以下为伪集群配置:
Use the following:
etc/hadoop/core-site.xml:
fs.defaultFS
hdfs://固定的机器ip或者别名(不要用localhost):9000
为了避免电脑重启把临时目录删除掉,所以要改掉默认配置
hadoop.tmp.dir
/usr/hadoop/tmp//这是我们自己创建存放数据的临时目录
etc/hadoop/hdfs-site.xml:
dfs.replication
1 //副本个数,由于我们只有一台机器,所以这里写1
如果要配置多节点集群,需要再配置一个文件,把集群的机器名字写入该文件,此文件就是
Hadoop下的/etc/hadoop/slaves
[if !supportLists]6) [endif]启动hdfs
在/usr/hadoop/hadoop-2.6.0-cdh5.7.0/bin下执行
A.格式化文件系统(仅第一次执行即可,不要重复执行):hdfs namenode -format
B.启动hdfs
/usr/hadoop/hadoop-2.6.0-cdh5.7.0/sbin目录下执行
start-dfs.sh
验证启动是否成功:
A.第一种验证方式
用linux查看进程的命令jps
48368 DataNode
48661 Jps
48554 SecondaryNameNode
48285 NameNode
[if !supportLists]B. [endif]第二种验证方式:
浏览器访问:
机器ip:50070就可以看到一个页面
如果访问不了,就需要配置防火墙,把50070端口打开
编辑防火墙:
vi /etc/sysconfig/iptables
增加规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
保存退出后#重启iptables服务,新配置即可保存生效service iptables restart
7)停止hdfs
/usr/hadoop/hadoop-2.6.0-cdh5.7.0/sbin目录下执行
stop-dfs.sh
[if !supportLists]8)[endif]查看端口被哪些pid(进程)占用了
netstat -apn|grep 50070
利用hadoop的shell操作文件
查看hadoop所有命令的命令:hdfs dsf
执行hadoop的命令hadoop fs -命令
如果虚拟机安装hadoop的话,需要关闭防火墙
service iptables stop
网友评论