hadoop 主机免密设置

hadoop三台主机免密设置

文件权限
.ssh 700 id_rsa 600 id_rsa.pub 644

环境rhel8 需要三台主机

master slave1 slave2

配置三台主机同一网段 10.10.10.0/24

[root@maoqiyang network-scripts]# nmcli connection add con-name  supermao ifname ens160 ipv4.method manual ipv4.addresses 10.10.10.128/24  ipv4.gateway 10.10.10.2  ipv4.dns 114.114.114.114 type ethernet 

master 10.10.10.128
slave1 10.10.10.129
slave2 10.10.10.130

三台主机配置/etc/hosts

10.10.10.128 master master.example.com
10.10.10.129 slave1 slave1.example.com
10.10.10.130 slave2 slave2.example.com

三台主机修改 /etc/ssh.config

sed  -i  '/PubkeyA*/ s/#//'   /etc/ssh/sshd_config
systemctl   restart  sshd 

(默认开启,可改可不改)

三台主机创建hadoop用户并切换到hadoop

useradd hadoop  && echo 123 | passwd --stdin hadoop
su   -   hadoop

三台主机一定得切换到hadoop

master

生成秘钥并配置免密ssh登录自己

方式一
ssh-keygen -t rsa -P ''
(一直回车)
cat id_rsa.pub > authorized_keys
chmod 600 authorized_keys
ssh hadoop@localhost

登录slave1和slave2

#slave1
[hadoop@master ~]$ scp     ~/.ssh/id_rsa.pub     hadoop@slave1:~/
##切换到slave1 虚拟机
[hadoop@slave1 ~]$ cat id_rsa.pub >   ~/.ssh/authorized_keys    
[hadoop@slave1 .ssh]$ chmod 600 authorized_keys
[hadoop@master ~]$ ssh hadoop@slave1
#slave2
[hadoop@master ~]$ scp     ~/.ssh/id_rsa.pub     hadoop@slave1:~/
##切换到slave2 虚拟机
[hadoop@slave2 ~]$ cat id_rsa.pub >   ~/.ssh/authorized_keys    
[hadoop@slave2 .ssh]$ chmod 600 authorized_keys
[hadoop@master ~]$ ssh hadoop@slave2

slave1

生成秘钥并配置免密ssh登录自己

方式一
ssh-keygen -t rsa -P ''
(一直回车)
cat id_rsa.pub > authorized_keys
chmod 600 authorized_keys
ssh hadoop@localhost

登录master和slave2

类似master,省略

slave2

生成秘钥并配置免密ssh登录自己

方式二
ssh-keygen -t rsa -P ''
(一直回车)
ssh-copy-id hadoop@localhost
yes 并且 输入当前hadoop密码
ssh hadoop@localhost

登录slave1和master

ssh-copy-id hadoop@master  
yes  并且  输入当前hadoop密码  
ssh hadoop@master  
ssh-copy-id hadoop@slave1  
yes  并且  输入当前hadoop密码  
ssh hadoop@slave1  

最后,三台主机能够相互免密登录

posted @ 2022-03-18 19:46  supermao12  阅读(150)  评论(0编辑  收藏  举报