目录
二:lvs(Linux virtual server)运行原理
2:把主机的 /etc/ssh/sshd_config 的远程连接调为yes,不然xshell无法远程连接
3:添加一个网卡,把第一个网卡调为nat模式,另一个网卡调为仅主机模式
2:安装httpd服务,输入信息到网址里面(方便后续测试)并且开启服务
2:安装httpd服务,输入信息到网址里面(方便后续测试)并且开启服务
六:在主机webserver1和主机webserver2使VIP不对外响应
七:在LVS和webserver1和webserver2上添加环回VIP
一:集群和分布式简介
1.1:集群Cluster
Cluster:
集群是为了解决某个特定问题将堕胎计算机组合起来形成的单个系统
Cluster
常见的三种类型:
- LB:LoadBalancing(负载均衡)由多个主机组成,每个主机只承担一部分访问
- HA:High Availiablity(高可用)SPOF(single Point Of failure)
MTBF:Mean Time Between Failure
平均无故障时间,正常时间
MTTR:Mean Time To Restoration
(
repair
)平均恢复前时间,故障时间
A=MTBF/
(
MTBF+MTTR
)
(0,1)
:
99%, 99.5%, 99.9%, 99.99%, 99.999%
SLA
:
Service level agreement
(服务等级协议)是在一定开销下为保障服务的性能和可用性,服 务提供商与用户间定义的一种双方认可的协定。通常这个开销是驱动提供服务质量的主要因素。在 常规的领域中,总是设定所谓的三个9
,四个
9
来进行表示,当没有达到这种水平的时候,就会有一 些列的惩罚措施,而运维,最主要的目标就是达成这种服务水平。
停机时间又分为两种,一种是计划内停机时间,一种是计划外停机时间,而运维则主要关注计划外
停机时间
- HPC:High-performance computing(高性能计算,国家战略资源
1.2:分布式
分布式存储:Ceph
,
GlusterFs
,
FastDFS
,
MogileFs
分布式计算
:hadoop
,
Spark
分布式常见应用
- 分布式应用-服务按照功能拆分,使用微服务
- 分布式静态资源--静态资源放在不同的存储集群上分布式数据和存储--使用key-value缓存系统
- 分布式计算--对特殊业务使用分布式计算,比如Hadoop集群
1.3:集群和分布式
- 集群:同一个业务系统,部署在多台服务器上,集群中,每一台服务器实现的功能没有差别,数据 和代码都是一样的
- 分布式:一个业务被拆成多个子业务,或者本身就是不同的业务,部署在多台服务器上。分布式中,每一台服务器实现的功能是有差别的,数据和代码也是不一样的,分布式每台服务器功能加起来,才是完整的业务
- 分布式是以缩短单个任务的执行时间来提升效率的,而集群则是通过提高单位时间内执行的任务数 来提升效率,
- 对于大型网站,访问用户很多,实现一个群集,在前面部署一个负载均衡服务器,后面几台服务器 完成同一业务。如果有用户进行相应业务访问时,负载均衡器根据后端哪台服务器的负载情况,决 定由给哪一台去完成响应,并且台服务器垮了,其它的服务器可以顶上来。分布式的每一个节点, 都完成不同的业务,如果一个节点垮了,那这个业务可能就会失败
二:lvs(Linux virtual server)运行原理
2.1:lvs简介
LVS:Linux Virtual Server
,负载调度器,内核集成,章文嵩,阿里的四层
SLB(Server LoadBalance)
是基 于LVS+keepalived
实现
2.2:lvs概念
- VS:Virtual Server
- RS:Real Server
- CIP:Client IP
- VIP: Virtual serve IP VS外网的IP
- DIP: Director IP VS内网的IP
- RIP: Real server IP
访问流程:
CIP <--> VIP == DIP <--> RIP
2.3:lvs集群的类型
- lvs-nat:修改请求报文的目标IP,多目标IP的DNAT
- lvs-dr:操纵封装新的MAC地址
- lvs-tun:在原请求IP报文之外新加一个IP首部
- lvs-fullnat:修改请求报文的源和目标IP
三:NAT模式
3.1:Ivs-nat:
- 本质是多目标IP的DNAT,通过将请求报文中的目标地址和目标端口修改为某挑出的RS的RIP和 PORT实现转发
- RIP和DIP应在同一个IP网络,且应使用私网地址;RS的网关要指向DIP
- 请求报文和响应报文都必须经由Director转发,Director易于成为系统瓶颈
- 支持端口映射,可修改请求报文的目标PORT
- VS必须是Linux系统,RS可以是任意OS系统
3.2:部署NAT模式集群
3.21:架构图
3.22:实验前的环境准备
主机名 | ip | VIP | 角色 |
LVS | 192.168.0.100 | 172.25.254.100 | 调度器 |
webserver1 | 192.168.0.10 | null | RS1 |
webserver2 | 192.168.0.20 | null | RS2 |
cilent | null | 测试机 |
3.23:实验步骤
红帽9.2的LVS调度器的配置
1:更改网卡的名称为ethx
grubby --update-kernel ALL --args net.ifnames=0
然后重启主机生效:reboot
2:把主机的 /etc/ssh/sshd_config 的远程连接调为yes,不然xshell无法远程连接
然后重启服务生效,systemctl restart sshd
3:添加一个网卡,把第一个网卡调为nat模式,另一个网卡调为仅主机模式
4:基础环境网卡配置
[root@LVS ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=172.25.254.100/24,172.25.254.2
method=manual
dns=114.114.114.114;
[root@LVS ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
[connection]
id=eth1
type=ethernet
interface-name=eth1
[ipv4]
address1=192.168.0.100/24,
method=manual
!!!!!记得要删除eth1种的gateway和dns
5:在LVS种启用内核路由功能
[root@LVS ~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 0
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
[root@LVS ~]# vim /etc/sysctl.conf
[root@LVS ~]# vim /etc/sysctl.conf
[root@LVS ~]# sysctl -p
net.ipv4.ip_forward = 1
[root@LVS ~]#
红帽9.2的webserver1(仅主机模式)的配置
1:基础网卡配置
[root@webserver1 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=192.168.0.10/24,192.168.0.100
method=manual
[root@webserver1 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.100 0.0.0.0 UG 100 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@webserver1 ~]#
2:安装httpd服务,输入信息到网址里面(方便后续测试)并且开启服务
yum install httpd -y
echo webserver1 -192.168.0.10 > /var/www/html/index.html
systemctl enable --now httpd
3:关闭防火墙
systemctl stop firewalld
红帽9.2的webserver2(仅主机模式)的配置
1:基础网卡配置
[root@webserver2 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=192.168.0.20/24,192.168.0.100
method=manual
[root@webserver2 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.100 0.0.0.0 UG 100 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@webserver2 ~]#
2:安装httpd服务,输入信息到网址里面(方便后续测试)并且开启服务
yum install httpd -y
echo webserver2 -192.168.0.20 > /var/www/html/index.html
systemctl enable --now httpd
3:关闭防火墙
systemctl stop firewalld
在LVS种测试一下看看httpd服务是否成功了
[root@LVS ~]# curl 192.168.0.10
webserver1 -192.168.0.10
[root@LVS ~]# curl 192.168.0.20
webserver2 -192.168.0.20
[root@LVS ~]#
在LVS主机上的操作:
1:安装ipvsadm
yum install ipvsadm -y
2:添加调度策略
[root@LVS ~]# ipvsadm -A -t 172.25.254.100:80 -s wrr
[root@LVS ~]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m -w 1
[root@LVS ~]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m -w 2
[root@LVS ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.254.100:80 wrr
-> 192.168.0.10:80 Masq 1 0 0
-> 192.168.0.20:80 Masq 2 0 0
[root@LVS ~]#
客户端测试调度策略是否添加成功
以上操作均为临时,如果想开机启动
systemctl enable --now ipvsadm.service
NAT模式集群部署完成!!!!!!!!!!!!!
四:DR模式
4.1:DR简介
DR:Direct Routing,直接路由,LVS默认模式,应用最广泛,通过为请求报文重新封装一个MAC首部进行 转发,源MAC是DIP所在的接口的MAC,目标MAC是某挑选出的RS的RIP所在接口的MAC地址;源 IP/PORT,以及目标IP/PORT均保持不变
4.2:部署DR模式集群
4.21:架构图:
4.22:实验前的环境准备
主机名 | IP | vip | 角色 |
LVS | 192.168.0.50,GW:192.168.0.100 | 192.168.0.200 | 调度器 |
router | 172.25.254.100,GW:172.25.254.2 仅主机:192.168.0.100 | null | 路由器 |
cilent | 172.25.254.200,GW:172.25.254.100 | null | 客户端 |
websever1 | 192.168.0.10,GW:192.168.0.100 | 192.168.0.200 | RS3 |
webserver2 | 192.168.0.20,GW:192.168.0.100 | 192.168.0.200 | RS4 |
4.23 :实验步骤
一:红帽9.2的LVS的配置
[root@LVS ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
[connection]
id=eth1
type=ethernet
interface-name=eth1
[ipv4]
address1=192.168.0.50/24,192.168.0.100
method=manual
[root@LVS ~]#
二:红帽9.2的router的配置
添加一块网卡,eth0为NAT模式,eth1为仅主机模式
[root@router ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=172.25.254.100/24,172.25.254.2
method=manual
dns=114.114.114.114;
[root@router ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
[connection]
id=eth1
type=ethernet
interface-name=eth1
[ipv4]
address1=192.168.0.100/24,
method=manual
[root@router ~]#
三:在router种启用内核路由功能
[root@router ~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
四:cilent配置
[root@client ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=172.25.254.200/24,172.25.254.100
method=manual
[root@client ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.254.100 0.0.0.0 UG 100 0 0 eth0
172.25.254.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@client ~]#
五:webserver1和webserver2的配置
webserver1
[root@webserver1 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=192.168.0.10/24,192.168.0.100
method=manual
[root@webserver1 ~]#
webserver2
[root@webserver2 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-name=eth0
[ipv4]
address1=192.168.0.20/24,192.168.0.100
method=manual
[root@webserver2 ~]#
六:在主机webserver1和主机webserver2使VIP不对外响应
webserver1
[root@webserver1 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@webserver1 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@webserver1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@webserver1 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@webserver1 ~]#
webserver2
[root@webserver2 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@webserver2 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@webserver2 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@webserver2 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@webserver2 ~]#
七:在LVS和webserver1和webserver2上添加环回VIP
ip a a 192.168.0.200/32 dev lo
八:在LVS上添加调度策略
[root@LVS ~]# ipvsadm -A -t 192.168.0.200:80 -s wrr
[root@LVS ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.10:80 -g -w 1
[root@LVS ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.20:80 -g -w 2
[root@LVS ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.0.200:80 wrr
-> 192.168.0.10:80 Route 1 0 0
-> 192.168.0.20:80 Route 2 0 0
[root@LVS ~]#
九:测试一下
webserver2 -192.168.0.20
[root@client ~]# curl 192.168.0.200
webserver2 -192.168.0.20
[root@client ~]# curl 192.168.0.200
webserver1 -192.168.0.10
[root@client ~]# curl 192.168.0.200
webserver2 -192.168.0.20
[root@client ~]# curl 192.168.0.200
webserver2 -192.168.0.20
[root@client ~]# curl 192.168.0.200
webserver1 -192.168.0.10
测试成功!!!!!!!!!!!!!!!!!!!
五,防火墙标签解决轮询错误
也是本人亲写!!!!!!!!!!!!!分成了两部分书写,请看https://blog.csdn.net/qq_26553949/article/details/141037967