linux系统安装hadoop真分布式集群详解

Hadoop真分布式完全集群安装,基于版本2.7.2安装,在两台Linux机器上面分别安装Hadoop的master和slave节点。

1.安装说明

不管NameNode还是DataNode节点,安装的用户名需要一致。
master和slave的区别,只是在于配置的hostname,
在config的slaves配置的hostname所代表的机器即为slave,
不使用主机名也可以,直接配置为IP即可。
在这种集群下面,需要在master节点创建namenode路径,
并且使用格式化命令hdfs namenode –format。
然后在slave节点创建datanode路径,注意目录的权限。

2.配置hosts

如果已经存在则不需要,每台机器进行相同的操作

10.43.156.193 zdh193 ywmaster/fish master
10.43.156.194 zdh194 ywmaster/fish slave

3.创建用户

集群上面的用户名必须都是一样的,否则无法影响Hadoop集群启动,
在每台机器里面添加相同的用户,参考如下命令:

useradd ywmaster

4.安装JDK

此处安装的是jdk1.7

scp [email protected]:/home/yuwen/backup/jdk-7u80-linux-x64.tar.gz .
zdh123
tar -zxvf jdk-7u80-linux-x64.tar.gz 
vi .bash_profile 
export JAVA_HOME=~/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
source .bash_profile 

验证jdk

java -version

5.设置集群免密登陆

5.1.设置本地免密登陆

ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

必须修改权限,否则无法免秘登陆

chmod 600 ~/.ssh/authorized_keys

验证免密登陆

ssh localhost

5.2.设置远程免密登陆

需要把本机的公钥放到对方的机器authorized_keys,才能免密登陆其他机器。
进入ywmaster的.ssh目录

scp ~/.ssh/authorized_keys [email protected]:~/.ssh/authorized_keys_from_zdh193

进入ywslave的.ssh目录,注意备份,否则下面步骤存在重复的ywmaster公钥。

cat authorized_keys_from_zdh193 >> authorized_keys
ssh zdh194

5.3.设置其他机器免密登陆

参考上面的步骤同理设置其他机器,配置后zdh193可以免密登陆。

scp ~/.ssh/authorized_keys [email protected]:~/.ssh/authorized_keys_from_zdh194

6.安装Hadoop

上传并解压hadoop文件

scp [email protected]:/home/pub/hadoop/source/hadoop-2.7.2-src/hadoop-dist/target/hadoop-2.7.2.tar.gz .
zdh1234
tar -zxvf hadoop-2.7.2.tar.gz

7.配置环境变量

export HADOOP_HOME=~/hadoop-2.7.2
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop 

配置别名,可以快速访问配置路径

alias conf='cd /home/ywmaster/hadoop-2.7.2/etc/hadoop'

8.检查和修改Hadoop配置文件

8.1 hadoop-env.sh

涉及环境变量:JAVA_HOMEHADOOP_HOMEHADOOP_CONF_DIR

8.2 yarn-env.sh

涉及环境变量:JAVA_HOMEHADOOP_YARN_USERHADOOP_YARN_HOME, YARN_CONF_DIR

8.3 slaves

这个文件里面保存所有slave节点,注释掉localhost,新增zdh194作为slave节点。

8.4 core-site.xml

fs.defaultFS
hdfs://10.43.156.193:29080

fs.default.name
hdfs://10.43.156.193:29080
  
io.file.buffer.size
131072

hadoop.tmp.dir
file:/home/ywmaster/tmp

8.5 hdfs-site.xml

dfs.namenode.rpc-address
10.43.156.193:29080

dfs.namenode.http-address
10.43.156.193:20070
  
dfs.namenode.secondary.http-address
10.43.156.193:29001

dfs.namenode.name.dir
file:/home/ywmaster/dfs/name

dfs.datanode.data.dir
file:/home/ywmaster/dfs/data

dfs.replication
1

dfs.webhdfs.enabled
true

8.6 mapred-site.xml

mapreduce.framework.name
yarn

mapreduce.shuffle.port
23562
  
mapreduce.jobhistory.address
10.43.156.193:20020

mapreduce.jobhistory.webapp.address
10.43.156.193:29888

8.7:yarn-site.xml

yarn.nodemanager.aux-services
mapreduce_shuffle
                                                            
yarn.nodemanager.aux-services.mapreduce.shuffle.class  TODODELETE
org.apache.hadoop.mapred.ShuffleHandler

#mapreduce.shuffle已经过时,改为mapreduce_shuffle
yarn.nodemanager.aux-services.mapreduce_shuffle.class
org.apache.hadoop.mapred.ShuffleHandler

yarn.resourcemanager.address
10.43.156.193:28032

yarn.resourcemanager.scheduler.address
10.43.156.193:28030

yarn.resourcemanager.resource-tracker.address
10.43.156.193:28031

yarn.resourcemanager.admin.address
10.43.156.193:28033

yarn.resourcemanager.webapp.address
10.43.156.193:28088

8.8 获取Hadoop的默认配置文件

选择相应版本的hadoop,下载解压后,搜索*.xml,
找到core-default.xml,hdfs-default.xml,mapred-default.xml,
这些就是默认配置,可以参考这些配置的描述说明,
在这些默认配置上进行修改,配置自己的Hadoop集群。

find . -name *-default.xml
./hadoop-2.7.1/share/doc/hadoop/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml
./hadoop-2.7.1/share/doc/hadoop/hadoop-project-dist/hadoop-common/core-default.xml
./hadoop-2.7.1/share/doc/hadoop/hadoop-mapreduce-client/hadoop-mapreduce-client-core/mapred-default.xml
./hadoop-2.7.1/share/doc/hadoop/hadoop-yarn/hadoop-yarn-common/yarn-default.xml
./hadoop-2.7.1/share/hadoop/httpfs/tomcat/webapps/webhdfs/WEB-INF/classes/httpfs-default.xml

9.把配置好的Hadoop复制到其他节点

scp -r ~/hadoop-2.7.2 [email protected]:~/

或者只拷贝配置文件,可以提高拷贝效率:

scp -r ~/hadoop-2.7.2/etc/hadoop [email protected]:~/hadoop-2.7.2/etc

创建好name和data数据目录

mkdir -p ./dfs/name
mkdir -p ./dfs/data

10.启动验证Hadoop

格式化namenode:

hdfs namenode -format

出现如下结果则表示成功:

16/09/13 23:57:16 INFO common.Storage: Storage directory /home/ywmaster/dfs/name has been successfully formatted.

启动hdfs

start-dfs.sh

启动yarn:

start-yarn.sh

注意修改了配置之后一定要重新复制到其他节点,否则启动会有问题。

11.检查启动结果

NameNode下执行jps应该包含如下进程:

15951 ResourceManager
13294 SecondaryNameNode
12531 NameNode
16228 Jps

DataNode下执行jps应该包含如下进程:

3713 NodeManager
1329 DataNode
3907 Jps

查看HDFS服务:

http://10.43.156.193:20070

查看SecondaryNameNode:

http://10.43.156.193:29001/

具体IP和Port参考hdfs-site.xml:

dfs.namenode.http-address
 The address and the base port where the dfs namenode web ui will listen on.

查看RM:

http://10.43.156.193:28088

具体IP和Port参考yarn-site.xml:

yarn.resourcemanager.webapp.address
10.43.156.193:28088

12.其他参考

停止命令:

stop-yarn.sh
stop-dfs.sh

执行命令验证:

hadoop fs -ls /usr
hadoop fs -mkdir usr/yuwen
hadoop fs -copyFromLocal wordcount /user
hadoop fs -rm -r /user/wordresult
hadoop jar ~/hadoop-2.7.2/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/wordcount.txt /user/wordresult_001
hadoop fs -text /user/wordresult_001/part-r-00000

更多关于linux系统安装hadoop真分布式集群的文章请查看下面的相关链接

你可能感兴趣的:(linux系统安装hadoop真分布式集群详解)