修改域名與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_rsa
,id_rsa.pub
文件ssh
ssh-keygen -t rsa
將id_rsa.pub公鑰內容拷貝到authorized_keys文件中oop
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
code
chmod 600 authorized_keys
最後將 authorized_keys
拷貝至hadoop2, hadoop3的.ssh目錄下ip
scp /root/.ssh/authorized_keys hadoop2:/root/.ssh/ scp /root/.ssh/authorized_keys hadoop3:/root/.ssh/
測試ssh無密碼登陸(注意:第一次登陸須要密碼,以後再也不須要)hadoop
ssh hadoop2 exit ssh hadoop3 exit