您好,登錄后才能下訂單哦!
本篇文章給大家主要講的是關于MySQL中ProxySQL新版本如何實現對MGR的原生支持的內容,感興趣的話一起來看看這篇文章吧,相信看完MySQL中ProxySQL新版本如何實現對MGR的原生支持對大家多少有點參考價值吧。
ProxySQL> show tables ;
+--------------------------------------------+
| tables |
+--------------------------------------------+
| global_variables |
| mysql_collations |
| mysql_group_replication_hostgroups |
| mysql_query_rules |
| mysql_replication_hostgroups |
| mysql_servers |
| mysql_users |
...
| scheduler |
+--------------------------------------------+
15 rows in set (0.00 sec)
name | ip |
---|---|
mysql1 | 192.168.90.2 |
mysql2 | 192.168.90.3 |
mysql3 | 192.168.90.4 |
Column Name | Description |
---|---|
writer_hostgroup | the id of the hostgroup that will contain all the members that are writer MGR寫節點都應被包含在這個組中 |
backup_writer_hostgroup | if the group is running in multi-primary mode, there are multi writers (read_only=0) but if the amount of these writer is larger than the max_writers, the extra nodes are located in that backup writer group 在MGR多寫的模式下,如果可以提供寫屬性的節點超過實際使用的寫節點數,剩下的節點將在這個備用寫節點組中存放。 |
reader_hostgroup | the id of the hostgroup that will contain all the members in read_only 該組將會包含所有具有只讀屬性的MGR節點 |
offline_hostgroup | the id of the hostgroup that will contain the host not being online or not being part of the Group 改組將會包含所有無法提供服務或者不處于online情況下的節點 |
active | when enabled, ProxySQL monitors the Group and move the server according in the appropriate hostgroups 當該列屬性啟動時,ProxySQL將會監察整個集權,并根據hostgroup和節點的屬性,進行匹配。 |
max_writers | limit the amount of nodes in the writer hostgroup in case of group in multi-primary mode 控制MGR多寫模式下實際對外提供寫服務的節點數量 |
writer_is_also_reader | boolean value, 0 or 1, when enabled, a node in the writer hostgroup will also belongs the the reader hostgroup 布爾值0或1,當啟動時寫節點組中的節點會同時出現在讀組中 |
max_transactions_behind | if the value is greater than 0, it defines how much a node can be lagging in applying the transactions from the Group, see this post for more info 定義節點最大落后整個集群的事務數量(ProxySQL內部,非MGR中的) |
ProxySQL在MySQL的代理和負載均衡中一直處于領先地位。其中包含了諸如緩存查詢,多路復用,流量鏡像,讀寫分離,路由等等的強力功能。在最新的功能性增強中,包含了對MGR的原生支持,不在需要使用第三方腳本進行適配。
This implementation supports Groups in Single-Primary and in Multi-Primary mode. It is even possible to setup a Multi-Primary Group but dedicate writes on only one member.
最新的增強中,提供了對單寫和多寫集群組的支持,甚至可以在多寫組上指定只由某個成員進行寫入操作。
René, the main developer of ProxySQL, went even further. For example in a 7 nodes clusters (Group of 7 members) where all nodes are writers (Multi-Primary mode), it’s possible to decide to have only 2 writers, 3 readers and 2 backup-writers. This mean that ProxySQL will see all the nodes as possible writers but will only route writes on 2 nodes (add them in the writer hostgroup, because we decided to limit it to 2 writers for example), then it will add the others in the backup-writers group, this group defines the other writer candidates. An finally add 2 in the readers hostgroup.
ProxySQL的主要開發者René,更進一步的可以(利用ProxySQL)做到例如在一個七個節點的多寫集群中,指定2組寫節點,2組備用寫節點,3個只讀節點的操作。即ProxySQL雖然識別出來所有的節點皆為寫節點,但只路由寫操作到選定的兩個寫節點(通過Hostgroup的方式),同時將另外兩個寫節點添加到備用寫節點組中,最后三個讀節點加入讀組。(本段中的組皆為ProxySQL中的hostgroup含義)。
It’s also possible to limit the access to a member that is slower in applying the replicated transactions (applying queue reaching a threshold).
除此之外,還可以限制連接訪問集群中超出最大設定落后事務值的慢節點。
It is time to have a look at this new ProxySQL version. The version supporting MySQL Group Replication is 1.4.0 and currently is only available on github (but stay tuned for a new release soon).
ProxySQL從1.4.0版本開始增加對MGR的原生支持,若發行版中沒有,可以從GitHub中編譯獲取。
So let’s have a look at what is new for users. When you connect to the admin interface of ProxySQL, you can see a new table: mysql_group_replication_hostgroups
下面我們看下對于用戶來說有哪些明顯的變化,開始進行admin端口連接后會發現比之前多了一個mysql_group_replication_hostgroups表
This is the table we will use to setup in which hostgroup a node will belongs.
我們將在這個表中進行節點的歸屬組(hostgroup)的設置。
To illustrate how ProxySQL supports MySQL Group Replication, I will use a cluster of 3 nodes:
為了闡明ProxySQL 對MGR支持的原理,下面我會用到一個三節點的集群。
So first, as usual we need to add our 3 members into the mysql_servers table:
首先,我們照舊插入三個節點的信息到mysql_servers表中。
Now we can setup ProxySQL’s behavior with our Group Replication cluster, but before let’s check the definition of the new mysql_group_replication_hostgroups table:
在設置MGR節點在ProxySQL中的行為之前,先查看下新加入的mysql_group_replication_hostgroups表的DDL。
There are many new columns, let’s have a look at their meaning:
看一下之前沒有出現過的新列的含義
Now that we are (or should be) more familiar with that table, we will set it up like this:
熟悉了表的定義后,整個拓補將會如下圖所示:
So let’s add this:
下面我們將MGR集群的分組定義和關鍵參數寫入mysql_group_replication_hostgroups表中
We should not forget to save our mysql servers to disk and load them on runtime:
然后將新更改的配置保存到磁盤上,并加載到運行環境。
It’s also important with the current version of MySQL Group Replication to add a view and its dependencies in sys schema: addition_to_sys.sql:
同時,我們需要在MGR中添加如下的視圖,及其依賴的存儲過程。
So now from every members of the group, we can run the following statement. ProxySQL based its internal monitoring this same view:
如此,我們便可以從MGR集群中任意一個節點上執行下面的語句獲取MGR成員的基本信息,ProxySQL 也是根據這個辦法進行監測節點的健康與落后情況。
We also must not forget to create in our cluster the monitor user needed by ProxySQL:
同時,我們需要講sys庫的讀權限賦給ProxySQL配置的監控MySQL的賬戶:
We can immediately check how ProxySQL has distributed the servers in the hostgroups :
接下來,我們馬上檢查下ProxySQL是如何將MGR節點分發到ProxySQL各個組中:
The Writer (Primary-Master) is mysql1 (192.168.90.2 in hostgroup 2) and the others are in the read hostgroup (id=3).
寫節點被分配到之前定義好的ID為2的寫組中,其他所有的節點被分配到ID為3的只讀組中。(單寫模式)
As you can see, there is no more need to create a scheduler calling an external script with complex rules to move the servers in the right hostgroup.
這樣,我們就省掉了通過定時器去調用第三方復雜定義的腳本將MGR節點匹配并分配到對應的ProxySQL組中的操作。
Now to use the proxy, it’s exactly as usual, you need to create users associated to default hostgroup or add routing rules.
接下來,你就可以按照之前的做法對ProxySQL進行配置,例如關聯用戶到默認ProxySQL組中,或者添加查詢路由規則。
An extra table has also been added for monitoring:
另外,ProxySQL比之前多了一個監控MySQL實例的表,具體信息如下面所示:
以上關于MySQL中ProxySQL新版本如何實現對MGR的原生支持詳細內容,對大家有幫助嗎?如果想要了解更多相關,可以繼續關注我們的行業資訊板塊。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。