MySQL Router 8.4  /  ...  /  組態檔範例

4.3.4 組態檔範例

以下是一個基本連線路由範例,連線至名為 myCluster 的 MySQL InnoDB 叢集。經典 MySQL 通訊協定和 X 通訊協定皆已啟用,它使用 TCP/IP 連線而非 Unix 網域通訊端,並且使用 --bootstrap 作為獨立組態產生,而 --directory 設定為 /tmp/router

在此範例中,讀寫(主要)流量會傳送到連接埠 6446 (傳統) 或 6448 (X 通訊協定),而唯讀(次要)流量則使用連接埠 6447 (傳統) 或 6449 (X 通訊協定) 存取。

路由區段索引鍵(例如 myCluster_rw)是選擇性的,但描述性的區段索引鍵有助於除錯,並且允許同一外掛程式的多個組態區段。

destinations 選項參考 metadata-cache,以利用 InnoDB 叢集的 metadata 快取,該快取會動態設定主機資訊。或者,destinations 也可以是逗號分隔的主機清單,以在沒有 InnoDB 叢集的情況下容納基本連線路由。

[http_server] 開頭的選項參考預設啟用的 REST API。如需其他詳細資訊,請參閱 第 6 章,MySQL Router REST API

# File automatically generated during MySQL Router bootstrap
[DEFAULT]
logging_folder=/tmp/router/log
runtime_folder=/tmp/router/run
data_folder=/tmp/router/data
keyring_path=/tmp/router/data/keyring
master_key_path=/tmp/router/mysqlrouter.key
connect_timeout=15
read_timeout=30
dynamic_state=/tmp/router/data/state.json
client_ssl_cert=/tmp/router/data/router-cert.pem
client_ssl_key=/tmp/router/data/router-key.pem
client_ssl_mode=PREFERRED
server_ssl_mode=AS_CLIENT
server_ssl_verify=DISABLED

[logger]
level = INFO

[metadata_cache:myCluster]
cluster_type=gr
router_id=1
user=mysql_router1_x9v4uk10nbcd
metadata_cluster=myCluster
ttl=0.5
auth_cache_ttl=-1
auth_cache_refresh_interval=2
use_gr_notifications=0

[routing:myCluster_rw]
bind_address=0.0.0.0
bind_port=6446
destinations=metadata-cache://myCluster/?role=PRIMARY
routing_strategy=first-available
protocol=classic

[routing:myCluster_ro]
bind_address=0.0.0.0
bind_port=6447
destinations=metadata-cache://myCluster/?role=SECONDARY
routing_strategy=round-robin-with-fallback
protocol=classic

[routing:myCluster_x_rw]
bind_address=0.0.0.0
bind_port=6448
destinations=metadata-cache://myCluster/?role=PRIMARY
routing_strategy=first-available
protocol=x

[routing:myCluster_x_ro]
bind_address=0.0.0.0
bind_port=6449
destinations=metadata-cache://myCluster/?role=SECONDARY
routing_strategy=round-robin-with-fallback
protocol=x

[http_server]
port=8443
ssl=1
ssl_cert=/tmp/router/data/router-cert.pem
ssl_key=/tmp/router/data/router-key.pem

[http_auth_realm:default_auth_realm]
backend=default_auth_backend
method=basic
name=default_realm

[rest_router]
require_realm=default_auth_realm

[rest_api]

[http_auth_backend:default_auth_backend]
backend=metadata_cache

[rest_routing]
require_realm=default_auth_realm

[rest_metadata_cache]
require_realm=default_auth_realm