说明:
任务:搭建Hadoop伪分布式版本。
目的:快速搭建一个学习环境,跳过这一环境,快速进入状态,使用Hadoop一些组件做些任务
没有选择2.7,觉得bug比较多,不稳定。
选择伪分布式简单快速
环境:
Win 7 64 8G 内存 ,4核
VM 12,1 虚拟机 3G 内存
ubuntu 4.4.0 x86-64
Hadoop 2.6.4
JDK 1.7.0_80
1. 虚拟机Linux准备
安装虚拟机,(可以选择克隆方式),网络选择NAT。
创建用户hadoop, 配置 sudo 命令,文件设置 (待细化:Baidu)
后续所有操作以hadoop用户进行,没有权限就 sudo
1.1 网络IP 配置(偷懒,采用默认分配, 如果多节点要设置, 待细化)
[email protected]:~$ ifconfig ens33 Link encap:Ethernet HWaddr 00:0c:29:2e:0f:82 inet addr:192.168.249.144 Bcast:192.168.249.255 Mask:255.255.255.0 inet6 addr: fe80::400:dd35:2b5d:4dba/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:145870 errors:0 dropped:0 overruns:0 frame:0 TX packets:12833 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:209812987 (209.8 MB) TX bytes:1827590 (1.8 MB)
1.2 主机名设置
修改以下三个地方:
a
[email protected]:~$ sudo vi /etc/hostname [email protected]:~$ more /etc/hostname ssmaster
b
[email protected]:~$ hostname ubuntu [email protected]:~$ sudo hostname ssmaster [email protected]:~$ hostname ssmaster
c
[email protected]:~$ sudo vi /etc/hosts
修改后:
127.0.0.1 localhost
#127.0.1.1 ubuntu
192.168.249.144 ssmaster
2. 安装JDK
配置环境变量
vi /etc/profile 在末尾添加保存
export JAVA_HOME=/home/szb/hadoop/jdk1.7.0_80 export JRE_HOME=$JAVA_HOME/jre export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=./:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
执行命令生效 source /etc/profile
如下安装成功
[email protected]:~$ java -version java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
3. SSH 设置
先测试 ssh ssmaster (当前主机名,前面设置)
需要密码表示还没设置。
执行以下命令,一路回车。
[email protected]:~$ cd ~ [email protected]:~$ ssh-keygen -t rsa [email protected]:~/.ssh$ cp id_rsa.pub authorized_keys [email protected]:~/.ssh$ ls authorized_keys id_rsa id_rsa.pub known_hosts [email protected]:~/.ssh$ more authorized_keys ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxjtfFUPSmTNNHJ4+4SubFrNEz7Teyu3HHvq7Lq0cOWXEJ6r53zA9LCawDyKUsrv5pNly4bqlt6SWJSELySieu+WgPVL6UNwROUE uBDagbnURviUVt6dXLcCOlqsCvy0AQsk+YIvS+qQhmE839X4W+Zd5xBZgUlGIqS1WhXbCs8sHiho09rxA0MIBXBlyvkfwmh71ubXny6GQHH3ZriyRZO0KrcMgwPHgsC/83fzSujnw5 BKiesJkpLHejmCo8m+eqW1Hcmj7OFMnAbaih86rqUnAE4rNrJnQUin73KgUFKQeHwnGRL3CPWR/KXdNvoEyUPHc/eeW0HhfK8GCWlQ/P [email protected]
测试,应该无密码登录成功
ssh ssmaster
exit
3.准备hadoop 安装包
下载到任意目录
解压
tar -zxvf hadoop-2.6.4.tar.gz
移动解压包
sudo mv hadoop-2.6.4 /opt/
4.配置hadoop
4.1 添加hadoop路径到环境变量
sudo vi /etc/profile 修改后如下
export HADOOP_HOME=/opt/hadoop-2.6.4 export JAVA_HOME=/home/szb/hadoop/jdk1.7.0_80 export JRE_HOME=$JAVA_HOME/jre export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin export CLASSPATH=./:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
source /etc/profile 生效
4.2 创建hdfs 数据存放目录
在hadoop安装目录下创建 dfs/name dfs/data
[email protected]:/opt/hadoop-2.6.4$ pwd /opt/hadoop-2.6.4 [email protected]:/opt/hadoop-2.6.4$ mkdir dfs [email protected]:/opt/hadoop-2.6.4$ ls bin dfs etc include lib libexec LICENSE.txt logs NOTICE.txt README.txt sbin share tmp [email protected]:/opt/hadoop-2.6.4$ cd dfs [email protected]:/opt/hadoop-2.6.4/dfs$ mkdir name data [email protected]:/opt/hadoop-2.6.4/dfs$ ls data name
4.3 添加jdk路径到 hadoop xxxx.sh 脚本文件中
所在路径 [email protected]:/opt/hadoop-2.6.4/etc/hadoop$
在以下文件中添加
export JAVA_HOME=/home/szb/hadoop/jdk1.7.0_80
hadoop-env.sh
yarn-env.sh
mapred-env.sh
4.4 修改slaves文件
所在路径 [email protected]:/opt/hadoop-2.6.4/etc/hadoop$
修改slaves文件内容为主机名,修改后:
[email protected]:/opt/hadoop-2.6.4/etc/hadoop$ more slaves ssmaster
4.5 配置xml文件
4.5.1 core-site.xml
修改后内容
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://ssmaster:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/hadoop-2.6.4/tmp</value>
</property>
</configuration>
备注:
fs.defaultFS namenode的目录
hadoop.tmp.dir 中间临时结果存放目录
目前来说,core-site.xml文件的最小化配置,core-site.xml各项配置可参考:http://hadoop.apache.org/docs/r2.6.0/hadoop-project-dist/hadoop-common/core-default.xml
4.5.2 hdfs-site.xml
修改后内容
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/opt/hadoop-2.6.4/dfs/name</value>
</property>
<property>
<name>dfs.namenode.data.dir</name>
<value>/opt/hadoop-2.6.4/dfs/data</value>
</property>
</configuration>
备注:
dfs.replication 副本数量,伪分布式为1,分布式一般为3
dfs.namenode.name.dir namenode 数据目录
dfs.namenode.data.dir datanode 数据目录
上述是hdfs-site.xml文件的最小化配置,hdfs-site.xml各项配置可参考:http://hadoop.apache.org/docs/r2.6.0/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml
4.5.3 mapred-site.xml
首先 复制 mapred-site.xml.template 为 mapred-site.xml
添加内容:
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
备注:
mapreduce.framework.name mapreduce的资源管理组件,可以存在其他值
上述是mapred-site.xml最小化配置,mapred-site.xml各项配置可参考:http://hadoop.apache.org/docs/r2.6.0/hadoop-mapreduce-client/hadoop-mapreduce-client-core/mapred-default.xml
4.5.4 yarn-site.xml
修改后内容
<configuration>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>ssmaster</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
备注:
yarn.resourcemanager.hostname resourcemanager的节点。 (问题猜测 如果是分布式 ,可以与namenode不同节点,待验证)
yarn.nodemanager.aux-services 暂不清楚含义,有空了解
上述内容是yarn-site.xml的最小化配置,yarn-site文件配置的各项内容可参考:http://hadoop.apache.org/docs/r2.6.0/hadoop-yarn/hadoop-yarn-common/yarn-default.xml
5.启动Hadoop
5.1 格式化HDFS
[email protected]:/opt/hadoop-2.6.4$ bin/hdfs namenode -format
最后日志有这样的,说明成功
16/10/22 19:40:40 INFO common.Storage: Storage directory /opt/hadoop-2.6.4/dfs/name has been successfully formatted.
5.2 启动HDFS
[email protected]:/opt/hadoop-2.6.4$ sbin/start-dfs.sh Starting namenodes on [ssmaster]ssmaster: starting namenode, logging to /opt/hadoop-2.6.4/logs/hadoop-hadoop-namenode-ssmaster.outssmaster: starting datanode, logging to /opt/hadoop-2.6.4/logs/hadoop-hadoop-datanode-ssmaster.outStarting secondary namenodes [0.0.0.0]The authenticity of host ‘0.0.0.0 (0.0.0.0)‘ can‘t be established.ECDSA key fingerprint is SHA256:ADBlLjhQ7xYbJRFQpw9t5OyA7+q7Yo50S+oK7liAnUk.Are you sure you want to continue connecting (yes/no)? yes0.0.0.0: Warning: Permanently added ‘0.0.0.0‘ (ECDSA) to the list of known hosts.0.0.0.0: starting secondarynamenode, logging to /opt/hadoop-2.6.4/logs/hadoop-hadoop-secondarynamenode-ssmaster.out [email protected]:/opt/hadoop-2.6.4$ jps 11151 DataNode 11042 NameNode 11349 SecondaryNameNode 11465 Jps
备注:
Starting secondary namenodes [0.0.0.0]
The authenticity of host ‘0.0.0.0 (0.0.0.0)‘ can‘t be established.
secondary namenode IP 为0,接下来提示yes/no,选择yes.
不知道怎么配置这里。 有空回头研究 [遗留小问题]
5.3 启动HDFS
[email protected]:/opt/hadoop-2.6.4$ sbin/start-yarn.sh starting yarn daemons starting resourcemanager, logging to /opt/hadoop-2.6.4/logs/yarn-hadoop-resourcemanager-ssmaster.out ssmaster: starting nodemanager, logging to /opt/hadoop-2.6.4/logs/yarn-hadoop-nodemanager-ssmaster.out [email protected]:/opt/hadoop-2.6.4$ jps 11151 DataNode 11042 NameNode 11714 Jps 11349 SecondaryNameNode 11675 NodeManager 11540 ResourceManager
http://192.168.249.144:8042/
http://192.168.249.144:8088/
hadoop web控制台页面的端口整理:
50070:hdfs文件管理
8088:ResourceManager
8042:NodeManager
JPS查看各个节点启动了,WEB 能打开各种页面,标志安装成功
6.保存虚拟机镜像
Z 总结:
Hadoop伪分布搭建初步成功
Z.1 存在的情况:[遗留研究]
- 网络配置没有特意设置,由虚拟机自动分配,可能有潜在IP变化问题
- hostname 大而全地设置,没有理清各个文件命令的功能
- hdfs 启动是 secondname node ip显示为0000,提示连接拒绝, 一定某个地方可以设置
Z.2 后续:
- 重点研究hadoop使用,安装eclipse,常用操作,jar调用
- 搭建spark环境,常用操作
- 有空研究纯分布式搭建
- 有空研究hadoop配置各个参数的含义,配置
Q 其他:
不同linux系统拷贝文件
scp hadoop-2.6.4.tar.gz [email protected]:~/
各种配置文件打包上传:
本机hadoop安装后涉及的文件.rar 任务:上传到某个地方,link过来 [遗留完善]
C 参考:
Ref 1
主要参考这篇教程
hadoop2.6.0版本搭建伪分布式环境
http://blog.csdn.net/stark_summer/article/details/43484545