分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

LVS-DR+Keepalived+httpd(双主)

发布时间:2023-09-06 02:04责任编辑:赖小花关键词:http

LVS-DR + Keepalived双主配置

  • 网络拓扑图如下

  • 准备RealServer(RS服务器)配置
    这里RS上准备http服务作为应用验证,在实际生产中两台RS服务器应该具有相同资源实现冗余。这里为了测试验证,故意将被访问资源设置成不同,以方便验证。

  1. 两台RS服务器上执行yum install httpd -y安装httpd应用程序(两台都要执行,前提是系统已配置yum仓库)
  2. 准备网络环境,要求LVS和RS服务器必须在同一个物理网络。
  3. RS服务器通过内核屏蔽arp报文广播及响应,为此编辑以下脚本实现(这是为了以后使用方便,如果是一次性验证直接敲命令也可以)。

  4. 两台RS服务器都运行以上脚本后检查状态如下:
    检查IP设置

    检查内核参数

  5. 验证RS http服务可用


    从客户端直接访问RS http服务资源,以确保RS 正常提供服务。

  • 准备Director调度服务器(LVS-DR+keepalived)

  1. 安装软件
  2. 修改Director1的keepalived配置文件
    ! Configuration File for keepalived
    global_defs {
    notification_email {
    root@localhost
    }
    notification_email_from Alexandre.Cassen@firewall.loc
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id LVS_DEVEL
    vrrp_mcast_group4 224.0.4.223
    }
    vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 163
    priority 100
    advert_int 1
    authentication {
    ???auth_type PASS
    ???auth_pass 11112222
    }
    virtual_ipaddress {
    ???192.168.30.100
    }
    }
    virtual_server 192.168.30.100 80 {
    delay_loop 2
    lb_algo rr
    lb_kind DR
    protocol TCP
    real_server 192.168.30.23 80 {
    ???weight 1
    ???HTTP_GET {
    ???????url {
    ???????????path /
    ???????????status_code 200
    ???????}
    ???????connect_timeout 1
    ???????nb_get_retry 3
    ???????delay_before_retry 1
    ???}
    }
    real_server 192.168.30.24 80 {
    ???weight 1
    ???HTTP_GET {
    ???????url {
    ?????????path /
    ?????????status_code 200
    ???????}
    ???????connect_timeout 1
    ???????nb_get_retry 3
    ???????delay_before_retry 1
    ???}
    }
    }
    vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 126
    priority 95
    advert_int 1
    authentication {
    ???auth_type PASS
    ???auth_pass 11112222
    }
    virtual_ipaddress {
    ???192.168.30.200
    }
    }
    virtual_server 192.168.30.200 80 {
    delay_loop 2
    lb_algo rr
    lb_kind DR
    protocol TCP
    real_server 192.168.30.23 80 {
    ???weight 1
    ???HTTP_GET {
    ???????url {
    ???????????path /
    ???????????status_code 200
    ???????}
    ???????connect_timeout 1
    ???????nb_get_retry 3
    ???????delay_before_retry 1
    ???}
    }
    real_server 192.168.30.24 80 {
    ???weight 1
    ???HTTP_GET {
    ???????url {
    ?????????path /
    ?????????status_code 200
    ???????}
    ???????connect_timeout 1
    ???????nb_get_retry 3
    ???????delay_before_retry 1
    ???}
    }
    }

  3. 修改Director2的keepalived配置文件,只需要修改以下黑体部分,其它部分不变
    vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 163
    priority 95
    advert_int 1
    authentication {
    ???auth_type PASS
    ???auth_pass 11112222
    }
    virtual_ipaddress {
    ???192.168.30.100
    }
    }
    vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 126
    priority 100
    advert_int 1
    authentication {
    ???auth_type PASS
    ???auth_pass 11112222
    }
    virtual_ipaddress {
    ???192.168.30.200
    }
    }

  4. 启动keepalived


    两台Director查看ipvs状态

  5. 客户端访问验证
    a. 访问两个VIP地址都能成功访问http资源,并且实现轮询调度

    b. 客户端持续访问过程中 关闭RS1的http服务,看能否自动调度到RS2并且从ipvs中剔除RS1

    ipvs剔除了RS1资源服务器


    c. 客户端持续访问过程中,断掉Director1服务 查看客户端是否受影响,并且Director VIP是否漂移
    客户端访问情况:

    Dirctor1关闭服务

    Dirctor2 VIP情况

至此,LVS-DR + keepalived安装配置测试成功。



来自为知笔记(Wiz)


LVS-DR+Keepalived+httpd(双主)

原文地址:https://www.cnblogs.com/allin2018/p/9309336.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved