Centos8.2服务器 (三台)
Xshell7(成功连接三台服务器)
2.搭建前的准备
以下代码均在Xshell7下执行
更改主机名(所有服务器都执行)
hostnamectl set-hostname master
hostnamectl set-hostname slave1
hostnamectl set-hostname slave2
更改完成后,需要重新连接服务器
主机名与IP地址的映射(所有服务器都执行)
vim /etc/hosts
在文件尾部添加以下内容(云服务自己的ip要用内网)
(ip地址+主机名)
106.13.58.73 master
106.13.238.4 slave1
106.12.194.252 slave2
关闭防火墙(所有服务器都执行)
//临时关闭防火墙
[root@master ~]# systemctl stop firewalld
//永久关闭防火墙
[root@master ~]# systemctl disable firewalld
关闭selinux(所有服务器都执行)
[root@node1 ~]# cd /etc/selinux
[root@node1 selinux]# vim config
//修改SELINUX值为disabled
SELINUX=disabled
服务器免密登录(所有服务器都执行)
[root@master ~]# ssh-keygen
然后输入三个回车即可
[root@master ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
SHA256:F3vCR4ZSwzU5n6OkVz/nzTeEi4QPiWoHIkDd0LSUm/4 root@master
The key's randomart image is:
+---[RSA 3072]----+
| ..=o. .o.o. |
| . ..+. ..oo. |
|. .o . o oo . |
|. o o =. = |
|. . S Booo.o |
| . . o . =.=o. oo|
| . . + +.. oo+|
| o E o . .=|
| . . o|
+----[SHA256]-----+
拷贝公钥到slave1服务器
[root@master ~]# ssh-copy-id root@slave1
得到结果:
[root@master ~]# ssh-copy-id root@slave1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'master (106.13.58.73)' can't be established.
ECDSA key fingerprint is SHA256:QJdCk0NMkbUfzrFqPah1sJA2fK1aX5FTN8FSlb12MNQ.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@master's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'master'"
and check to make sure that only the key(s) you wanted were added.
测试免密码登录
[root@master ~]# ssh root@slave1
其他服务器实现免密码登录,操作方式与上述一致。
linux集群搭建结束