mysql + haproxy +keepalived高可用

haproxy master1

vim /etc/haproxy/haproxy.cfg

global
    log         127.0.0.1 local2 info
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    nbproc 1
defaults
    mode                    http
    log                     global
    retries                 3
    option                  redispatch
    maxconn                 4000
    contimeout              5000
    clitimeout              50000
    srvtimeout              50000
listen stats
    bind                        *:81
    stats                       enable
    stats uri                   /haproxy
    stats auth                  qianfeng:123
frontend  web
    mode                        http
    bind                            *:80
    option                  httplog
    acl html url_reg  -i  \.html$
    use_backend httpservers if  html
    default_backend    httpservers
backend httpservers
    balance     roundrobin
    server  http1 192.168.180.251:80 maxconn 2000 weight 1  check inter 1s rise 2 fall 2
    server  http2 192.168.180.252:80 maxconn 2000 weight 1  check inter 1s rise 2 fall 2

listen mysql
    bind *:3307
    mode tcp
    balance roundrobin
    server mysql1 192.168.180.253:3306 weight 1  check inter 1s rise 2 fall 2
    server mysql2 192.168.180.100:3306 weight 1  check inter 1s rise 2 fall 2

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   router_id director1
}
vrrp_script check_mysql {
   script "/etc/keepalived/check_mysql_status.sh"
   interval 5
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 80
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.180.222/24
    }
    track_script {
        check_mysql
    }
}

配置keepalived backup配置文件

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   router_id directory2
   enable_script_security
}
vrrp_script check_mysql {
   script "/etc/keepalived/check_mysql_status.sh"
   interval 5
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    nopreempt
    virtual_router_id 80
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.180.222/24
    }
    track_script {
        check_mysql
    }
}

vim /etc /haproxy/haproxy.conf

global
    log         127.0.0.1 local2 info
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    nbproc 1
defaults
    mode                    http
    log                     global
    retries                 3
    option                  redispatch
    maxconn                 4000
    contimeout              5000
    clitimeout              50000
    srvtimeout              50000
listen stats
    bind                        *:81
    stats                       enable
    stats uri                   /haproxy
    stats auth                  qianfeng:123

frontend  web
    mode                        http
    bind                            *:80
    option                  httplog
    acl html url_reg  -i  \.html$
    use_backend httpservers if  html
    default_backend    httpservers
backend httpservers
    balance     roundrobin
    server  http1 192.168.180.251:80 maxconn 2000 weight 1  check inter 1s rise 2 fall 2
    server  http2 192.168.180.252:80 maxconn 2000 weight 1  check inter 1s rise 2 fall 2
listen mysql
    bind *:3307
    mode tcp
    balance roundrobin
    server mysql1 192.168.180.253:3306 weight 1  check inter 1s rise 2 fall 2
    server mysql2 192.168.180.100:3306 weight 1  check inter 1s rise 2 fall 2

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值