1.首先确保你的虚拟机能连上网络,首先我选择ping百度确定虚拟机是否有网络,如下代码是网络畅通的情况,如果不能ping通百度,请看我另一篇关于网卡的配置。
[root@master ~]# ping www.baidu.com
PING www.a.shifen.com (119.75.213.61) 56(84) bytes of data.
64 bytes from 119.75.213.61: icmp_seq=1 ttl=128 time=36.7 ms
64 bytes from 119.75.213.61: icmp_seq=2 ttl=128 time=37.2 ms
64 bytes from 119.75.213.61: icmp_seq=3 ttl=128 time=36.9 ms
64 bytes from 119.75.213.61: icmp_seq=4 ttl=128 time=36.7 ms
64 bytes from 119.75.213.61: icmp_seq=5 ttl=128 time=36.9 ms
2.在root账户下我们先关闭防火墙:
[root@master ~]# service iptables stop
或者选择以下命令永久关闭防火墙:
[root@master ~]# chkconfig iptables off
3.(root用户执行)安装ssh协议,执行下面两条命令:
[root@master ~]# yum install ssh
[root@master ~]# yum install rsyuc
4.(hadoop用户执行)生成SSH公钥:
首先切换到hadoop用户,在主节点执行“ssh-keygen -t rsa”,遇到提示一直回车即可,最后会显示图像就是公钥指纹加密,然后再执行“ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@master”就会将公钥发至本机且在本地生成authorized_keys文件,第一次登陆需要输入Hadoop密码:
[root@master ~]# su - hadoop
[hadoop@master ~]$ 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:
a8:58:8d:0e:93:b4:99:11:6a:f3:b1:15:cc:2f:16:b9 hadoop@master
The key's randomart image is:
+--[ RSA 2048]----+
| . o.. |
| . . =. |
|.oo. .+ |
|..o*+E o |
| Bo+ + S |
| * . |
| . o |
| |
| |
+-----------------+
[hadoop@master ~]$ cd ~/.ssh/
[hadoop@master .ssh]$ ls
id_rsa id_rsa.pub
[hadoop@master .ssh]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@master
The authenticity of host 'master (192.168.137.200)' can't be established.
RSA key fingerprint is 2e:0f:f4:40:3c:96:ea:e4:0e:11:bb:25:60:7f:4b:af.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'master,192.168.137.200' (RSA) to the list of known hosts.
hadoop@master's password:
Permission denied, please try again.
hadoop@master's password:
Now try logging into the machine, with "ssh 'hadoop@master'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
5.验证是否成功,如下就是成功的:
[hadoop@master .ssh]$ ssh hadoop@master
Last login: Sat Oct 13 23:12:48 2018 from 192.168.137.1
[hadoop@master ~]$
6.如果没有成功,建议更改权限:
[hadoop@master ~]$ chmod 700 /home/hadoop/.ssh/
[hadoop@master ~]$ chmod 644 /home/hadoop/.ssh/authorized_keys