zoukankan      html  css  js  c++  java
  • mysql主从双机keepalived配置

    1.关闭selinux

    SELINUX=disabled

    2.yum安装keepalived

    yum install -y keepalived

    3.修改配置文件

    主库配置文件:

    ! Configuration File for keepalived
    global_defs {
        notification_email {
            lr@isadba.com
        }
        notification_email_from lvs@isadba.com
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
        router_id mysql01
        ! lvs_sync_daemon eth0 VI_1 1
    }
    vrrp_instance VI_1 {
        state master
        priority 150
        nopreempt
        virtual_router_id 241
        interface eno16777728
        advert_int 1
        ! smtp_alert
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.12.4
        }
    }
    virtual_server 192.168.12.4 3306 {
        delay_loop 6
        lb_algo wlc
        lb_kind TUN
        protocol TCP
        real_server 192.168.12.60 3306 {
            weight 1
            notify_down /mysql/killkeepalived.sh
            TCP_CHECK {
                connect_port    3306
                connect_timeout 3
            }
        }
        real_server 192.168.12.2 3306 {
            weight 1
            TCP_CHECK {
                connect_port    3306
                connect_timeout 3
            }
        }
    }
     
    从库配置文件:
    ! Configuration File for keepalived
    global_defs {
        notification_email {
            lr@isadba.com
        }
        notification_email_from lvs@isadba.com
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
        router_id mysql02
        ! lvs_sync_daemon eth0 VI_1 1
    }
    vrrp_instance VI_1 {
        state backup
        priority 100
        nopreempt
        virtual_router_id 241
        interface eno16777728
        advert_int 1
        ! smtp_alert
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.12.4
        }
    }
    virtual_server 192.168.12.4 3306 {
        delay_loop 6
        lb_algo wlc
        lb_kind TUN
        protocol TCP
        real_server 192.168.12.60 3306 {
            weight 1
            TCP_CHECK {
                connect_port    3306
                connect_timeout 3
            }
        }
        real_server 192.168.12.2 3306 {
            weight 1
            TCP_CHECK {
                connect_port    3306
                connect_timeout 3
            }
        }
    }
     
    主库脚本/mysql/killkeepalived.sh
    #!/bin/sh
    systemctl stop keepalived
     
    4.主从切换过程
      1.主库停库
      2.keepalived执行关闭keepalived脚本
      3.恢复主库,启动主库keepalived,关闭备库keepalived,vip即可回到主库。
     
    5.扩展
     如果使用keepalived+mycat搭建主从+多个只读从库,将vip写入mycat配置schema.xml文件,业务使用vip连接数据库。
     
     
  • 相关阅读:
    根据时间类型查询
    @Autowired注解
    如何将jar包引入到本地maven仓库
    org.springframework.beans.factory.BeanDefinitionStoreException
    几个常用的 lombok 注解
    String类底层源码(随时更新)
    如何判断单链表有环
    指定java中Date日期格式化,实现字符串转Date
    vue学习记录
    小说,漫画
  • 原文地址:https://www.cnblogs.com/orcl-2018/p/13160985.html
Copyright © 2011-2022 走看看