02.hadoop集群搭建之免密登录

1.配置每个节点的hosts

   vi   /etc/hosts

  192.168.136.16 master1
  192.168.136.17 master2
  192.168.136.18 node1
  192.168.136.19 node2

 

2.每个节点生成公钥私钥

[hadoop@master1 .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
09:74:dc:02:6d:ff:42:8c:33:3c:08:09:97:2c:c1:26 hadoop@master1
The key's randomart image is:
+--[ RSA 2048]----+
| .o+.oo+..       |
|E +.=. .= .      |
| o . ..+ =       |
|      ..*.+      |
|        S= .     |
|          . .    |
|           .     |
|                 |
|                 |
+-----------------+

[hadoop@master1 .ssh]$ ll
总用量 8
-rw-------. 1 hadoop hadoop 1675 12月 31 15:47 id_rsa
-rw-r--r--. 1 hadoop hadoop  396 12月 31 15:47 id_rsa.pub

3.公钥复制到authorized_keys

[hadoop@master1 ~]$ cp  .ssh/id_rsa.pub   .ssh/authorized_keys
[hadoop@master1 ~]$ ll  .ssh

总用量 12
-rw-r--r--. 1 hadoop hadoop  396 12月 31 15:49 authorized_keys
-rw-------. 1 hadoop hadoop 1675 12月 31 15:47 id_rsa
-rw-r--r--. 1 hadoop hadoop  396 12月 31 15:47 id_rsa.pub

4.将master1节点上的authorized_keys拷贝到master2节点,并将master2节点上的id_rsa.pub追加到authorized_keys

master1节点上执行远程拷贝命令:

[hadoop@master1 .ssh]$ scp authorized_keys  master2:/home/hadoop/.ssh/
The authenticity of host 'master2 (192.168.136.17)' can't be established.
ECDSA key fingerprint is fa:b3:81:b4:5f:e5:ea:f4:d4:ac:ea:96:5d:5e:71:49.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'master2,192.168.136.17' (ECDSA) to the list of known hosts.
hadoop@master2's password: 
authorized_keys  

登录master2节点将公钥追加到authorized_keys文件中

[hadoop@master2 .ssh]$ cat id_rsa.pub  >> authorized_keys 

5.重复第4步,将master2节点上的authorized_keys拷到node1节点上,并将node1节点上的id_rsa.pub追加到authorized_keys

6.重复第4步,再将node1上的authorized_keys拷到node2节点上,并将node2节点上的id_rsa.pub追加到authorized_keys

7.将node4节点上的authorized_keys拷贝到master1、master2、node1上

hadoop@node2 .ssh]$ scp authorized_keys  master1:/home/hadoop/.ssh/
The authenticity of host 'master1 (192.168.136.16)' can't be established.
ECDSA key fingerprint is fa:b3:81:b4:5f:e5:ea:f4:d4:ac:ea:96:5d:5e:71:49.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'master1,192.168.136.16' (ECDSA) to the list of known hosts.
hadoop@master1's password: 
authorized_keys                                                                                                    100% 1580     1.5KB/s   00:00    
[hadoop@node2 .ssh]$ scp authorized_keys  master2:/home/hadoop/.ssh/
The authenticity of host 'master2 (192.168.136.17)' can't be established.
ECDSA key fingerprint is fa:b3:81:b4:5f:e5:ea:f4:d4:ac:ea:96:5d:5e:71:49.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'master2,192.168.136.17' (ECDSA) to the list of known hosts.
hadoop@master2's password: 
authorized_keys                                                                                                    100% 1580     1.5KB/s   00:00    
[hadoop@node2 .ssh]$ scp authorized_keys  node1:/home/hadoop/.ssh/
The authenticity of host 'node1 (192.168.136.18)' can't be established.
ECDSA key fingerprint is fa:b3:81:b4:5f:e5:ea:f4:d4:ac:ea:96:5d:5e:71:49.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node1,192.168.136.18' (ECDSA) to the list of known hosts.
hadoop@node1's password: 
authorized_keys         

8.验证免密

[hadoop@master1 ~]$ ssh master2
Last login: Tue Dec 31 16:00:39 2019 from master1
[hadoop@master2 ~]$ 

 

 

你可能感兴趣的:(hadoop)