MySQL Router 8.4  /  組態  /  組態位置

4.2 組態位置

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

預設組態檔位置

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

您可以使用 -DROUTER_CONFIGDIR=<路徑> 選項在編譯時變更預設位置。您也可以編輯 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 啟動的獨立安裝會將 mysqlrouter.conf 新增至 --directory 定義的目錄。

預設組態檔位置 (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 啟動的獨立安裝會將 mysqlrouter.conf 新增至 --directory 定義的目錄。

叢集元數據中的 MySQL Router 組態

自 MySQL Router 8.4 起,針對 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.routersattributes 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"
} |