美文网首页
项目分布17:部署HA高可用集群

项目分布17:部署HA高可用集群

作者: 大白菜的猪猪 | 来源:发表于2020-06-07 13:25 被阅读0次

    拓扑结构

    调度器高可用集群拓扑

    拓扑图

    Ip规划

    IP规划

    准备备用调度器主机

    主机haproxy98做如下配置

    – 安装haproxy软件

    [root@haproxy98 ~]# yum -y install haproxy

    – 修改配置文件(配置与haproxy99主机相同)

    [root@haproxy98 ~]# vim /etc/haproxy/haproxy.cfg

    – 启动服务

    [root@haproxy98 ~]# systemctl start haproxy

    [root@haproxy98 ~]# systemctl enable haproxy

    [root@haproxy98 ~]# ps -C haproxy

    [root@haproxy98 ~]# ss -antulp | grep haproxy

    – 测试配置

    MySQL [(none)]> select @@hostname;

    查询结果

    MySQL [(none)]> select @@hostname;

    查询结果

    多次连接访问显示不同的主机名

    安装软件

    在主机haproxy99/98分别安装软件keepalived

    [root@haproxy99 ~]# yum -y install keepalived

    [root@haproxy98 ~]# yum -y install keepalived

    修改配置文件

    修改主haproxy99 的 /etc/keepalived/keepalived.conf

    global_defs {

       notification_email {

         acassen@firewall.loc

         failover@firewall.loc

         sysadmin@firewall.loc

       }

       notification_email_fromAlexandre.Cassen@firewall.loc

       smtp_server 192.168.200.1

       smtp_connect_timeout 30

       router_id LVS_DEVEL

       vrrp_skip_check_adv_addr

       vrrp_strict

       vrrp_garp_interval 0

       vrrp_gna_interval 0

       vrrp_iptables

    }

    vrrp_instance VI_1 {

        state MASTER

        interface eth0

        virtual_router_id 51

        priority 150

        advert_int 1

        authentication {

            auth_type PASS

            auth_pass 1111

        }

        virtual_ipaddress {

            192.168.4.100

        }

    }

    修改haproxy98的/etc/keepalived/keepalived.conf

    [root@haproxy98 ~]# vim

    /etc/keepalived/keepalived.conf

    global_defs {

       notification_email {

         acassen@firewall.loc

         failover@firewall.loc

         sysadmin@firewall.loc

       }

       notification_email_fromAlexandre.Cassen@firewall.loc

       smtp_server 192.168.200.1

       smtp_connect_timeout 30

       router_id LVS_DEVEL

       vrrp_skip_check_adv_addr

       vrrp_strict

       vrrp_garp_interval 0

       vrrp_gna_interval 0

       vrrp_iptables

    }

    vrrp_instance VI_1 {

        state BACKUP

        interface eth0

        virtual_router_id 51

        priority 100

        advert_int 1

        authentication {

            auth_type PASS

            auth_pass 1111

        }

        virtual_ipaddress {

            192.168.4.100

        }

    }

    启动服务

    在两台主机上分别启动keepalived服务

    启动主的keepalived服务

    [root@haproxy99 ~]# systemctl start keepalived

    [root@haproxy99 ~]# systemctl enable keepalived

    [root@haproxy99 ~]# systemctl status keepalived

    启动备的keepalived服务

    [root@haproxy98 ~]# systemctl start keepalived.service

    [root@haproxy98 ~]# systemctl enable keepalived.service

    [root@haproxy98 ~]# systemctl status keepalived

    测试配置

    在客户端连接vip地址访问数据

    [root@client ~]# mysql -h 192.168.4.100 -uyaya99 -p123qqq...A

    连接vip地址

    MySQL [(none)]> select @@hostname;

    [root@client ~]# ping 192.168.4.100 查看vip地址能不能ping通

    [root@haproxy99 ~]# ip addr show | grep 192.168.4.100

        inet 192.168.4.100/32 scopeglobal eth0

    [root@haproxy98 ~]# ip addr show | grep 192.168.4.100 //查找不到

    在haproxy99上关闭keepalived服务,查看vip会不会转移到haproxy98上去,测试高可用

    [root@haproxy99 ~]# systemctl stop keepalived

    [root@haproxy98 ~]# ip addr show | grep 192.168.4.100

        inet 192.168.4.100/32 scopeglobal eth0

    Vip地址转移到了haproxy98上

    重启服务,查看vip地址是否回到优先级高的haproxy99

    [root@haproxy99 ~]# systemctl start keepalived

    [root@haproxy99 ~]# ip addr show | grep 192.168.4.100

        inet 192.168.4.100/32 scopeglobal eth0

    相关文章

      网友评论

          本文标题:项目分布17:部署HA高可用集群

          本文链接:https://www.haomeiwen.com/subject/tlkctktx.html