26-架构演变优化-模板机创建
文章目录
1. 企业集群架构概述
1.1 架构名词介绍
- 什么是项目,类似于手机的APP 网站。每一个APP或者网站都是一个项目
- 什么是架构,维护一个项目的一组服务器
- 什么是集群,为了解决某个特定问题将多台计算机组合起来形成的单个系统
- 什么是高可用,当一台服务器不可用,另一台服务器自动接管,保证业务不宕机
- 什么是负载均衡,将用户的请求,分摊到多个操作单元上执行,保证服务器的稳定性
1.2 架构如何演变
开车–>各种公路/高速公路–>到达目的地–>酒店
保安–>验证身份
迎宾小姐姐–>接待工作
服务员–>满足客户的需求(动态扩容)
后厨厨师–>提供具体的菜品
吧台–>存放烟酒
备菜–>提前准备好(快)
仓库–>存放杂物
经理–>管理保安服务员等
监控–>用来监控服务员厨师等状态信息。时间回溯
1.3 架构访问流程-用户视角
-
用户通过浏览器输入oldboyedu.com
-
浏览器会发生一次跳转,分析URL->然后进行DNS解析->获取真实的公网IP地址
-
用户通过TCP的三次握手发起连接->真实的公网IP
-
连接会通过公网->路由器->交换机->抵达前段的防火墙
-
防火墙会根据自身访问规则,进行匹配->如果是恶意连接则拒绝。如果是正常连接则放行
-
防火墙会将连接转发给负载均衡器->查看用户请求的内容->根据内容进行任务下发->下发给web服务器
-
web服务器接收请求后会根据请求进行判断。
如果是请求图片或者附件->查找存储服务器存储的静态资源
如果是请求的网站上的内容->缓存服务器没有->数据库
数据库查询数据之后会返回数据给web服务器->同时也会缓存一份给缓存服务器
-
数据库返回内容->web服务器->负载均衡->用户
1.4 架构访问流程-运维视角
- 用户通过公网连接(隧道)VPN服务器,这样方便管理内部主机
- 自动化配置管理,节省人力资源,便于后期维护。统一环境,标准化。
- 自动化监控服务,监控系统的运行状态,事前预警,事后追溯。
总结:
一个项目涵盖了一套架构,一套架构又涵盖了不同角色(高可用、负载均衡、web集群)
五层架构模型->负载均衡 web服务器 存储服务器 缓存服务器 数据库服务器(通过TCP连接)
1.5 架构如何演变-服务器架构扩容
横向扩展也叫水平扩展,用更多的节点支撑更大量的请求。 如成千上万的蚂蚁完成一项搬运工作
纵向扩展又叫垂直扩展,扩展一个点的能力支撑更大的请求。如蜘蛛侠逼停火车
2.模板机优化步骤
2.1 添加第二块网卡
虚拟机–右键设置-添加–网络适配器–LAN区段–设置名称172.16.1.0/24
2.2 创建第二块网卡的配置文件
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-eth1
#优化网卡eth1
vi ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=none
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=172.16.1.200
PREFIX=24
#优化网卡eth0
[root@oldboyedu network-scripts]# cat ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.200
PREFIX=24
GATEWAY=10.0.0.2
DNS1=223.5.5.5
#重启网卡
[root@oldboyedu network-scripts]# systemctl restart network
2.3 修改默认的YUM仓库为阿里云的
访问阿里云页面:
https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11yRIdp7
#1.备份默认仓库:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#2.配置yum源为阿里云
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
2.4 安装epel扩展仓库
#安装wget命令
[root@oldboyedu yum.repos.d]# yum install -y wget
#扩展仓库不需要备份,因为默认的linux系统没有扩展仓库
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@oldboyedu yum.repos.d]# ll
total 48
-rw-r--r--. 1 root root 2523 Apr 7 17:10 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 Oct 23 2020 CentOS-Base.repo.backup
-rw-r--r--. 1 root root 1309 Oct 23 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Oct 23 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Oct 23 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Oct 23 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 Oct 23 2020 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 664 Aug 4 2022 epel.repo
#检查
[root@oldboyedu yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
epel | 4.7 kB 00:00:00
(1/3): epel/x86_64/group_gz | 100 kB 00:00:00
(2/3): epel/x86_64/updateinfo | 1.0 MB 00:00:05
(3/3): epel/x86_64/primary_db | 7.0 MB 00:00:23
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,798
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 526
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 5,802
repolist: 30,198 #默认的仓库和扩展仓库总软件数量
2.5 安装常用的命令
yum -y install vim wget net-tools lrzsz tree bash-completion.noarch bash-completion-extras.noarch ntpdate
2.6 关闭NetworkManager和firewall
[root@oldboyedu ~]# systemctl stop NetworkManager
[root@oldboyedu ~]# systemctl disable NetworkManager
[root@oldboyedu ~]# systemctl stop firewalld
[root@oldboyedu ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
2.7 关闭selinux防火墙
[root@oldboyedu ~]# getenforce
Enforcing
[root@oldboyedu ~]# setenforce 0
[root@oldboyedu ~]# sed -i '7c SELINUX=disabled' /etc/selinux/config
[root@oldboyedu ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
2.8 修改进程打开的文件数量 默认是1024
echo '* - nofile 65535' >> /etc/security/limits.conf
2.9 优化SSH
1.创建普通用户
2.修改默认端口(公网机器)
3.优化远程登录速度
[root@oldboyedu ~]# grep -n 'UseDNS' /etc/ssh/sshd_config
115:UseDNS no
重启生效:[root@oldboyedu ~]# systemctl restart sshd
2.10 配置PS1变量(bash颜色)
#可以不配置
vim /etc/profile
# PS1="[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\h\[\e[0m\]\[\e[31;1m\] \W\[\e[0m\]]\\$"
2.11 重启系统
reboot
2.12 做快照
手动做快照
3.快速扩展一台服务器
10.0.0.41 172.16.1.41
10.0.0.7 172.16.1.7
1.克隆
2.修改信息
1)修改IP地址
2)修改主机名称
hostnamectl set-hostname backup
3)做快照
4)创建连接会话