linux系统lvs负载均衡使用keepalived

lvs使用keepalived

      • lvs-dr模式+keepalived

lvs-dr模式+keepalived

两台负载均衡器安装
yum -y install ipvsadm keepalived 

master端设置
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id lvs-keepalived-master    #辅助改为lvs-backup
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33                #VIP绑定接口
    virtual_router_id 80           #VRID 同一组集群,主备一致          
    priority 100                   #本节点优先级,辅助改为50
    advert_int 1                   #检查间隔,默认为1s
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.188.200/24  # 可以写多个vip
    }
}

virtual_server [vip地址] 80 {    #LVS配置
	delay_loop 3
	lb_algo rr     #LVS调度算法
	lb_kind DR     #LVS集群模式(路由模式)
	net_mask 255.255.255.0
	protocol TCP      #健康检查使用的协议
	real_server [后端web服务器地址] 80 {
		weight 1
		inhibit_on_failure   #当该节点失败时,把权重设置为0,而不是从IPVS中删除
		TCP_CHECK {          #健康检查
			connect_port 80   #检查的端口
			connect_timeout 3  #连接超时的时间
			}
		}
	real_server [后端web服务器地址] 80 {
		weight 1
		inhibit_on_failure
		TCP_CHECK {
			connect_timeout 3
			connect_port 80
			}
		}
}



backup端设置
vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   router_id lvs-keepalived-slave
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    nopreempt                    #不抢占资源
    virtual_router_id 80
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.188.200/24
    }
}
virtual_server 192.168.188.200 80 {
	delay_loop 3
	lb_algo rr
	lb_kind DR
	net_mask 255.255.255.0
	protocol TCP
	real_server 192.168.188.144 80 {
		weight 1
		inhibit_on_failure
		TCP_CHECK {
			connect_port 80
			connect_timeout 3
			}
		}
	real_server 192.168.188.145 80 {
		weight 1
		inhibit_on_failure
		TCP_CHECK {
			connect_timeout 3
			connect_port 80
			}
		}
}


启动KeepAlived
systemctl start keepalived
两台web服务器安装

yum install -y nginx

ip addr add dev lo vip的地址/32

net.ipv4.conf.all.arp_ignore = 1 >> /etc/sysctl.conf
net.ipv4.conf.all.arp_announce = 2 >> /etc/sysctl.conf

sysctl -p

systemctl start nginx

nginx需要关闭会话保持
vim /etc/nginx/nginx.conf

keepalive_timeout   0;

你可能感兴趣的:(linux,linux,lvs,负载均衡)