Ceonts 7 配置Mysql 高可用HA

环境:Cenots 7 

软件:Mysql 5.7  Keepalived v1.2.13

mysql 安装配置过程此章就不过讲了,直接讲keepalived

参考地址:http://www.tuicool.com/articles/Q7VBZnN

Keepalived 安装

yum -y install keepalived 

 

Keepalived 文件配置:

! Configuration File for keepalived

global_defs {
   notification_email {
    ***@gmail.com  # 此处定义通知邮箱,有多个可以换行添加  
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server smtp.google.com # 邮箱 SMTP 地址
   smtp_connect_timeout 30 # 定义连接smtp服务器超时时间
   router_id LVS_DEVEL
}

vrrp_instance Vi_1 {
    state MASTER    # 标示主备,备机上改为BACKUP
    interface em2    # HA监测的端口
    virtual_router_id 51  # 主备的virtual_router_id的值必须相同
    priority 100    # 优先级,通常主要比备稍大
    advert_int 1 # VRRP Multicast 广播周期秒数
    authentication { # 定义认证
        auth_type PASS  # 认证方式
        auth_pass 1111       # 认证口令字
    }
    virtual_ipaddress {  # 定义vip
        192.168.0.200   # 多个可换行添加,一行一个
    }
}

virtual_server 192.168.0.200 3306 {
    delay_loop 6    # 每隔 6 秒查询 realserver 状态
    lb_algo rr
    ld_kind    NAT
    nat_mask 255.255.255.0
    persistence_timeout 50   # 同一IP 的连接50秒内被分配到同一台realserver
    protocol TCP   # 用TCP监测realserver的状态
    real_server 192.168.0.111 3306 {  #需要指向Mysql负载的地址
        weight 3  # 权重
        TCP_CHECK {
            connect_timeout 20  # 20秒无响应超时
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }

    real_server 192.168.0.107 3306 {   #需要指向Mysql负载的地址
        weight 3
        TCP_CHECK {
            connect_timeout 3
            delay_before_retry 3
            connect_port 3306
        }
    }
}

 

posted @ 2019-11-25 12:40  Yee.Liu  阅读(170)  评论(0编辑  收藏  举报