设为首页 收藏本站
查看: 888|回复: 0

[经验分享] keepalived实现lvs的高可用

[复制链接]

尚未签到

发表于 2018-12-30 08:27:26 | 显示全部楼层 |阅读模式
  搭建环境:
      两台director,两台RS

      director1:ip(172.16.125.5),安装好keepalived;

      director2:ip(172.16.125.6),安装好keepalived;

      RS1:ip(172.16.125.7),安装好httpd;
      RS2:ip(172.16.125.8),安装好httpd;
      vip(1):172.16.125.100,vip(2):172.16.125.110。

      在此处keepalived实现lvs的高可用,使用了lvs的dr模型。关闭iptables和selinux,且实现时间同步。

  

  使用主从模式配置过程:
      (1)首先配置RS,在每一台的RS上安装好httpd,同时为了实现lvs调度算法的效果,在此故意使得每一台RS上提供的网页内容不一样。

      (2)首先设置内核参数,保证请求vip的报文必须经过director进行调度,才能到达后端RS上。
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce      (3)进行每一台RS上lo接口的vip的绑定,同时设置路由。
~]# ifconfig lo:0 172.16.125.100/32 broadcast 172.16.125.100 up
~]# route add -host 172.16.125.100 dev lo:0        通过以上设置,完成了后端RS的设置。

      (4)进行两台director上keepalived服务的配置。首先设置一个虚拟路由器组,其虚拟ip为172.16.125.100(也就是vip),在虚拟主机内部配置两台RS,即后端的两台RS,具体配置文件如下所示。

      配置文件一(在主keepalived服务器上的配置):
global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface eno16777736
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 125110
    }
    virtual_ipaddress {
        172.16.125.100/16 dev eno16777736 label eno16777736:0
    }
}
virtual_server 172.16.125.100 80 {
    delay_loop 3
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
    protocol TCP
    real_server 172.16.125.7 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 172.16.125.8 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
    }
    }   
}       在从keepalived所在的主机上的配置,不同的地方有两条:一,state设置为BACKUP,表明该主机为从服务器;二,priority(优先级)要低于主keepalived服务器上的优先级。

      在两台调度器上同时启动keepalived服务,进行查看集群服务的相关信息。
          一、使用ipvsadm查看负载均衡集群服务信息:
          
          二、查看vip是否已经加在主keepalived服务器上了:
          
          三、在客户端访问vip,看是否能够实现负载均衡调度,此处使用轮询(rr)算法。
              
          四、在主keepalived服务器上关闭keepalived服务,看高可用资源是否会发生转移,同时进行vip的访问,是否能够继续进行负载均衡调度。

  

  使用双主模型实现keepalived+lvs:
      (1)在后端RS上设置内核参数,保证请求vip的报文必须经过director进行调度,才能到达后端RS上。设置第一个vip(172.16.125.100),同时设置路由,详细配置步骤如主从模式的RS的vip的设置,在此处不再赘述。
          在后端RS上lo端口上配置第二个vip(172.16.125.110),同时设置路由。
~]# ifconfig lo:1 172.16.125.110/32 broadcast 172.16.125.110 up
~]# route add -host 172.16.125.110 dev lo:1      (2)在keepalived的服务器上修改配置文件,增加一个新的虚拟路由器,详细配置如下配置文件所示:
          主keepalived服务器1上的配置:
global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface eno16777736
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 125110
    }
    virtual_ipaddress {
    172.16.125.100/16 dev eno16777736 label eno16777736:0
    }
}
virtual_server 172.16.125.100 80 {
    delay_loop 3
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
    protocol TCP
    real_server 172.16.125.7 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 172.16.125.8 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
}
    }   
}
vrrp_instance VI_2 {
    state BACKUP
    interface eno16777736
    virtual_router_id 110
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456789
    }
    virtual_ipaddress {
    172.16.125.110/16 dev eno16777736 label eno16777736:1
    }
}
virtual_server 172.16.125.110 80 {
    delay_loop 3
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
    protocol TCP
    real_server 172.16.125.7 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 172.16.125.8 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
}
    }   
}      主keepalived服务器2上的配置:
global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP
    interface eno16777736
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 125110
    }
    virtual_ipaddress {
    172.16.125.100/16 dev eno16777736 label eno16777736:0
    }
}
virtual_server 172.16.125.100 80 {
    delay_loop 3
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
    protocol TCP
    real_server 172.16.125.7 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 172.16.125.8 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
}
    }   
}
vrrp_instance VI_2 {
    state MASTER
    interface eno16777736
    virtual_router_id 110
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456789
    }
    virtual_ipaddress {
    172.16.125.110/16 dev eno16777736 label eno16777736:1
    }
}
virtual_server 172.16.125.110 80 {
    delay_loop 3
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
    protocol TCP
    real_server 172.16.125.7 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 172.16.125.8 80 {
        weight 1
        HTTP_GET {
            url {
              path /
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
}
    }   
}      (3)在两台高可用服务器上启动keepalived服务,查看vip是否分别加载到高可用服务器上。
              
              
          在客户端进行测试,分别访问vip(172.16.125.100)和vip(172.16.125.110)。
              
         可以看到,访问两个vip都可以正常访问,并且实现了rr(轮询)调度算法。
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-657414-1-1.html 上篇帖子: LANP+KEEPALIVED集群(一) 下篇帖子: LVS+keepalived高可用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表