king

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

king 运维技术 2022-11-16 428浏览 0

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

多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

继续浏览有关 网络 的文章
发表评论