服务器集群搭建、管理、快速部署

修改主机名

> 搭建集群的第一个工作,得知道每台机器的名字,也就是给每台机器起名字(后续通过名字来取得联系)

centos 下修改主机名

[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=simon

ubuntu 下修改主机名

[root@localhost ~]# vim /etc/hostname
simon

搭建dns服务器(下面是通过host文件来实现,真实环境中可以DNS来配置)

我们现在需要每台服务器之间可以通信,把每台机器的hosts配置一下
[root@localhost ~]# inconfig 查看IP地址
[root@localhost ~]# vim /etc/hosts
192.168.1.102 ubuntu
192.168.1.102 ms 管理服务器 添加之末尾
192.168.1.119 db 数据库服务器
192.168.1.120 test 测试服务器
192.168.1.121 product 产品服务器
//添加四台服务器

> 需要重启服务器 shutdown -r now
此时可以通过主机名来联系,就可以ping通了

[root@simon ~]# ping ubuntu
PING ubuntu (192.168.1.102) 56(84) bytes of data.
64 bytes from ubuntu (192.168.1.102): icmp_seq=1 ttl=64 time=2.16 ms
64 bytes from ubuntu (192.168.1.102): icmp_seq=2 ttl=64 time=0.291 ms
64 bytes from ubuntu (192.168.1.102): icmp_seq=7 ttl=64 time=0.252 ms
--- ubuntu ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6818ms
rtt min/avg/max/mdev = 0.252/0.553/2.163/0.657 ms

服务器之间互相认识(可以互相传输文件 scp拷贝文件)

这里不需要写ip地址 myuser 是 ubuntu服务器的用户名
[root@simon ~]# scp ./install.log myuser@ubuntu:/home/

> 产品服务器的ip是直接暴露在外的,不安全,为了安全就把密码登录关闭(db,test,product),
但是我们关闭密码登录我们如何登录呢?我们如何管理呢?
我们自己必须可以登录,openssh(我们现在使用的是xshell)我们就必须使用公钥和私钥来登录
ms服务器:可以登录,其他都不能登录,只能在内网集群内登录
防火墙设置只有集群和局域网登录
还可以使用密钥登录

创建密钥、公钥的方法

[root@localhost ~]# 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:
2f:27:12:19:c4:16:e6:16:6a:24:0c:5e:3a:43:26:e3 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|+=....=.         |
|*.+o =o.         |
| E  o.+          |
|  o. . o         |
|      o S        |
|       . .       |
|      . o o      |
|       . +       |
|                 |
+-----------------+
[root@localhost ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog
[root@localhost ~]# cd  ./.ssh/
[root@localhost .ssh]# ls
id_rsa  id_rsa.pub
[root@localhost .ssh]# cat id_rsa.pub >> authorized_keys
[root@localhost .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub
[root@localhost .ssh]# cp id_rsa /home/   把私钥复制到/home下,以便下载到本地
    
    > id_rsa密钥 id_rsa.pub公钥 密钥登录:拿到公钥就可以互相登录

scp id_rsa.pub root@db:~/
scp id_rsa.pub root@test:~/
spc id_rsa.pub root@product:~/

重启服务器
ms服务器来登录其他服务器
ssh simon@db;这样就可以登录db的服务器

关闭密码登录(有必要的话,利用防火墙来设置)

[root@simon ~]# cd /etc/ssh/
[root@simon ssh]# vim sshd_config
passwordAuthentication on 把yes改成no

需要重启服务:shutdown -r now
此时xshell登录失败

此时只有ms服务器才能登录

如果ms服务器挂了的话,就没办法登录其他服务器了,可以把ms做一个备份(镜像 ),也可以在其他服务器上做防火墙,让其他服务器只能局域网访问,这样的话,我们一个基本的环境就OK了

版本库,测试环境,产品环境,文档库,自动化部署

你可能感兴趣的:(服务器集群搭建、管理、快速部署)