【问题标题】:Splitting read/write for mysql cluster with HAproxy使用 HAproxy 拆分 mysql 集群的读/写
【发布时间】:2018-10-20 10:06:54
【问题描述】:

我在 ubuntu 16.04 上有一个 mysql 集群,想用 haproxy 拆分读/写。

所有连接都将通过端口 80 完成。 如果有人使用 X.X.X.X/write 连接到服务器,我希望他被重定向到 1 个特定服务器。 到目前为止,这是我的配置,它适用于默认值(除 /write 之外的任何内容),但是当尝试与 /write 连接时,我得到“未知的 MySql 服务器主机”。 我的配置如下:

global
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy

defaults
mode tcp
log global
retries 2
timeout connect 3000
timeout server 5000
timeout client 5000

backend read
balance roundrobin
server mysql1 192.168.0.4:3306
server mysql2 192.168.0.5:3306
server mysql3 192.168.0.6:3306

backend write
server mysql1 192.168.0.4:3306

frontend local
bind *:80
acl write url_beg /write
use_backend write if write
default_backend read

感谢您的帮助!

【问题讨论】:

    标签: mysql ubuntu reverse-proxy haproxy portforwarding


    【解决方案1】:

    MySQL 连接中没有“URL”,因此url_beg 不可能匹配任何内容。连接到 MySQL 服务器(或代理)仅通过 IP 地址或主机名完成——不是主机名和路径,因为没有路径。检测客户端使用的主机名是不可能的,因为建立连接时没有通过。

    要完成你想要的,你需要两个不同的主机名,指向 HAProxy 服务器上的两个不同的 IP 地址,并且这两个 IP 中的每一个都在自己的 frontend 和 bind 语句中。

    frontend read
      mode tcp
      bind 203.0.113.1:3306
      default_backend read
    
    frontend write
      mode tcp
      bind 203.0.113.2:3306
      default_backend write
    

    【讨论】:

    • 明白了。没有第二个IP地址就没有办法做到这一点吗?
    • 在这种情况下,您必须绑定到不同的端口,因为只有一个 IP 没有其他方法可以区分目标。
    猜你喜欢
    • 1970-01-01
    • 2021-01-09
    • 2016-03-14
    • 2011-09-04
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    相关资源
    最近更新 更多