CentOS 7下Hadoop完全分布式集群搭建

1.Hadoop的节点构成如下:

HDFS daemon:  NameNode, SecondaryNameNode, DataNode

YARN damones: ResourceManager, NodeManager, WebAppProxy

MapReduce Job History Server

本次测试的分布式环境为:Master 1台 (test166),Slave 1台(test167)

2.1 安装JDK及下载解压hadoop

JDK安装可参考: 或 CentOS7.2安装JDK1.7 

从官网下载Hadoop最新版2.7.5

[hadoop@hadoop-master ~]$ su - hadoop
[hadoop@hadoop-master ~]$ cd /usr/hadoop/
[hadoop@hadoop-master ~]$ wget

将hadoop解压到/usr/hadoop/下

[hadoop@hadoop-master ~]$ tar zxvf /root/hadoop-2.7.5.tar.gz

结果:

[hadoop@hadoop-master ~]$ ll
total 211852
drwxr-xr-x.  2 hadoop hadoop        6 Jan 31 23:41 Desktop
drwxr-xr-x.  2 hadoop hadoop        6 Jan 31 23:41 Documents
drwxr-xr-x.  2 hadoop hadoop        6 Jan 31 23:41 Downloads
drwxr-xr-x. 10 hadoop hadoop      4096 Feb 22 01:36 hadoop-2.7.5
-rw-rw-r--.  1 hadoop hadoop 216929574 Dec 16 12:03 hadoop-2.7.5.tar.gz
drwxr-xr-x.  2 hadoop hadoop        6 Jan 31 23:41 Music
drwxr-xr-x.  2 hadoop hadoop        6 Jan 31 23:41 Pictures
drwxr-xr-x.  2 hadoop hadoop        6 Jan 31 23:41 Public
drwxr-xr-x.  2 hadoop hadoop        6 Jan 31 23:41 Templates
drwxr-xr-x.  2 hadoop hadoop        6 Jan 31 23:41 Videos
[hadoop@hadoop-master ~]$

2.2 在各节点上设置主机名及创建hadoop组和用户

所有节点(master,slave)

1 [root@hadoop-master ~]#  su - root
2 [root@hadoop-master ~]#  vi /etc/hosts
3 10.86.255.166 hadoop-master
4 10.86.255.167 slave1
5 注意:修改hosts中,是立即生效的,无需source或者. 。

先使用

建立hadoop用户组

新建用户,useradd -d /usr/hadoop -g hadoop -m hadoop (新建用户hadoop指定用户主目录/usr/hadoop 及所属组hadoop)

passwd hadoop 设置hadoop密码(这里设置密码为hadoop)

[root@hadoop-master ~]# groupadd hadoop
[root@hadoop-master ~]# useradd -d /usr/hadoop -g hadoop -m hadoop
[root@hadoop-master ~]# passwd hadoop

2.3 在各节点上设置SSH无密码登录

最终达到目的:即在master:节点执行  ssh hadoop@salve1不需要密码,此处只需配置master访问slave1免密。

su - hadoop

进入~/.ssh目录

执行:ssh-keygen -t rsa,一路回车

生成两个文件,一个私钥,一个公钥,在master1中执行:cp id_rsa.pub authorized_keys

[hadoop@hadoop-master ~]$ su - hadoop
[hadoop@hadoop-master ~]$ pwd
/usr/hadoop
[hadoop@hadoop-master ~]$ cd .ssh
[hadoop@hadoop-master .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/usr/hadoop/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /usr/hadoop/.ssh/id_rsa.
Your public key has been saved in /usr/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
11:b2:23:8c:e7:32:1d:4c:2f:00:32:1a:15:43:bb:de hadoop@hadoop-master
The key's randomart image is:
+--[ RSA 2048]----+
|=+*.. . .        |
|oo O . o .      |
|. o B + .        |
|  = + . .      |
|  + o  S        |
| . +            |
|  . E            |
|                |
|                |
+-----------------+
[hadoop@hadoop-master .ssh]$
[hadoop@hadoop-master .ssh]$ cp id_rsa.pub authorized_keys
[hadoop@hadoop-master .ssh]$ ll
total 16
-rwx------. 1 hadoop hadoop 1230 Jan 31 23:27 authorized_keys
-rwx------. 1 hadoop hadoop 1675 Feb 23 19:07 id_rsa
-rwx------. 1 hadoop hadoop  402 Feb 23 19:07 id_rsa.pub
-rwx------. 1 hadoop hadoop  874 Feb 13 19:40 known_hosts
[hadoop@hadoop-master .ssh]$

2.3.1:本机无密钥登录

[hadoop@hadoop-master ~]$ pwd
/usr/hadoop
[hadoop@hadoop-master ~]$ chmod -R 700 .ssh
[hadoop@hadoop-master ~]$ cd .ssh
[hadoop@hadoop-master .ssh]$ chmod 600 authorized_keys
[hadoop@hadoop-master .ssh]$ ll
total 16
-rwx------. 1 hadoop hadoop 1230 Jan 31 23:27 authorized_keys
-rwx------. 1 hadoop hadoop 1679 Jan 31 23:26 id_rsa
-rwx------. 1 hadoop hadoop  410 Jan 31 23:26 id_rsa.pub
-rwx------. 1 hadoop hadoop  874 Feb 13 19:40 known_hosts

验证:
没有提示输入密码则表示本机无密钥登录成功,如果此步不成功,后续启动hdfs脚本会要求输入密码

[hadoop@hadoop-master ~]$ ssh hadoop@hadoop-master
Last login: Fri Feb 23 18:54:59 2018 from hadoop-master
[hadoop@hadoop-master ~]$

2.3.2:master与其他节点无密钥登录     

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/fb5e257ae63a43966006ef5aaa499ef0.html