MySQL Router 9.0  /  組態  /  組態位置

4.2 組態位置

MySQL Router 會在啟動時掃描預設組態檔,並選擇性地從命令列載入使用者定義的組態檔。

預設組態檔位置

預設情況下,MySQL Router 會掃描特定位置的組態檔,這些位置取決於平台以及 MySQL Router 的設定方式。

您可以使用 -DROUTER_CONFIGDIR=<path> 選項在編譯時變更預設位置。您也可以編輯 cmake/settings.cmake 以在編譯 MySQL Router 之前變更預設位置,從而為特定平台新增新的位置或例外情況。

執行 mysqlrouter --help 以查看系統上的預設組態檔位置 (及其可用性)。例如

$> mysqlrouter --help

...

Start MySQL Router.

Configuration read from the following files in the given order (enclosed
in parentheses means not available for reading):
  (/usr/local/mysql-router/mysqlrouter.conf)
  /Users/philip/.mysqlrouter.conf
Plugins Path:
  /usr/local/lib/mysqlrouter
Default Log Directory:
  /usr/local/mysql-router
Default Persistent Data Directory:
  /usr/local/mysql-router/data
Default Runtime State Directory:
  /usr/local/mysql-router/run

Usage: mysqlrouter [-v|--version] [-h|--help]

...
重要

如果使用 --config 選項傳入使用者定義的組態檔,則不會載入預設組態檔。

在 Linux 上,MySQL Router 預設會掃描以下位置,儘管這些位置取決於系統

  1. /etc/mysqlrouter/mysqlrouter.conf

    注意

    與 MySQL 伺服器不同,不支援向後相容的路徑 "/etc/mysqlrouter.conf"。

  2. $HOME/.mysqlrouter.conf

注意

為了向後相容性,MySQL Router 還會搜尋每個目錄中的 .ini 變體。這樣做時,Router 會在初始目錄中搜尋 .conf 版本,然後檢查 .ini 版本,然後在下一個目錄 (通常是系統上的使用者主目錄) 中重複此過程。

使用者定義和額外的組態檔

兩個命令列選項有助於控制這些組態檔位置

  • --config (或 -c):從此檔案讀取基本組態,且不使用或掃描預設檔案路徑。

    使用範例:當使用 --directory 引導啟動選項產生獨立的 MySQL Router 安裝時,產生的 start.sh 會將此選項傳遞至該目錄內產生的 mysqlrouter.conf

  • --extra-config (或 -a):在從預設位置或使用 --config 選項指定的檔案讀取組態檔之後,讀取此額外組態檔。

例如

$> mysqlrouter --config /custom/path/to/router.conf --extra-config /another/config.conf

可以傳入多個額外組態選項,並且會按照輸入的順序載入檔案,其中 --config 選項會在 --extra-config 選項之前載入。例如

$> mysqlrouter --extra-config a.conf --config b.conf --extra-config c.conf

在上面的範例中,首先載入 b.conf,然後依序載入 a.confc.conf。此外,由於使用了 --config,因此不會載入預設組態檔,例如 /etc/mysqlrouter/mysqlrouter.conf

每個載入的組態檔都會覆寫先前讀取的組態檔中的組態設定。

預設組態檔位置 (Linux)

以下列出路由器在常用的 Linux 平台上讀取組態檔的預設檔案位置。

注意

執行 mysqlrouter --help 以查看系統上的預設組態檔位置 (及其可用性)。

  • /usr/local 下的預設系統範圍安裝:/usr/local/etc/mysqlrouter.conf

  • RPM 和 Debian:/etc/mysqlrouter/mysqlrouter.conf

  • 在所有系統上,使用 --directory 的引導啟動獨立安裝會在 --directory 定義的目錄中新增 mysqlrouter.conf

預設組態檔位置 (Windows)

MySQL Router 在 Windows 上搜尋組態檔的預設檔案位置。

注意

執行 mysqlrouter.exe --help 以查看系統上的預設組態檔位置 (及其可用性)。

  • C:\ProgramData\MySQL\MySQL Router 下的預設系統範圍安裝:C:\ProgramData\MySQL\MySQL Router\mysqlrouter.conf

  • 此外:C:\Users\username\AppData\Roaming\mysqlrouter.conf,其中 username 會替換為您的系統使用者。

  • 除了 mysqlrouter.conf 之外,為了向後相容性,系統還會搜尋 mysqlrouter.ini

  • 使用 --directory:使用 --directory 的引導啟動獨立安裝會在 --directory 定義的目錄中新增 mysqlrouter.conf

叢集元數據中的 MySQL Router 組態

針對 InnoDB 叢集引導啟動的路由器的完整組態儲存在 InnoDB 叢集元數據架構中,並且可以使用 MySQL Shell 作業 object.routerOptions (適用於叢集、叢集集和複本集) 讀取。

組態以 JSON 格式儲存在每個路由器的 mysql_innodb_cluster_metadata.routers 資料表中,每個路由器一列。每個路由器的列會在啟動或重新啟動時由路由器更新。

例如

        mysql>  select JSON_PRETTY(attributes->>'$.Configuration') as Configuration from mysql_innodb_cluster_metadata.routers \G
        
        Configuration: {
"io": {
    "backend": "poll",
    "threads": 0
},
"common": {
    "name": "system",
    "user": "",
    "read_timeout": 30,
    "client_ssl_key": "/Users/areliga/dev/server/mysql-trunk/build/pt/data/router-key.pem",
    "client_ssl_cert": "/Users/areliga/dev/server/mysql-trunk/build/pt/data/router-cert.pem",
    "client_ssl_mode": "PREFERRED",
    "connect_timeout": 5,
    "server_ssl_mode": "PREFERRED",
    "server_ssl_verify": "DISABLED",
    "max_total_connections": 512,
    "unknown_config_option": "error",
    "router_require_enforce": true,
    "max_idle_server_connections": 64
},
"loggers": {
    "filelog": {
    "level": "info",
    "filename": "mysqlrouter.log",
    "destination": "",
    "timestamp_precision": "second"
    }
},
"endpoints": {
    "bootstrap_ro": {
    
    ......
    
    }
   }

如需詳細資訊,請參閱使用 MySQL Shell 檢視路由器組態

為了向後相容性,MySQL Router 仍會將一些組態參數儲存在 mysql_innodb_cluster_metadata.routers 中的 attributes JSON 中。

例如

select JSON_PRETTY(attributes) from mysql_innodb_cluster_metadata.routers;
| {
  "ROEndpoint": "6447",
  "RWEndpoint": "6446",
  "ROXEndpoint": "6449",
  "RWXEndpoint": "6448",
  "RWSplitEndpoint": "6450",
  "MetadataUser": "mysql_router1_plje99d",
  "Configuration": { /*...*/ },
  "bootstrapTargetType": "cluster"
} |