多集群方案负载均衡器配置代码

网络 网络优化 网络运维
本文主要讲述了在伏在集群部署中负载均衡的配置问题。那么首先讲述了在怎是服务器的操作过程,之后是均衡器上的配置问题。

前面我们介绍了此方案的设备连接问题,那么接下来我们就是通过负载均衡器的使用来部署具体的方案了。那么现在主要讲的是其中的设备安装配置问题。希望通过本文的介绍能让大家对这个过程有一个清晰的思路。稍后我们还会对负载均衡器的测试进行一个详解。

多vrrp负载集群部署

参照"cdn缓存服务器集群部署"操作步骤,多vrrp_instance集群的部署也按真实服务器和负载均衡器2个环节来处理。

◆真实服务器上进行的操作

1、编写负载均衡客户端配置脚本。本例中有3组真实服务器,每组服务器使用相同的lvs客户端配置脚本。配置脚本除了vip而外,其余的部分与本章其他部分所列的lvs客户端配置脚本完全相同。关于3个组vip地址使用情况。

2、检验lvs客户端配置脚本的正确性。

◆负载均衡器上的操作

1、负载均衡器lvs_1

(1)安装ipvsadm.方法如前文所叙。

(2)安装keepalived.方法如前文所叙。

(3)新增配置文件/etc/keepalived/keepalived.conf。为了跟第二个lvs负载均衡器做比较,我在后面把2个配置文件放在一个表格里(表1),方便查看。

2、负载均衡器lvs_2

(1)安装ipvsadm。方法如前文所叙。

(2)安装keepalived。方法如前文所叙。

(3)新增配置文件/etc/keepalived/keepalived.conf。

负载均衡器lvs_1配置文件/etc/keepalived/keepalived.conf

负载均衡器lvs_2配置文件/etc/keepalived/keepalived.conf

#guration File for keepalived,writed by sery

#global define

global_defs {

   router_id lvs_1

}

 

vrrp_sync_group VGM {

   group {

      VI_WEB

   }

}

vrrp_sync_group VGB {

   group {

      VI_CTCP

   }

}

 

vrrp_instance VI_WEB{

    state MASTER

    interface eth0

    lvs_sync_daemon_inteface eth0

    virtual_router_id 51

    priority 180

    advert_int 5

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        61.135.93.99

            }

}

# setting port 80 forward

virtual_server 61.135.93.99 80 {

    delay_loop 6

    lb_algo wlc

    lb_kind DR

    persistence_timeout 10

    protocol TCP

 

    real_server 61.135.99.80 80 {

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

    }

   real_server 61.135.93.81 80 {

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

    }

   real_server 61.135.93.82 80 {

        weight 90

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

}

real_server 61.135.93.83 80 {

        weight 90

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

}

}

 

vrrp_instance VI_CTCP {

    state BACKUP

    interface eth0

    lvs_sync_daemon_inteface eth0

    virtual_router_id 52

    priority 150

    advert_int 5

    authentication {

        auth_type PASS

        auth_pass 2222

    }

    virtual_ipaddress {

        61.135.93.100

    }

}

 

virtual_server 61.135.93.100 3000 {

    delay_loop 6

    lb_algo wlc

    lb_kind DR

    persistence_timeout 50

    protocol TCP

 

    real_server 61.135.93.84  3000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3000

        }

    }

    real_server 61.135.93.85  3000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3000

        }

    }

    real_server 61.135.93.86  3000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3000

        }

    }

    real_server 61.135.93.87 3000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3000

        }

    }

}

 

virtual_server 61.135.93.100 4000 {

    delay_loop 6

    lb_algo wlc

    lb_kind DR

    persistence_timeout 50

    protocol TCP

 

    real_server 61.135.93.88  4000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 4000

        }

    }

    real_server 61.135.93.89  4000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 4000

        }

    }

    real_server 61.135.93.90  4000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 4000

        }

    }

    real_server 61.135.93.91 4000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 4000

        }

    }

}

#guration File for keepalived,writed by sery

#global define

global_defs {

   router_id lvs_2

}

 

vrrp_sync_group VGM {

   group {

      VI_CTCP

   }

}

vrrp_sync_group VGB {

   group {

      VI_WEB

   }

}

 

vrrp_instance VI_WEB{

    state BACKUP

    interface eth0

    lvs_sync_daemon_inteface eth0

    virtual_router_id 51

    priority 150

    advert_int 5

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        61.135.93.99

            }

}

# setting port 80 forward

virtual_server 61.135.93.99 80 {

    delay_loop 6

    lb_algo wlc

    lb_kind DR

    persistence_timeout 10

    protocol TCP

 

    real_server 61.135.99.80 80 {

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

    }

   real_server 61.135.93.81 80 {

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

    }

   real_server 61.135.93.82 80 {

        weight 90

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

}

real_server 61.135.93.83 80 {

        weight 90

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

        }

}

}

 

vrrp_instance VI_CTCP {

    state MASTER

    interface eth0

    lvs_sync_daemon_inteface eth0

    virtual_router_id 52

    priority 180

    advert_int 5

    authentication {

        auth_type PASS

        auth_pass 2222

    }

    virtual_ipaddress {

        61.135.93.100

    }

}

 

virtual_server 61.135.93.100 3000 {

    delay_loop 6

    lb_algo wlc

    lb_kind DR

    persistence_timeout 50

    protocol TCP

 

    real_server 61.135.93.84  3000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3000

        }

    }

    real_server 61.135.93.85  3000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3000

        }

    }

    real_server 61.135.93.86  3000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3000

        }

    }

    real_server 61.135.93.87 3000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 3000

        }

    }

}

 

virtual_server 61.135.93.100 4000 {

    delay_loop 6

    lb_algo wlc

    lb_kind DR

    persistence_timeout 50

    protocol TCP

 

    real_server 61.135.93.88  4000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 4000

        }

    }

    real_server 61.135.93.89  4000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 4000

        }

    }

    real_server 61.135.93.90  4000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 4000

        }

    }

    real_server 61.135.93.91 4000{

        weight 100

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 4000

        }

    }

}

表1 lvs负载均衡器配置文件keepalived.conf

责任编辑:佟健 来源: 互联网
相关推荐

2017-05-19 14:45:01

OVN负载均衡器路由器

2010-05-06 10:14:31

负载均衡器

2010-05-04 13:32:37

nginx负载均衡器

2011-03-17 09:27:07

HAProxy负载均衡

2011-08-24 13:45:49

HAProxy负载均衡负载均衡器

2010-04-22 09:54:12

负载均衡器

2024-02-22 10:11:00

负载均衡器反向代理

2023-02-13 16:39:45

Kubernetes容器负载均衡器

2023-03-30 13:32:51

负载均衡器HDFS

2022-07-14 08:53:48

MetalLBkubernetes

2010-04-21 18:21:36

负载均衡器配置

2010-04-22 10:46:40

Lvs负载均衡故障负载均衡器

2010-05-04 13:38:25

nginx负载均衡器

2010-07-15 11:16:04

负载均衡

2010-04-20 10:46:59

什么是负载均衡器

2010-05-10 14:13:26

2010-05-10 18:22:51

负载均衡器

2024-06-18 08:14:21

2010-04-22 22:25:50

F5负载均衡器

2010-04-22 22:16:27

F5负载均衡器配置
点赞
收藏

51CTO技术栈公众号