18.6 负载均衡集群介绍;18.7 LVS介绍;18.9 LVS NAT模式搭建(上);18.10 LVS NAT模式搭建(下)

简介:

扩展:

lvs 三种模式详解  

http://www.it165.net/admin/html/201401/2248.html

lvs几种算法 

http://www.aminglinux.com/bbs/thread-7407-1-1.html

关于arp_ignore和 arp_announce 

http://www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html

lvs原理相关的   http://blog.csdn.net/pi9nc/article/details/23380589

18.6 负载均衡集群介绍

1. 主流开源软件LVS、keepalived、haproxy、nginx等

2. 其中LVS属于4层(网络OSI 7层模型),nginx属于7层,haproxy既可以认为是4层,也可以当做7层使用

3. keepalived的负载均衡功能其实就是lvs

4. lvs这种4层的负载均衡是可以分发除80外的其他端口通信的,比如MySQL的,而nginx仅仅支持http,https,mail,haproxy也支持MySQL这种

5. 相比较来说,LVS这种4层的更稳定,能承受更多的请求,而nginx这种7层的更加灵活,能实现更多的个性化需求

18.7 LVS介绍;

1. LVS是由国人章文嵩开发

2. 流行度不亚于apache的httpd,基于TCP/IP做的路由和转发,稳定性和效率很高

3. LVS最新版本基于Linux内核2.6,有好多年不更新了

4. LVS有三种常见的模式:NAT、DR、IP Tunnel

5. LVS架构中有一个核心角色叫做分发器(Load balance),它用来分发用户的请求,还有诸多处理用户请求的服务器(Real Server,简称rs)

wKioL1muoyjBoUZrAAIVPY95NEk964.pngwKiom1muo1iDrzo2AAILAvIiWyw815.pngwKiom1muo22w93MqAALLUqMFHyc009.png18.8 LVS的调度算法

前四条算法较为重要!!!

1. 轮询 Round-Robin  rr

2. 加权轮询 Weight Round-Robin wrr

3. 最小连接 Least-Connection lc

4. 加权最小连接 Weight Least-Connection wlc

5. 基于局部性的最小连接 Locality-Based Least Connections lblc

6. 带复制的基于局部性最小连接 Locality-Based Least Connections with Replication  lblcr

7. 目标地址散列调度 Destination Hashing dh

8. 源地址散列调度 Source Hashing  sh

18.9 LVS NAT模式搭建(上)

NAT模式搭建 – 准备工作

准备三台机器:hao1  hao2  hao3

hao1机器操作:

hao1机器作为分发器,也叫调度器(简写为dir)

1. 添加一个新网卡选择仅主机模式

ens33网卡内网:192.168.211.128(ANT模式)

ens37网卡外网:192.168.47.128(仅主机模式)

wKioL1muo23i0NlrAACdEdwStpY370.png2.编辑ens37网卡配置文件:

[root@hao-01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens37

设定ip为(仅主机网段): 192.168.47.128

添加内容(不用设置网关):

NAME=ens37

DEVICE=ens37

ONBOOT=no

IPADDR=192.168.47.128

PREFIX=24

wKiom1muo6KR5_pKAABhSTjRBrA805.png

3. 重启网络服务命令:(重启network.service网络服务)

[root@hao-01 ~]# systemctl restart network.service

4. 激活ens37网卡

[root@hao-01 ~]# ifup ens37

5. 在windows系统,pingens37(仅主机)外网ip

wKiom1muo7jhN34pAAA6qt7s0ks065.png

hao1   hao2   hao3机器都要执行下面关闭防火墙命令:

1. 关闭firewalld防火墙:

[root@hao-01 ~]# systemctl stop firewalld

设定开机不启动firewalld防火墙:

[root@hao-01 ~]# systemctl disable firewalld

查看firewalld防火墙是否关闭

[root@hao-01 ~]# iptables -nvL

wKiom1muo82y4G4xAAA4oDOirnI038.png2. 安装centos 6系统中的iptables防火墙工具:

[root@hao-01 ~]# yum install -y iptables-services

如果上面安装慢,临时重命名epel.repo,再yum 安装

(记得改回重命名!):

mv /etc/yum.repos.d/epel.repo  /etc/yum.repos.d/epel.repo1

启用iptables

[root@hao-01 ~]# systemctl enable iptables

开启iptables

[root@hao-01 ~]# systemctl start iptables

清除防火墙规则

[root@hao-01 ~]# iptables -F

关闭iptables

[root@hao-01 ~]# service iptables save

查看firewalld防火墙是否关闭

[root@hao-01 ~]# iptables -nvL

wKioL1muo8uj7z2-AAA4oDOirnI243.png3. 临时关闭getenforce防火墙

[root@hao-01 ~]# setenforce 0

永久关闭getenforce防火墙:

[root@hao-01 ~]# vi /etc/selinux/config

更改内容:

SELINUX=disabled

wKiom1muo_3BRkjTAABJjznxqzw138.pnghao2   hao3机器上操作:

ens33网卡网关改成ip段内网段iphao1内网ip(128)

1. 更改hao2机器ens33网卡配置文件:

[root@hao-02 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33

wKioL1muo_qDr4auAAAQwVpCgIQ597.png

重启网卡:

[root@hao-02 ~]# systemctl restart network

2. 更改hao3机器ens33网卡配置文件:

[root@hao-03 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33

wKiom1mupCyRO-ihAAAQ-z04_lU641.png

重启网卡:

[root@hao-03 ~]# systemctl restart network

18.10 LVS NAT模式搭建(下)

hao1机器(dir)上操作:

1. 在hao1机器(dir)上,安装 ipvsadm

[root@hao-01 ~]# yum install -y ipvsadm

2. 在hao1机器(dir)上,编写lvs_nat.sh脚本:

[root@hao-01 ~]# vim /usr/local/sbin/lvs_nat.sh

添加内容:

#! /bin/bash

# director 服务器上开启路由转发功能

echo 1 > /proc/sys/net/ipv4/ip_forward

# 关闭icmp的重定向

echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects

echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects

# 注意区分网卡名字,阿铭的两个网卡分别为ens33和ens37

echo 0 > /proc/sys/net/ipv4/conf/ens33/send_redirects

echo 0 > /proc/sys/net/ipv4/conf/ens37/send_redirects

# director 设置nat防火墙

iptables -t nat -F

iptables -t nat -X

iptables -t nat -A POSTROUTING -s 192.168.211.0/24  -j MASQUERADE

# director设置ipvsadm

IPVSADM='/usr/sbin/ipvsadm'

$IPVSADM -C

$IPVSADM -A -t 192.168.47.128:80 -s rr

$IPVSADM -a -t 192.168.47.128:80 -r 192.168.211.129:80 -m -w 1

$IPVSADM -a -t 192.168.47.128:80 -r 192.168.211.130:80 -m -w 1

wKiom1mupEGgTdDlAACwywtymHQ355.png3. 执行lvs_nat.sh脚本:

[root@hao-01 ~]# sh /usr/local/sbin/lvs_nat.sh

hao2机器(r)上操作:

1. 启动nginx(yum安装的nginx):

[root@hao-02 ~]# systemctl start nginx

2. 搜索nginx是否启动?

[root@hao-02 ~]# ps aux |grep nginx

3. 清空index.html内容(yum安装的nginx):

[root@hao-02 ~]# > /usr/share/nginx/html/index.html

4. 编辑index.html(yum安装的nginx):

[root@hao-02 ~]# vim /usr/share/nginx/html/index.html

添加内容(便于和hao3区分):

hao2

5. 查看:

[root@hao-02 ~]# curl localhost

hao3机器(r)上操作:

1. 启动nginx(yum安装的nginx):

[root@hao-03 ~]# systemctl start nginx

2. 搜索nginx是否启动?

[root@hao-03 ~]# ps aux |grep nginx

3. 清空index.html内容(yum安装的nginx):

[root@hao-03 ~]# > /usr/share/nginx/html/index.html

4. 编辑index.html(yum安装的nginx):

[root@hao-03 ~]# vim /usr/share/nginx/html/index.html

添加内容(便于和hao2区分):

hao3

5. 查看:

[root@hao-03 ~]# curl localhost

hao1机器(dir)上操作测试

1. curl访问hao1机器(dir) ens37外网ip

[root@hao-01 ~]# curl 192.168.47.128










本文转自 主内安详 51CTO博客,原文链接:http://blog.51cto.com/zhuneianxiang/1962940,如需转载请自行联系原作者
相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
目录
相关文章
|
19天前
|
域名解析 移动开发 负载均衡
阿里云DNS常见问题之DNS负载均衡调加权模式失败如何解决
阿里云DNS(Domain Name System)服务是一个高可用和可扩展的云端DNS服务,用于将域名转换为IP地址,从而让用户能够通过域名访问云端资源。以下是一些关于阿里云DNS服务的常见问题合集:
|
4月前
|
负载均衡 网络协议 网络架构
VRRP负载均衡模式配置实用吗?
VRRP负载均衡模式配置实用吗?
64 0
|
4月前
|
网络协议 Linux 网络架构
Linux三种网络模式 | 仅主机、桥接、NAT
Linux三种网络模式 | 仅主机、桥接、NAT
164 0
|
5月前
|
负载均衡 应用服务中间件 Linux
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
164 0
|
7天前
|
Linux 虚拟化
VMware workstation 中centos7虚拟机在nat模式下怎么配置网卡,指定我想要的IP并且可以联网
https://blog.csdn.net/2302_78534730/article/details/132825156?spm=1001.2014.3001.5502
131 0
|
3月前
|
网络协议 虚拟化 网络架构
桥接模式和NAT模式的区别
桥接模式和NAT模式的区别
|
3月前
|
网络安全 虚拟化 Windows
RHEL7-NAT模式连接外部网络
RHEL7-NAT模式连接外部网络
22 1
|
3月前
|
Kubernetes 负载均衡 监控
Kubernetes高可用集群二进制部署(一)主机准备和负载均衡器安装
Kubernetes高可用集群二进制部署(一)主机准备和负载均衡器安装
|
3月前
|
缓存 负载均衡 应用服务中间件
【分布式技术专题】「分析Web服务器架构」Tomcat服务器的运行架构和LVS负载均衡的运行机制(修订版)
在本章内容中,我们将深入探讨 Tomcat 服务器的运行架构、LVS 负载均衡的运行机制以及 Cache 缓存机制,并提供相应的解决方案和指导。通过理解这些关键概念和机制,您将能够优化您的系统架构,提高性能和可扩展性。
203 4
【分布式技术专题】「分析Web服务器架构」Tomcat服务器的运行架构和LVS负载均衡的运行机制(修订版)
|
4月前
|
负载均衡 监控 算法
负载均衡一般用什么模式
负载均衡可以采用多种模式,具体的选择取决于应用程序的需求、架构设计和性能目标。以下是一些常见的负载均衡模式: 1. **轮询(Round Robin):** 请求依次分发到每个后端服务器,循环进行。这是一种简单的负载均衡算法,适用于后端服务器性能相对均衡的情况。 2. **加权轮询(Weighted Round Robin):** 类似于轮询,但可以为每个后端服务器分配不同的权重,以便更灵活地分配负载。性能更高的服务器可以分配更高的权重。 3. **最小连接数(Least Connections):** 请求分发到当前连接数最少的后端服务器。这可以确保负载更平均地分布到服务器上,适用于处
137 0