1、配置ssh 无密码登录
ssh-keygen -t rsa
根据提示按三次enter键
[root@centos67 opt]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
22:ec:f0:b6:2b:dc:54:d6:4f:ae:a0:a8:e6:3d:55:84 root@centos67
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| E . |
| .. |
| . o.. . |
| . ooo S+ |
| +.o.. o |
| . +=. . . |
| .=oo. . |
|+o o+. |
+-----------------+
2、修改ip与hostname映射,修改/etc/hosts(删除所有,只添加下面一行)
192.168.128.130 master
192.168.128.131 slave1
192.168.128.132 slave2
192.168.128.133 slave3
3、输入命令
ssh-copy-id -i /root/.ssh/id_rsa.pub centos67
根据提示输入yes,123456(root用户的密码)
[root@centos67 opt]# ssh-copy-id -i /root/.ssh/id_rsa.pub centos67
The authenticity of host 'centos67 (192.168.0.128)' can't be established.
RSA key fingerprint is 09:7a:e4:ad:28:ce:ac:b6:0f:ea:99:82:fa:62:25:96.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'centos67,192.168.0.128' (RSA) to the list of known hosts.
root@centos67's password:
Now try logging into the machine, with "ssh 'centos67'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting
4、检查各个子节点是否能成功直接登录
[root@centos67 opt]# ssh centos67
Last login: Tue Nov 3 18:39:41 2015 from 192.168.0.1
[root@master ~]# ssh slave1
[root@slave1 ~]# exit
[root@master ~]# ssh-keygen -t rsa
[root@master ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub master
[root@master ~]# ssh master
[root@master ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub slave1
[root@master ~]# ssh slave1
[root@slave1 ~]# exit
[root@master ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub slave2
[root@master ~]# ssh slave2
[root@slave2 ~]# exit
[root@master ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub slave3
[root@master ~]# ssh slave3
[root@slave3 ~]# exit
注:当报错-bash: ssh-copy-id: command not found
是因为还没安装openssh-clients。
输入yum install openssh-clients
命令进行安装,如果安装的时候报错No more mirrors to try是因为没有挂载,清理yum缓存并挂载
[root@master ~]# ls /media/
[root@master ~]# mount /dev/dvd /media/
然后再安装openssh-clients即可。