修改域名与IP的对应关系(hadoop2和hadoop3同样也需要修改hosts文件)

vi /etc/hosts
10.2.15.176 hadoop1
10.2.15.177 hadoop2
10.2.15.170 hadoop3

cd ~/.ssh 进入rsa公钥私钥文件存放的目录(如果没有.ssh目录,则使用ssh命令连接一次其他主机就会生成)
.ssh 目录下输入命令并三次回车就会生成 id_rsaid_rsa.pub文件

ssh-keygen -t rsa

将id_rsa.pub公钥内容拷贝到authorized_keys文件中

cat id_rsa.pub >> authorized_keys

按照相同的方式在另外两台服务器hadoop2, hadoop3生成id_rsa.pub,并把id_rsa.pub拷贝到同一个authorized_keys文件中,拷贝后的authorized_keys

[root@hadoop1 .ssh] more authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC92MPpDY5H4Rnq9AM1QKPFu6dRlLI2oiH/C+eUtDcYM4TQMLV9/Jwk0ffOaWvGIdLYbj/pQ+pZm8i4jWXQ/IDtnC8UlScQqpa5dkzi3yBZTs6/t6Z5+Hbe0s8cXemqxXllVIitg3VQQ8hZOQss5kl/XS4mN51xAfCnuehr1VLOJ3eMjmoIpKtWSzypxaO7GTxHfd/zzZB0fs5u//Sv1uaZKpIHPWCFiNvfxDG4C1mts9LqIf+iQyMrJGCCFxuuIOGvBjqmNDX2dUd7glVCwpiQf2bbw1N7INvfOkwoT33hSn0uICGvK36tQYYh8CAyyuh9CUP+TJu+Mz0M0fcNeJ root@hadoop1.com
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDX8gcUU5M8RURsxBfSzrdMTjXxJAU6UsxLHLxxCa1aiUNrLQyF6QwwZQlmzBpnNjXE9vOtzTfXOAu7m/2YBXDN8tQ4ULFNmKF3xt/lZfeYkSiuJmSxOw/BklOJGhwrEwJIaQV7h28Oqx/o2iHyfSbx6BcBDVzzwiwBlKThb3EM9J3r9dHynvT0ogGb5KpP/o4pi7inhb7PffB5zq4sz1Q726tq9YsS/uG3emJLHj4ovSf4F3FIFPY8mtFuTsIjtuOO2YRTIYyTXd17XqJEVhd+rIYosoLi2oB6U7az2HI00j3f+DgB0wbd9zHaI2h2J88a4RhTnAfSCWaWFZyxn19d root@hadoop2.com
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCn2yYONHHW25rqBX2X4zUD4qHHXzIf1wtWaLEi1FYOOrB46aWZxVMV/UTA+AowvH4RVV9nw0rldmG6PaEyrNvUZW0t7wripRNxGTldpm2nBg692gSgLy+gQH4i4nG/r/nxXL05XmH+zUJT7sLZYea2S/pH2NZpIkThusR6hiDyfqcTCB22MhRlkdgIh1MgMdFoDlk5jN4ezra6MBWcNg1VBP4xp70+NhSwmt1RutN/puNFkpgUjz5gmOT8ZLZ4R4cwM5H8/ZLljB/8aDkQrneUJ9TIVYAyVZOhD3w7NTpJsfulX6ao71PuFSwje0+V2nctPYP6L1litX4S6t5vDgup root@hadoop3.com

在hadoop1中授权authorized_keys

chmod 600 authorized_keys

最后将 authorized_keys 拷贝至hadoop2, hadoop3的.ssh目录下

scp /root/.ssh/authorized_keys hadoop2:/root/.ssh/ 
scp /root/.ssh/authorized_keys hadoop3:/root/.ssh/

测试ssh无密码登录(注意:第一次登录需要密码,之后不再需要)

ssh hadoop2
exit
ssh hadoop3
exit

Natasha
21 声望7 粉丝