(三)lvs负载均衡详解--lvs-DR+keepalived配置

                                LVS-DR+ KeepAlived负载均衡高可用配置

(一)lvs负载均衡详解--lvs-DR模式配置_W1124824402的博客-CSDN博客

(二)lvs负载均衡详解--lvs-NAT模式配置_W1124824402的博客-CSDN博客

(四)lvs负载均衡详解--mysql+keepalived配置,yum下载mysql详解、mysql集群高可用_W1124824402的博客-CSDN博客

KeepAlived在该项目中的功能:

1. 管理IPVS的路由表(包括对RealServer做健康检查)

2. 实现调度器的HA(高可用)

http://www.keepalived.org

Keepalived所执行的外部脚本命令建议使用绝对路径

主/备调度器安装软件

192.168.11.208-master yum -y install ipvsadm keepalived

192.168.11.192-slave yum -y install ipvsadm keepalived

两台nginx用来测试效果

192.168.11.193-nginx 

192.168.11.194-nginx 

192.168.11.208-master 操作

vim /etc/keepalived/keepalived.conf 修改为以下内容建议直接dG

! 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.11.222/24   #keepalived抢占设置的vip

    }

}

virtual_server 192.168.11.222 80 {    #LVS配置

delay_loop 3  #启动3个进程 cpu有几个设置几个最佳

lb_algo rr     #LVS调度算法轮询

lb_kind DR     #LVS集群模式(路由模式)

nat_mask 255.255.255.0

protocol TCP      #健康检查使用的协议

real_server 192.168.11.193 80 { #nignx节点ip

weight 1

inhibit_on_failure   #当该节点失败时,把权重设置为0,而不是从IPVS中删除

TCP_CHECK {          #健康检查

connect_port 80   #检查的端口

connect_timeout 3  #连接超时的时间

        }

}

real_server 192.168.11.194 80 { #nginx节点ip

weight 1

inhibit_on_failure

TCP_CHECK {

connect_timeout 3

connect_port 80

                }

        }

}                      

192.168.11.192-slave 操作

vim /etc/keepalived/keepalived.conf   修改为以下内容建议直接dG

! 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 #从节点优先级设置为50就行

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

            }

    virtual_ipaddress {

        192.168.11.222/24

            }

}

virtual_server 192.168.11.222 80 {

delay_loop 3

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

protocol TCP

real_server 192.168.11.193 80 {

weight 1

inhibit_on_failure

TCP_CHECK {

connect_port 80

connect_timeout 3

        }

}

real_server 192.168.11.194 80 {

weight 1

inhibit_on_failure

TCP_CHECK {

connect_port 80

connect_timeout 3

                }

        }

}

启动KeepAlived(主备均启动)

systemctl start keepalived       systemctl enable keepalived

启动以后查看一下   ipvsadm -Ln

(三)lvs负载均衡详解--lvs-DR+keepalived配置_第1张图片

(三)lvs负载均衡详解--lvs-DR+keepalived配置_第2张图片

(三)lvs负载均衡详解--lvs-DR+keepalived配置_第3张图片

配置好以后可以看一下是否会进行vip漂移,漂移成功测部署成功

关掉主节点的keepalvied

Systemctl stop keepalived  

(三)lvs负载均衡详解--lvs-DR+keepalived配置_第4张图片

然后在配置两台nginx服务器用来测试

192.168.11.193-nginx yum install -y nginx

192.168.11.194-nginx yum install -y nginx

在192.168.11.193-nginx 操作

ip addr add dev lo 192.168.11.222/32

 echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore #忽略arp广播

 echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce #匹配精确ip地址回包

 echo "2022" >> /usr/share/nginx/html/index.html

systemctl start nginx

在 192.168.11.194-nginx 操作

ip addr add dev lo 192.168.11.222/32

 echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore #忽略arp广播

 echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce #匹配精确ip地址回包

 echo "2021" >> /usr/share/nginx/html/index.html

systemctl start nginx

然后访问配置的vip看一下结果

192.168.11.222  为了能够查看测试效果nginx的长链接记得修改为0 两台nginx都操作

(三)lvs负载均衡详解--lvs-DR+keepalived配置_第5张图片

(三)lvs负载均衡详解--lvs-DR+keepalived配置_第6张图片

(三)lvs负载均衡详解--lvs-DR+keepalived配置_第7张图片

可以访问到两个则配置成功,如果访问没有变化 看一下是不是修改了长链接,重启nignx

                             

你可能感兴趣的:(负载均衡,运维,linux,lvs,云计算)