3、实现LVS+Keepalived高可用。

在2的实验基于上修改,添加一个机器159.50,将其159.30和159.50都改为keepalived服务器:


先实现keepalived服务器双方的ssh验证:

图1

在keepalived服务器上修改hosts文件:

图2

在159.30和159.50上安装keepalived服务和ipvsadmin:

图3

master进行文件配置:

图4
图5

具体配置文件:

! Configuration File for keepalived

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id ka1

vrrp_mcast_group4 224.100.100.100

}

vrrp_instance VI_1 {

state MASTER

interface eth0

virtual_router_id 6

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 123456

}

virtual_ipaddress {

192.168.159.100/24 dev eth0 label eth0:1

}

}

virtual_server 192.168.159.100 80 {

    delay_loop 6

    lb_algo rr

    lb_kind DR

    protocol TCP

    sorry_server 192.168.159.30 80

    real_server 192.168.159.10 80 {

        weight 1

        HTTP_GET {

            url {

              path /

              status_code 200

            }

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    }

  real_server 192.168.159.20 80 {

        weight 1

        HTTP_GET {

            url {             

      path /

              status_code 200

            }

    connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    } 

}

backup配置:

图6
图7

具体配置文件:

! Configuration File for keepalived

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id ka1

vrrp_mcast_group4 224.100.100.100

}

vrrp_instance VI_1 {

state BACKUP

interface eth0

virtual_router_id 6

priority 80

advert_int 1

authentication {

auth_type PASS

auth_pass 123456

}

virtual_ipaddress {

192.168.159.100/24 dev eth0 label eth0:1

}

}

virtual_server 192.168.159.100 80 {

    delay_loop 6

    lb_algo rr

    lb_kind DR

    protocol TCP

    sorry_server 192.168.159.50 80

    real_server 192.168.159.10 80 {

        weight 1

        HTTP_GET {

            url {           

    path /

            status_code 200

            } 

    connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    }

  real_server 192.168.159.20 80 {

        weight 1

        HTTP_GET {

            url { 

      path /

              status_code 200

            }

    connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }    } 

}

在keepalived服务器上,启动keepalived服务:

//启动之前使用ls.sh停止之前的配置。

图8

查看网卡:

图9

查看规则:

图10

安装sorry-server:

图11
图12

在客户端测试:

图13

将其masterkeepalive断电:

图14

在backup查看,发现地址已经飘动过来了:

图15

将两台rs关机,在客户端查看发现sorry已经上线了:

图16
图17
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容