日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql router docker_MySQL Router 完全讲解

發布時間:2025/3/15 数据库 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql router docker_MySQL Router 完全讲解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MySQL Router 是一款輕量級 MySQL 中間件,提供應用與任意 MySQL 后端服務器的透明路由。同時插件式架構也方便開發者擴展其功能。

1. 安裝

rpm -ivh mysql-router-2.0.4-1.el6.x86_64.rpm

2. 配置文件

2.1?配置文件語法

2.1.1 注釋

支持 # 和 ; 作為注釋

不支持行尾的注釋

2.1.2 section

[section name:optional section key]

option = value

option = value

option = value

[section name]

option = value

option = value

option = value

每個section 包含一個name和一個可選的key,[ ]內不能有空格。但是鍵值對可以含有空格,服務器會自動忽略。且鍵值對大小寫不敏感。

可以使用{ }引用變量。當{ }內的變量名沒有定義,就使用字面意思。

[DEFAULT]

prefix = /usr/

[sample]

bin = {prefix}bin/{name}

lib = {prefix}lib/{name}

name = magic

directory = C:\foo\bar\{3a339172-6898-11e6-8540-9f7b235afb23}

所以,這里 directory = C:\foo\bar\3a339172-6898-11e6-8540-9f7b235afb23。

2.2 配置文件位置

2.2.1 讀取順序

依次讀取:

/etc/mysqlrouter/mysqlrouter.ini

$HOME/.mysqlrouter.ini

另外,還可以使用兩個參數指定

-c : 當指定這個參數,就不掃描默認位置了。

-a: 指定額外胚子文件。當讀取了默認位置的配置文件(或用-c 指定的配置文件),緊接著讀取這個位置的配置文件。

如下所示:

shell> mysqlrouter -c /custom/path/to/router.ini -a /another/config.ini

3. 配置

3.1 general

bind_address 和 bind_port

將router綁定到哪個網絡接口NIC,

可以寫成

[routing:example_1]

bind_address =127.0.0.1

bind_port = 7001

或者

[routing:example_1]

bind_address =127.0.0.1:7001

Connect Timeout

connect_timeout = 1

允許范圍1-65536 ,read-write模式可以設置大一些,read-only模式要設置低一點。

Destinations

destinations= a.example.com,b.example.com,c.example.com

提供一個逗號分隔的用于建立連接使用的地址池。默認端口3306。

Modes

[routing:example_strategy]

bind_port = 7001

destinations = master1.example.com,master2.example.com,master3.example.com

mode = read-write

必須參數。

read-write:

主要用于路由到 mysql master。

In read-write mode, all traffic is directed to the initial address on the list. If that fails,then MySQL Router will try the next entry on the list, and will continue trying each MySQL server on the list. If no more MySQL servers are available on the list, then routing is aborted. This method is also known as ”first-available“。

第一個成功連接的服務器保存在內存中,以用于未來的連接請求,但這是一個臨時狀態,重啟就失去記憶了。

read-only:

主要用于路由到 slave 上。

使用一種簡單的 round-robin 方式來掃描服務器,第一個連接發送到第一個地址,第二個連接發送到第二個地址,以此類推,往返重復。如果其中一個地址不可達,直接跳過。不可達的地址將被隔離。當它恢復后,將被重新添加到可用隊列中。

Max Connections

max_connections = 512

類似于Mysql的max_connections,一種可用的應用是抵御DDOS,范圍從1-65536,默認512。

max_connect_errors

默認= 100 , 類似于 mysql 的 max_connect_errors 參數。

client_connect_timeout

默認 = 9 , 類似于 mysql 的? connect_timeout ,合法的范圍是 2-31536000.

3.2 Logging

[logger]

level = DEBUG

可選的有 INFO (default) 和 DEBUG,不區別大小寫。

INFO = all informational messages, warnings, and error messages

DEBUG= additional diagnostic information from the Router code, including successful routes.

默認是 INFO級別。這個需要在 [default]里先設置 logging_folder,如果 logging_folder 留空或者沒設置,將輸出到命令行。

3.3 配置文件demo

[DEFAULT]

logging_folder = /var/log/mysqlrouter #后面不指定具體的文件名

[logger]

level = DEBUG

[routing:failover]? # failover可選,方便理解

bind_port = 7001

mode = read-write

destinations = a.example.com,b.example.com,c.example.com

上面案例,read-write 模式,所有請求將轉發至 a.example.com ,當它掛了,轉發到 b.example.com,以此類推。但如果 read-only 模式,將使用round-robin 輪訓。

4. Router的應用

4.1 用戶選項

-v 顯示更多

-h 幫助

-c 指定配置文件

-a 指定額外配置文件

4.2 啟動Router

shell> mysqlrouter --config=/path/to/file/my_router.ini

2015-10-22 10:51:34 INFO [7f5f66768700] routing:basic_redirect started: listening on localhost:7001; read-write

2015-10-22 10:51:34 INFO [7f5f65f67700] routing:read_only_redirect started: listening on localhost:7002;

5. Plugins

5.1 Connection Routing 插件

[DEFAULT]

logging_folder = /var/log/mysql/router

config_folder = /usr/local/etc/mysqlrouter

plugin_folder = /usr/local/lib/mysqlrouter

runtime_folder = /usr/local/

[logger]

level = INFO

[routing]

bind_address = 127.0.0.1:7002

destinations = slave1.example.com,slave2.example.com,slave3.example.com

mode = read-only

其實就是前面講到的內容的一個簡單應用。

6. Q&A

6.1 Router 應該部署在哪?

應該和應用部署在一臺服務器上。

6.2 可以運行多個router實例嗎?

可以。

6.3 怎么部署router的高可用?

目前還木有。不過你可以使用腳本或類似的機制監控router。

6.4 router對性能會有影響嗎?

測試發現,大約會有1%的影響。

總結

以上是生活随笔為你收集整理的mysql router docker_MySQL Router 完全讲解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。