zoukankan      html  css  js  c++  java
  • Mysql MGR + Consul + Consul-template + Haproxy 搭建mysql 高可用集群 (四)

    Haproxy + Consul-template 对外提供服务:

    安装haproxy:

    yum install haproxy

    按照consul-template要求修改frontend和backend,制作配置文件模板:
    cd /etc/haproxy/
    mv haproxy.cfg haproxy.cfg.tpl
    vi haproxy.cfg.tpl
    frontend proxy_rw
        mode tcp
        bind *:22014
        maxconn 66666
        option clitcpka
        default_backend mysql_servers_rw
    
    backend mysql_servers_rw
        mode tcp
        option tcp-check
    {{range service "mysql_rw"}}    
        server {{.Address}} {{.Address}}:{{.Port}} check inter 10s maxconn 66666   
    {{end}}
    
    frontend proxy_ro
        mode tcp
        bind *:22015
        maxconn 66666
        option clitcpka
        default_backend mysql_servers_ro
    
    backend mysql_servers_ro
        mode tcp
        option tcp-check
    {{range service "mysql_ro"}}
        server {{.Address}} {{.Address}}:{{.Port}} check inter 10s maxconn 66666
    {{end}}

    启动consul-template:

    cd /root/consul
    #swarm1:
    nohup consul-template  -consul-addr 172.16.0.90:8500 -template /etc/haproxy/haproxy.cfg.tpl:/etc/haproxy/haproxy.cfg:"systemctl restart haproxy.service" >> consul-template.log &
    #swarm2:
    nohup consul-template  -consul-addr 172.16.0.76:8500 -template /etc/haproxy/haproxy.cfg.tpl:/etc/haproxy/haproxy.cfg:"systemctl restart haproxy.service" >> consul-template.log &
    #swarm3:
    nohup consul-template  -consul-addr 172.16.0.175:8500 -template /etc/haproxy/haproxy.cfg.tpl:/etc/haproxy/haproxy.cfg:"systemctl restart haproxy.service" >> consul-template.log &

    检查haproxy配置文件及启动情况:

    systemctl status haproxy.service
    cat /etc/haproxy/haproxy.cfg
    frontend proxy_rw
        mode tcp
        bind *:22014
        maxconn 66666
        option clitcpka
        default_backend mysql_servers_rw
    
    backend mysql_servers_rw
        mode tcp
        option tcp-check
        
        server 172.16.0.90 172.16.0.90:40010 check inter 10s maxconn 66666   
    
    
    frontend proxy_ro
        mode tcp
        bind *:22015
        maxconn 66666
        option clitcpka
        default_backend mysql_servers_ro
    
    backend mysql_servers_ro
        mode tcp
        option tcp-check
    
        server 172.16.0.76 172.16.0.76:40010 check inter 10s maxconn 66666
    
        server 172.16.0.175 172.16.0.175:40010 check inter 10s maxconn 66666

    验证连接情况,使用haproxy配置的新端口:

    [root@swarm1 ~]# mysql -uqxy -pqxy -hswarm1 -P22014 -e "show variables like '%hostname%';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+--------+
    | Variable_name | Value  |
    +---------------+--------+
    | hostname      | swarm1 |
    +---------------+--------+
    [root@swarm1 ~]# mysql -uqxy -pqxy -hswarm1 -P22015 -e "show variables like '%hostname%';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+--------+
    | Variable_name | Value  |
    +---------------+--------+
    | hostname      | swarm2 |
    +---------------+--------+
    [root@swarm1 ~]# mysql -uqxy -pqxy -hswarm1 -P22015 -e "show variables like '%hostname%';"
    mysql: [Warning] Using a password on the command line interface can be insecure.
    +---------------+--------+
    | Variable_name | Value  |
    +---------------+--------+
    | hostname      | swarm3 |
    +---------------+--------+

    至此一个3节点MGR集群部署完毕,三个集群模式haproxy对外提供服务,前面加一层网络负载均衡就彻底OK了。。。

    备注:

    这种部署模式中,consul成为了高可用关键点,如果同一主机上,consul 客户端发生异常,而mysql工作正常,则会出现问题,需要思考解决。。

  • 相关阅读:
    [navicat premium] [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
    阿里云推荐码优惠享9折
    [eclipse]maven 编译时报错:编码 UTF-8 的不可映射字符
    Aqua Data Studio【下载】ads-windows-x64-16.0.5
    PL/SQL Develper配置Oracle client
    SecureCRT 访问本地Linux虚拟机NAT网络(VMware workstation 9+secureCRT+Ubuntu12.04)
    Spring官方下载地址
    dom4j创建XML文件
    azure devops
    html里如何获取每次点击select里的option值
  • 原文地址:https://www.cnblogs.com/qixingyi/p/10310298.html
Copyright © 2011-2022 走看看