HAProxy 但仍有單點故障

HAProxy 但仍有單點故障

我正在使用 HAProxy 在 3 個實體節點上設定一個測試叢集 - Maria Galera Cluster。它有效,但我犯了某種初學者錯誤,我似乎無法解決 - 所以希望有人能以專家的眼光幫助我? !

我有3個實體節點Node1:10.1.1.120

節點2:10.1.1.121

節點3:10.1.1.124

使用HAProxy虛擬IP 10.1.1.113

啟動並運行,當我透過虛擬 IP 查詢時,我得到...

$ mysql -uroot -pPassword -P 3306 -h 10.1.1.113 -e "select @@hostname; show processlist;"
+------------+
| @@hostname |
+------------+
| node2      |
+------------+
+----+-------------+-------------+------+---------+------+--------------------+------------------+----------+
| Id | User        | Host        | db   | Command | Time | State              | Info                 | Progress |
+----+-------------+-------------+------+---------+------+--------------------+------------------+----------+
|  1 | system user |             | NULL | Sleep   |   37 | NULL               | NULL                 |    0.000 |
|  2 | system user |             | NULL | Sleep   |   37 | wsrep aborter idle | NULL             |    0.000 |
| 45 | root        | node1:55877 | NULL | Query   |    0 | init               | show processlist |    0.000 |
+----+-------------+-------------+------+---------+------+--------------------+-

如果我這樣做ip 一個節點1- 這確實是我的虛擬 IP 位址所在的地方,但主機名稱返回為節點2

如果我在節點 1 上關閉(或只是停用 eth0),虛擬 IP 位址會轉移到其他地方,但 @@ 主機名稱仍然會作為節點 2 返回。

如果我關閉node2,那麼當我嘗試使用虛擬IP mysql時,問題就會出現:

**ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"**

(此時,如果我在不使用虛擬IP的情況下登入任何本機計算機,它將起作用)。

因此,HAProxy 部分似乎正在工作(因為它適當地移動),但 MariaDB 正在嘗試做自己的事情,並決定所有內容都需要透過 Node2 進行路由。

我的 .cnf 檔案中沒有綁定位址。我對 sql 服務使用連接埠 1306,以避免在恰好具有虛擬 IP 和同時發布 3306 的電腦上重新啟動服務時與 3306 發生任何衝突。

我的 keepalived 檔案是...(不確定這是否正確,但所有節點都設定為 master 並且優先順序分別為 100,101 和 102 - 似乎沒有什麼區別)

global_defs {
  router_id geordi
}
vrrp_script haproxy {
  script "killall -0 haproxy"
  interval 1
  weight 1
}

vrrp_instance 51 {
  virtual_router_id 51
  priority 101
  state MASTER
  interface eth0
  virtual_ipaddress {
    10.1.1.113 dev eth0
  }
  track_script {
    haproxy
  }
}

我的 haproxy.cfg 是:

global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    user haproxy
    group haproxy
    daemon

defaults
    log global
    mode    http
    option  dontlognull
    contimeout 5000
    clitimeout 50000
    srvtimeout 50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

listen mysql_proxy 10.1.1.113:3306
        mode tcp 
        balance roundrobin
        option tcpka 
        option httpchk
        option mysql-check user haproxy
        server node1 10.1.1.120:1306 check 
        server node2 10.1.1.121:1306 check 
        server node3 10.1.1.124:1306 check

非常感謝您收到的任何建議——令人沮喪的是,我已經接近讓這一切正常工作,只是還沒有完全實現!

答案1

明確設定bind-address=0.0.0.0my.cnf.

另外(如果你到目前為止,你可能已經這樣做了):

  1. 確保每個主機都有 IP 位址10.1.1.113(如果使用 keepalived,則透過虛擬介面 /32)。
  2. 設定net.ipv4.conf.default.rp_filter = 2/etc/sysctl.conf
  3. 設定net.ipv4.conf.default.accept_source_route = 0/etc/sysctl.conf

這允許 MySQL 偵聽所有接口,並允許 MySQL 在資料包不屬於的介面上回應。

節點 1 上的網路介面 (10.1.1.120) 在 10.1.1.120 對應的介面上收到「10.1.1.13」封包。通常情況下,這會被刪除,並說「那不適合我」。這發生在 TCP/IP 模型的“Internet”層上。

然而,上面的第 2 條和第 3 條規定“只要接受它,它可能適合我們”,然後傳遞到 MySQL(TCP/IP 模型的“應用程式”層)。 MySQL 發現我們綁定到所有位址,其中之一是 10.1.1.113(規定 1),並對其進行處理。

相關內容