• Nginx 学习(九)集群概述与LVS工作模式的配置


     一  集群

    1  概述

    通过高速网络将很多服务器集中起来一起提供同一种服务,在客户端看来就像是只有一个服务器,可以在付出较低成本的情况下获得在性能、可靠性、灵活性方面的相对较高的收益,任务调度是集群系统中的核心技术。

    2  目的

    • 提高性能。如计算密集型应用,如:天气预报、核试验模拟
    • 降低成本。相对百万美元级的超级计算机,价格便宜
    • 提高可扩展性。只要增加集群节点即可
    • 增强可靠性。多个节点完成相同功能,避免单点失败

    3  分类

    高性能计算集群HP        通过以集群开发的并行应用程序,解决复杂的科学问题

    负载均衡(LB)集群         客户端负载在计算机集群中尽可能平均分摊。

    高可用(HA)集群            避免单点故障,当一个系统发生故障时,可以快速迁移。

    二  LVS

    1  概述

    Linux虚拟服务器 (LVS) 是章文嵩在国防科技大学就读博士期间创建的,可实现高可用的、可伸缩的Web、Mail、Cache和Media等网络服务,最终目标是利用Linux操作系统和LVS集群软件实现一个高可用、高性能、低成本的服务器应用集群。

    2  组成

    前端:负载均衡层。由一台或多台负载调度器构成

    中间:服务器群组层。由一组实际运行应用服务的服务器组成

    底端:数据共享存储层。提供共享存储空间的存储区域

    3  术语

    Director Server调度服务器将负载分发到Real Server的服务器
    Real Server真实服务器真正提供应用服务的服务器
    VIP虚拟IP地址公布给用户访问的虚拟IP地址
    VIP调度器连接后端节点服务器的IP地址
    RIP真实IP地址集群节点上使用的IP地址

    4  工作模式(三种)

     VS/NAT(网络地址转换)

    • 通过网络地址转换实现的虚拟服务器
    • 大并发访问时,调度器的性能成为瓶颈

    VS/DR(路由模式)

    • 直接使用路由技术实现虚拟服务器
    • 节点服务器需要配置VIP,注意MAC地址广播

    VS/TUN(隧道模式)

    • 通过隧道方式实现虚拟服务器

    5  负载均衡调度算法

    LVS目前实现了10种调度算法

    常见的4种调度算法

    轮询rrReal Server轮流提供服务
    加权轮询wrr根据服务器性能设置权重,权重大的得到的请求更多
    最少连接lc根据Real Server的连接数分配请求
    加权最少连接wlc类似于wrr,根据权重分配请求

     

     

     三  配置

     1  LVS NAT模式

    • 架构图

    • 环境准备

    client1eth0->192.168.88.10网关192.168.88.5
    lvs1

    eth0 -> 192.168.88.5

    eth1 -> 192.168.99.5

    web1eth1->192.168.99.100网关192.168.99.5
    web2eth1->192.168.99.200网关192.168.99.5
    1. # 创建4台虚拟机
    2. [root@myhost ~]# vm clone client1 lvs1 web{1..2}
    3. # 初始化虚拟机
    4. [root@myhost ~]# virsh console client1 # 连接client1控制台
    5. localhost login: root
    6. Password: a
    7. # 登陆之后,将以下内容粘贴到终端
    8. hostnamectl set-hostname client1
    9. nmcli connection modify "System eth0" con-name eth0
    10. nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.88.10/24 autoconnect yes ipv4.gateway 192.168.88.5
    11. nmcli connection down eth0
    12. nmcli connection up eth0
    13. # 退出
    14. [root@localhost ~]# exit
    15. # 退出之后,按ctrl+]可回到真机
    16. # 真机通过ssh连接client1
    17. [root@myhost ~]# rm -f ~/.ssh/known_hosts
    18. [root@myhost ~]# ssh 192.168.88.10
    19. # 配置第2台机器作为lvs1
    20. [root@myhost ~]# virsh console lvs1
    21. localhost login: root
    22. Password: a
    23. # 登陆之后,将以下内容复制到命令行
    24. hostnamectl set-hostname lvs1
    25. nmcli connection modify "System eth0" con-name eth0
    26. nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.88.5/24 autoconnect yes
    27. nmcli connection down eth0
    28. nmcli connection up eth0
    29. rm -f /etc/sysconfig/network-scripts/ifcfg-eth1
    30. nmcli connection add con-name eth1 ifname eth1 type ethernet autoconnect yes ipv4.method manual ipv4.addresses 192.168.99.5/24
    31. reboot # 重启系统,使得eth1网卡生效
    32. # 按ctrl+]可回到真机
    33. # 真机通过ssh连接lvs1
    34. [root@myhost ~]# ssh 192.168.88.5
    35. # 配置第3台机器作为web1
    36. [root@myhost ~]# virsh console web1
    37. localhost login: root
    38. Password: a
    39. # 登陆之后,将以下内容复制到命令行
    40. hostnamectl set-hostname web1
    41. nmcli connection modify "System eth0" con-name eth0
    42. nmcli connection modify eth0 autoconnect no
    43. rm -f /etc/sysconfig/network-scripts/ifcfg-eth1
    44. nmcli connection add con-name eth1 ifname eth1 type ethernet autoconnect yes ipv4.method manual ipv4.addresses 192.168.99.100/24 ipv4.gateway 192.168.99.5
    45. reboot
    46. # 按ctrl+]可回到真机
    47. # 真机通过ssh连接web1
    48. [root@myhost ~]# ssh 192.168.99.100
    49. # 配置第4台机器作为web2
    50. [root@myhost ~]# virsh console web2
    51. localhost login: root
    52. Password: a
    53. # 登陆之后,将以下内容复制到命令行
    54. hostnamectl set-hostname web2
    55. nmcli connection modify "System eth0" con-name eth0
    56. nmcli connection modify eth0 autoconnect no
    57. rm -f /etc/sysconfig/network-scripts/ifcfg-eth1
    58. nmcli connection add con-name eth1 ifname eth1 type ethernet autoconnect yes ipv4.method manual ipv4.addresses 192.168.99.200/24 ipv4.gateway 192.168.99.5
    59. reboot
    60. # 按ctrl+]可回到真机
    61. # 真机通过ssh连接web2
    62. [root@myhost ~]# ssh 192.168.99.200
    • 虚拟机已关闭selinux和防火墙 。
    • 在pubserver上准备管理环境
    1. # 创建工作目录
    2. [root@pubserver ~]# mkdir cluster
    3. [root@pubserver ~]# cd cluster/
    4. #创建主配置文件
    5. [root@pubserver cluster]# vim ansible.cfg
    6. [defaults]
    7. inventory = inventory
    8. host_key_checking = false # 不检查主机密钥
    9. # 创建主机清单文件及相关变量
    10. [root@pubserver cluster]# vim inventory
    11. [clients]
    12. client1 ansible_host=192.168.88.10
    13. [webservers]
    14. web1 ansible_host=192.168.99.100
    15. web2 ansible_host=192.168.99.200
    16. [lb]
    17. lvs1 ansible_host=192.168.88.5
    18. [all:vars] # all是ansible自带的组,表示全部主机
    19. ansible_ssh_user=root
    20. ansible_ssh_pass=a
    21. # 创建文件目录,用于保存将要拷贝到远程主机的文件
    22. [root@pubserver cluster]# mkdir files
    23. # 编写yum配置文件
    24. [root@pubserver cluster]# vim files/local88.repo
    25. [BaseOS]
    26. name = BaseOS
    27. baseurl = ftp://192.168.88.240/dvd/BaseOS
    28. enabled = 1
    29. gpgcheck = 0
    30. [AppStream]
    31. name = AppStream
    32. baseurl = ftp://192.168.88.240/dvd/AppStream
    33. enabled = 1
    34. gpgcheck = 0
    35. [rpms]
    36. name = rpms
    37. baseurl = ftp://192.168.88.240/rpms
    38. enabled = 1
    39. gpgcheck = 0
    40. [root@pubserver cluster]# vim files/local99.repo
    41. [BaseOS]
    42. name = BaseOS
    43. baseurl = ftp://192.168.99.240/dvd/BaseOS
    44. enabled = 1
    45. gpgcheck = 0
    46. [AppStream]
    47. name = AppStream
    48. baseurl = ftp://192.168.99.240/dvd/AppStream
    49. enabled = 1
    50. gpgcheck = 0
    51. [rpms]
    52. name = rpms
    53. baseurl = ftp://192.168.99.240/rpms
    54. enabled = 1
    55. gpgcheck = 0
    56. # 编写用于上传yum配置文件的playbook
    57. [root@pubserver cluster]# vim 01-upload-repo.yml
    58. ---
    59. - name: config repos.d
    60. hosts: all
    61. tasks:
    62. - name: delete repos.d # 删除repos.d目录
    63. file:
    64. path: /etc/yum.repos.d
    65. state: absent
    66. - name: create repos.d # 创建repos.d目录
    67. file:
    68. path: /etc/yum.repos.d
    69. state: directory
    70. mode: '0755'
    71. - name: config local88 # 上传repo文件到88网段
    72. hosts: clients,lb
    73. tasks:
    74. - name: upload local88
    75. copy:
    76. src: files/local88.repo
    77. dest: /etc/yum.repos.d/
    78. - name: config local99 # 上传repo文件到99网段
    79. hosts: webservers
    80. tasks:
    81. - name: upload local99
    82. copy:
    83. src: files/local99.repo
    84. dest: /etc/yum.repos.d/
    85. [root@pubserver cluster]# ansible-playbook 01-upload-repo.yml

    2  配置LVS NAT模式步骤 

    <1> 操作流程

    Real Server:

            -  配置WEB服务器

    Director Server:

            -  在上安装并启用ipvsadm- 创建虚拟服务器

            -  向虚拟服务器中加入节点

    Client:

            -  连接虚拟服务器测试

    <2> 实施

    • 配置2台web服务器
    1. # 创建首页文件,文件中包含ansible facts变量
    2. [root@pubserver cluster]# vim files/index.html
    3. Welcome from {{ansible_hostname}}
    4. # 配置web服务器
    5. [root@pubserver cluster]# vim 02-config-webservers.yml
    6. ---
    7. - name: config webservers
    8. hosts: webservers
    9. tasks:
    10. - name: install nginx # 安装nginx
    11. yum:
    12. name: nginx
    13. state: present
    14. - name: upload index # 上传首页文件到web服务器
    15. template:
    16. src: files/index.html
    17. dest: /usr/share/nginx/html/index.html
    18. - name: start nginx # 启动服务
    19. service:
    20. name: nginx
    21. state: started
    22. enabled: yes
    23. [root@pubserver cluster]# ansible-playbook 02-config-webservers.yml
    24. # 在lvs1上测试到web服务器的访问
    25. [root@lvs1 ~]# curl http://192.168.99.100
    26. Welcome from web1
    27. [root@lvs1 ~]# curl http://192.168.99.200
    28. Welcome from web2
    • 确保lvs1的ip转发功能已经打开。该功能需要改变内核参数
    1. # 查看ip转发功能的内核参数
    2. [root@lvs1 ~]# sysctl -a # 查看所有的内核参数
    3. [root@lvs1 ~]# sysctl -a | grep ip_forward # 查看ip_foward参数
    4. net.ipv4.ip_forward = 1 # 1表示打开转发,0表示关闭转发
    5. # 设置打开ip_forward功能
    6. [root@pubserver cluster]# vim 03-sysctl.yml
    7. ---
    8. - name: config sysctl
    9. hosts: lb
    10. tasks:
    11. - name: set ip_forward
    12. sysctl: # 用于修改内核参数的模块
    13. name: net.ipv4.ip_forward # 内核模块名
    14. value: '1' # 内核模块的值
    15. sysctl_set: yes # 立即设置生效
    16. sysctl_file: /etc/sysctl.conf # 配置写入文件
    17. [root@pubserver cluster]# ansible-playbook 03-sysctl.yml
    18. # 测试从客户端到服务器的访问
    19. [root@client1 ~]# curl http://192.168.99.100
    20. Welcome from web1
    21. [root@client1 ~]# curl http://192.168.99.200
    22. Welcome from web2
    • 安装LVS
    1. [root@pubserver cluster]# vim 04-inst-lvs.yml
    2. ---
    3. - name: install lvs
    4. hosts: lb
    5. tasks:
    6. - name: install lvs # 安装lvs
    7. yum:
    8. name: ipvsadm
    9. state: present
    10. [root@pubserver cluster]# ansible-playbook 04-inst-lvs.yml

    ipvsadm使用说明

    1. -A: 添加虚拟服务器
    2. -E: 编辑虚拟服务器
    3. -D: 删除虚拟服务器
    4. -t: 添加tcp服务器
    5. -u: 添加udp服务器
    6. -s: 指定调度算法。如轮询rr/加权轮询wrr/最少连接lc/加权最少连接wlc
    7. -a: 添加虚拟服务器后,向虚拟服务器中加入真实服务器
    8. -r: 指定真实服务器
    9. -w: 设置权重
    10. -m: 指定工作模式为NAT
    11. -g: 指定工作模式为DR

    ipvsadm命令用法

    1. 使用命令添加基于TCP一些的集群服务
    2. 在集群中添加若千台后端真实服务器
    3. 实现同一客户端访问,调度器分配固定服务器
    4. 会使用ipvsadm实现规则的增、删、改保存ipvsadm规则
    • 配置LVS
    1. # 为web服务器创建虚拟服务器,使用rr调度算法
    2. [root@lvs1 ~]# ipvsadm -A -t 192.168.88.5:80 -s rr
    3. # 查看配置
    4. [root@lvs1 ~]# ipvsadm -Ln # L是列出,n是使用数字,而不是名字
    5. # 向虚拟服务器中添加RIP
    6. [root@lvs1 ~]# ipvsadm -a -t 192.168.88.5:80 -r 192.168.99.100 -w 1 -m
    7. [root@lvs1 ~]# ipvsadm -a -t 192.168.88.5:80 -r 192.168.99.200 -w 2 -m
    8. # 查看配置
    9. [root@lvs1 ~]# ipvsadm -Ln
    10. # 验证
    11. [root@client1 ~]# for i in {1..6}
    12. > do
    13. > curl http://192.168.88.5
    14. > done
    15. Welcome from web2
    16. Welcome from web1
    17. Welcome from web2
    18. Welcome from web1
    19. Welcome from web2
    20. Welcome from web1
    21. # 删除配置。(如果配置有错,用以下命令删除重配置)
    22. [root@lvs1 ~]# ipvsadm -D -t 192.168.88.5:80
    23. # 修改调度模式为加权轮询
    24. [root@lvs1 ~]# ipvsadm -E -t 192.168.88.5:80 -s wrr
    25. # 验证配置
    26. [root@client1 ~]# for i in {1..6}; do curl http://192.168.88.5; done
    27. Welcome from web2
    28. Welcome from web2
    29. Welcome from web1
    30. Welcome from web2
    31. Welcome from web2
    32. Welcome from web1

    3  LVS DR模式

    • 架构图

    • LVS DR模式,LVS主机和web服务器都是单网卡。它们连在同一网络中

    • 修改实验环境

    client1eth0-> 192.168.88.10
    lvs1eth0->192.168.88.5删除eth1的IP
    web1eth0->192.168.88.100删除eth1的IP
    web2eth0->192.168.88.200删除eth1的IP
    1. # 删除lvs虚拟服务器配置
    2. [root@lvs1 ~]# ipvsadm -D -t 192.168.88.5:80
    3. [root@lvs1 ~]# ipvsadm -Ln
    4. # 删除lvs1上eth1的配置
    5. [root@lvs1 ~]# nmcli connection modify eth1 ipv4.method disabled ipv4.addresses ''
    6. [root@lvs1 ~]# nmcli connection down eth1
    7. # 修改web1的配置:停掉eth1的地址。配置eth0的地址为192.168.88.100
    8. # 进入网卡配置文件目录
    9. [root@web1 ~]# cd /etc/sysconfig/network-scripts/
    10. # eth0网卡的配置文件叫ifcfg-eth0
    11. [root@web1 network-scripts]# ls ifcfg-eth*
    12. ifcfg-eth0 ifcfg-eth1
    13. # 配置eth0地址
    14. [root@web1 network-scripts]# vim ifcfg-eth0
    15. TYPE=Ethernet # 网络类型为以太网
    16. BOOTPROTO=none # IP地址是静态配置的,也可以用static
    17. NAME=eth0 # 为设备重命名
    18. DEVICE=eth0 # 网卡设备名
    19. ONBOOT=yes # 开机激活网卡
    20. IPADDR=192.168.88.100 # IP地址
    21. PREFIX=24 # 子网掩码长度
    22. GATEWAY=192.168.88.254 # 网关
    23. [root@web1 ~]# systemctl restart NetworkManager # 重启网络服务
    24. # 在web1上停掉eth1
    25. [root@web1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
    26. TYPE=Ethernet
    27. BOOTPROTO=none
    28. NAME=eth1
    29. DEVICE=eth1
    30. ONBOOT=no
    31. [root@web1 ~]# nmcli connection down eth1 # 终端卡住,关掉它,在新终端重新连
    32. # 修改web2的网络
    33. [root@web2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
    34. TYPE=Ethernet
    35. BOOTPROTO=none
    36. NAME=eth0
    37. DEVICE=eth0
    38. ONBOOT=yes
    39. IPADDR=192.168.88.200
    40. PREFIX=24
    41. GATEWAY=192.168.88.254
    42. [root@web2 ~]# systemctl restart NetworkManager
    43. [root@web2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
    44. TYPE=Ethernet
    45. BOOTPROTO=none
    46. NAME=eth1
    47. DEVICE=eth1
    48. ONBOOT=no
    49. [root@web2 ~]# nmcli connection down eth1
    50. # 修改pubserver的主机清单文件
    51. [root@pubserver cluster]# cp inventory inventory.bak
    52. [root@pubserver cluster]# vim inventory
    53. [clients]
    54. client1 ansible_host=192.168.88.10
    55. [webservers]
    56. web1 ansible_host=192.168.88.100
    57. web2 ansible_host=192.168.88.200
    58. [lb]
    59. lvs1 ansible_host=192.168.88.5
    60. [all:vars]
    61. ansible_ssh_user=root
    62. ansible_ssh_pass=a
    63. # 修改2台web服务器yum配置文件中的地址
    64. [root@web1 ~]# sed -i 's/99/88/' /etc/yum.repos.d/local99.repo
    65. [root@web1 ~]# cat /etc/yum.repos.d/local99.repo
    66. [BaseOS]
    67. name = BaseOS
    68. baseurl = ftp://192.168.88.240/dvd/BaseOS
    69. enabled = 1
    70. gpgcheck = 0
    71. [AppStream]
    72. name = AppStream
    73. baseurl = ftp://192.168.88.240/dvd/AppStream
    74. enabled = 1
    75. gpgcheck = 0
    76. [rpms]
    77. name = rpms
    78. baseurl = ftp://192.168.88.240/rpms
    79. enabled = 1
    80. gpgcheck = 0

    4  配置LVS DR模式

    <1>操作流程

    Real Server

            - 配置WEB服务器

            - 配置辅助IP地址、调整内核参数

    Director Server

            - 在上安装并启用ipvsadml

            - 配置辅助IP地址

            - 创建虚拟服务器、向虚拟服务器中加入节点

    Client:

            - 连接虚拟服务器测试

    <2>  ARP广播的问题

    当客户端发起访问VIP对应的域名的请求时,根据网络通信原理会产生ARP广播

    因为负载均衡器和真实的服务器在同一网络并且VIP设置在集群中的每个节点上

    此时集群内的真实服务器会尝试回答来自客户端的ARP广播,这就会产生问题,大家都说我是VIP

    <3>  内核参数说明

    arp_ignore(定义回复ARP广播的方式)

    -0:回应所有的本地地址ARP广播,本地地址可以配置在任意网络接口(默认值)

    -1:只回应配置在入站网卡接口上的任意IP地址的ARP广播

    arp_announce

    -0:使用配置在任意网卡接口上的本地IP地址

    -2:对查询目标使用最适当的本地地址。在此模式下将忽略这个IP数据包的源地址并尝试选择与能与该地址通信的本地地址。首要是选择所有的网络接口的子网中外出访问子网中包含该目标IP地址的本地地址。如果没有合适的地址被发现,将选择当前的发送网络接口或其他的有可能接受到该ARP回应的网络接口来进行发送

    <4> 配置

    • 在lvs1的eth0上配置vip 192.168.88.15。
    1. [root@pubserver cluster]# vim 05-config-lvsvip.yml
    2. ---
    3. - name: config lvs vip
    4. hosts: lb
    5. tasks:
    6. - name: add vip
    7. lineinfile: # 确保文件中有某一行内容
    8. path: /etc/sysconfig/network-scripts/ifcfg-eth0
    9. line: IPADDR2=192.168.88.15
    10. notify: restart eth0 # 通知执行handlers中的任务
    11. handlers: # 被通知执行的任务写到这里
    12. - name: restart eth0
    13. shell: nmcli connection down eth0; nmcli connection up eth0
    14. [root@pubserver cluster]# ansible-playbook 05-config-lvsvip.yml
    15. # 在lvs1查看添加的IP地址
    16. [root@lvs1 ~]# ip a s eth0 | grep 88
    17. inet 192.168.88.5/24 brd 192.168.88.255 scope global noprefixroute eth0
    18. inet 192.168.88.15/24 brd 192.168.88.255 scope global secondary noprefixroute eth0
    • 在2台web服务器的lo上配置vip 192.168.88.15。lo:0网卡需要使用network-scripts提供的配置文件进行配置。
    1. [root@pubserver cluster]# vim 06-config-webvip.yml
    2. ---
    3. - name: config webservers vip
    4. hosts: webservers
    5. tasks:
    6. - name: install network-scripts # 安装服务
    7. yum:
    8. name: network-scripts
    9. state: present
    10. - name: add lo:0 # 创建lo:0的配置文件
    11. copy:
    12. dest: /etc/sysconfig/network-scripts/ifcfg-lo:0
    13. content: |
    14. DEVICE=lo:0
    15. NAME=lo:0
    16. IPADDR=192.168.88.15
    17. NETMASK=255.255.255.255
    18. NETWORK=192.168.88.15
    19. BROADCAST=192.168.88.15
    20. ONBOOT=yes
    21. notify: activate lo:0
    22. handlers:
    23. - name: activate lo:0 # 激活网卡
    24. shell: ifup lo:0
    25. [root@pubserver cluster]# ansible-playbook 06-config-webvip.yml
    26. # 查看结果
    27. [root@web1 ~]# cd /etc/sysconfig/network-scripts/
    28. [root@web1 network-scripts]# cat ifcfg-lo:0
    29. DEVICE=lo:0
    30. NAME=lo:0
    31. IPADDR=192.168.88.15
    32. NETMASK=255.255.255.255
    33. NETWORK=192.168.88.15
    34. BROADCAST=192.168.88.15
    35. ONBOOT=yes
    36. [root@web1 network-scripts]# ifconfig # 可以查看到lo:0网卡信息
    37. lo:0: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
    38. inet 192.168.88.15 netmask 255.255.255.255
    39. loop txqueuelen 1000 (Local Loopback)
    • 在2台web服务器上配置内核参数,使得它们不响应对192.168.88.15的请求
    1. [root@web1 ~]# sysctl -a | grep arp_ignore
    2. net.ipv4.conf.all.arp_ignore = 1
    3. net.ipv4.conf.lo.arp_ignore = 0
    4. [root@web1 ~]# sysctl -a | grep arp_announce
    5. net.ipv4.conf.all.arp_announce = 2
    6. net.ipv4.conf.lo.arp_announce = 0
    7. [root@web1 ~]# vim /etc/sysctl.conf
    8. net.ipv4.conf.all.arp_ignore = 1
    9. net.ipv4.conf.lo.arp_ignore = 1
    10. net.ipv4.conf.all.arp_announce = 2
    11. net.ipv4.conf.lo.arp_announce = 2
    12. [root@web1 ~]# sysctl -p
    13. [root@web2 ~]# vim /etc/sysctl.conf
    14. net.ipv4.conf.all.arp_ignore = 1
    15. net.ipv4.conf.lo.arp_ignore = 1
    16. net.ipv4.conf.all.arp_announce = 2
    17. net.ipv4.conf.lo.arp_announce = 2
    18. [root@web2 ~]# sysctl -p
    • 在lvs1上配置虚拟服务器
    1. # 创建虚拟服务器
    2. [root@lvs1 ~]# ipvsadm -A -t 192.168.88.15:80 -s wlc
    3. # 向虚拟服务器中加真实服务器
    4. [root@lvs1 ~]# ipvsadm -a -t 192.168.88.15:80 -r 192.168.88.100 -w 1 -g
    5. [root@lvs1 ~]# ipvsadm -a -t 192.168.88.15:80 -r 192.168.88.200 -w 2 -g
    6. # 查看配置
    7. [root@lvs1 ~]# ipvsadm -Ln
    8. # 客户验证
    9. [root@client1 ~]# for i in {1..6}; do curl http://192.168.88.15/; done
    10. Welcome from web2
    11. Welcome from web1
    12. Welcome from web2
    13. Welcome from web2
    14. Welcome from web1
    15. Welcome from web2

    附:出错时,排错步骤:

    1. # 在lvs上可以访问到web服务器
    2. [root@lvs1 ~]# curl http://192.168.88.100/
    3. 192.168.99.100
    4. [root@lvs1 ~]# curl http://192.168.88.200/
    5. apache web server2
    6. # 查看vip
    7. [root@lvs1 ~]# ip a s eth0 | grep 88
    8. inet 192.168.88.5/24 brd 192.168.88.255 scope global noprefixroute eth0
    9. inet 192.168.88.15/24 brd 192.168.88.255 scope global secondary noprefixroute eth0
    10. [root@web1 ~]# ifconfig lo:0
    11. lo:0: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
    12. inet 192.168.88.15 netmask 255.255.255.255
    13. loop txqueuelen 1000 (Local Loopback)
    14. # 查看内核参数
    15. [root@web1 ~]# sysctl -p
    16. net.ipv4.conf.all.arp_ignore = 1
    17. net.ipv4.conf.lo.arp_ignore = 1
    18. net.ipv4.conf.all.arp_announce = 2
    19. net.ipv4.conf.lo.arp_announce = 2
    20. # 查看规则
    21. [root@lvs1 ~]# ipvsadm -Ln
    22. IP Virtual Server version 1.2.1 (size=4096)
    23. Prot LocalAddress:Port Scheduler Flags
    24. -> RemoteAddress:Port Forward Weight ActiveConn InActConn
    25. TCP 192.168.88.15:80 wlc
    26. -> 192.168.88.100:80 Route 1 0 12
    27. -> 192.168.88.200:80 Route 2 0 18

  • 相关阅读:
    法国博士后招聘|国家健康与医学研究院(INSERM)-计算化学
    flutter 设置全屏 和隐藏状态栏和导航栏
    ufw配置:外网ip禁止访问配置
    4.SpringCloud基础项目搭建利用RestTemplate实现远程调用
    在ubuntu18.04上安装pangolin
    用项目管理管PMP考试我该如何准备?
    经验分享丨中小企业如何低成本开发APP
    FFplay文档解读-22-音频过滤器七
    rxjs Observable 两大类操作符简介
    这次主要的配置
  • 原文地址:https://blog.csdn.net/2301_79227925/article/details/132631282