VMware版本號:12.0.0node
CentOS版本:CentOS 7.3.1611dom
三臺虛擬機(IP):ssh
修改三臺主機名,以此類推,node1,node3,node3ide
命令格式測試
hostnamectl set-hostname <hostname>
$ hostnamectl set-hostname node1
剩下的虛擬機依次修改hostnamectl set-hostname[1-3]
spa
重啓操做系統操作系統
$ reboot
1.在 node1 的 /etc/hosts
文件下添加以下內容3d
$ vi /etc/hosts
2.查看修改後的/etc/hosts
文件內容rest
$ cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 # 如下是添加的 192.168.252.121 node1 192.168.252.122 node2 192.168.252.123 node3
2.將集羣node1 上的文件hosts
文件 經過 scp
命令複製發送到集羣的每個節點code
$ for a in {1..3} ; do scp /etc/hosts node$a:/etc/hosts ; done
3.檢查是否集羣每個節點的 hosts
文件都已經修改過來了
$ for a in {1..3} ; do ssh node$a cat /etc/hosts ; done
1.在集羣node1的 /etc/ssh/sshd_config
文件去掉如下選項的註釋
$ vi /etc/ssh/sshd_config RSAAuthentication yes #開啓私鑰驗證 PubkeyAuthentication yes #開啓公鑰驗證
2.將集羣node1 修改後的 /etc/ssh/sshd_config
經過 scp
命令複製發送到集羣的每個節點
$ for a in {1..3} ; do scp /etc/ssh/sshd_config node$a:/etc/ssh/sshd_config ; done
1.在集羣的每個節點節點輸入命令 ssh-keygen -t rsa -P ''
,生成 key,一概回車
$ ssh-keygen -t rsa -P ''
[root@node1 ~]# ssh-keygen -t rsa -P '' Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): 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:42:2d:15:39:cc:f6:4a:9c:da:57:5b:55:b8:18:5d root@node1 The key's randomart image is: +--[ RSA 2048]----+ | ooo . +E | | o* . + | | oo.+ + . | | . .+ . . o . | | .+....So | | ..o.... | | . | | | | | +-----------------+
2.在集羣的node1 節點輸入命令
將集羣每個節點的公鑰id_rsa.pub
放入到本身的認證文件中authorized_keys
;
for a in {1..3}; do ssh node$a cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys; done
3.在集羣的node1 節點輸入命令
將本身的認證文件 authorized_keys
經過
scp 命令複製發送到每個節點上去:
/root/.ssh/authorized_keys`
for a in {1..3}; do scp /root/.ssh/authorized_keys node$a:/root/.ssh/authorized_keys ; done
4.在集羣的每個節點節點輸入命令
接重啓ssh服務
systemctl restart sshd.service
5.開一個其餘窗口測試下可否免密登錄
例如:在node3
[root@node3 ~]# ssh node1 The authenticity of host 'node1 (192.168.252.121)' can't be established. ECDSA key fingerprint is ab:0f:08:20:3d:7a:11:05:ea:d9:b0:0c:9e:e1:d0:97. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'node1,192.168.252.121' (ECDSA) to the list of known hosts. Last login: Tue Aug 22 14:00:18 2017 from 192.168.252.1
exit
退出
[root@node1 ~]# exit logout Connection to node1 closed.
注意:開新的其餘窗口測試下可否免密登錄,把當前窗口都關了