keepalived+LVS-DR模式

LVS的DR模式+keepalived

keepalived+LVS-DR模式

---------client---------主LVS---------从LVS---------WEB1---------WEB2--------

192.168.6.1       192.168.6.20   192.168.6.200    192.168.6.30   192.168.6.50

                  lo:0:192.168.6.254   lo:0:192.168.6.254

1、配置主LVS

1).配置IP,虚拟IP不用配置,让群集IP代替

2).调整响应参数(主从配置一样)

vim /etc/sysctl.conf

添加:

net.ipv4.conf.all.send_redirects = 0

net.ipv4.conf.default.send_redirects = 0

net.ipv4.conf.ens33.send_redirects = 0

sysctl -p

3).安装ipvsadm(主从配置一样)

modprobe ip_vs

yum -y install ipvsadm  keepalived

4).配置主Keepalived

vim /etc/keepalived/keepalived.conf

修改:

router_id LVS_DEVEL-r1

vrrp_instance VI_1 {

    state MASTER

    interface ens33

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.6.254

    }

}

virtual_server 192.168.6.254 80 {

    delay_loop 6

    lb_algo rr

    lb_kind DR

    protocol TCP

    real_server 192.168.6.30 80 {

        weight 1

        TCP_CHECK {

            connect_port 80

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    }

    real_server 192.168.6.50 80 {

        weight 1

        TCP_CHECK {

            connect_port 80

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    }

}

systemctl restart keepalived

5).查看

ip add //有群集地址

ipvsadm -ln //有节点服务器地址

2、配置WEB节点服务器(两台配置一样,配置两台)

1).配置IP地址,并安装配置httpd

2).设置VIP

cd /etc/sysconfig/network-scripts/

cp ifcfg-lo ifcfg-lo:0

vim ifcfg-lo:0

修改:

DEVICE=lo:0

IPADDR=192.168.6.254

NETMASK=255.255.255.255

ONBOOT=yes

systemctl restart network

3).添加路由

route add -host 192.168.6.254 dev lo:0

4).调整响应参数

vim /etc/sysctl.conf

添加:

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

net.ipv4.conf.default.arp_ignore = 1

net.ipv4.conf.default.arp_announce = 2

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

sysctl -p

vim /usr/local/httpd/htdocs/index.html

systemctl restart httpd

5).客户端验证

firefox 192.168.6.254(比较慢) //刷新测试在两个httpd间互相调度

3、配置从keepalived

1).配置IP,虚拟IP不用配置,让群集IP代替

2).调整响应参数(主从配置一样)

vim /etc/sysctl.conf

添加:

net.ipv4.conf.all.send_redirects = 0

net.ipv4.conf.default.send_redirects = 0

net.ipv4.conf.ens33.send_redirects = 0

sysctl -p

3).安装ipvsadm(主从配置一样)

modprobe ip_vs

yum -y install ipvsadm  keepalived

4).配置从Keepalived

vim /etc/keepalived/keepalived.conf

修改:

router_id LVS_DEVEL-r2

vrrp_instance VI_1 {

    state BACKUP

    interface ens33

    virtual_router_id 51

    priority 99

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.6.254

    }

}

virtual_server 192.168.6.254 80 {

    delay_loop 6

    lb_algo rr

    lb_kind DR

    protocol TCP

    real_server 192.168.6.30 80 {

        weight 1

        TCP_CHECK {

            connect_port 80

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    }

    real_server 192.168.6.50 80 {

        weight 1

        TCP_CHECK {

            connect_port 80

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    }

}

systemctl restart keepalived

在此inet 192.168.6.254/32 scope global ens33是应用不上的

断掉主的网卡,回到从

记得切换回来重启keepalived

在此inet 192.168.6.254/32 scope global ens33是已经应用上了的


L

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值