这是一个简短的示例,用于演示如何部署 MySQL Router 以使用引导程序使用 InnoDB Cluster。有关其他信息,请参阅
--bootstrap
和其他
引导程序选项。
此示例使用
--directory
选项创建一个独立的 MySQL Router 实例,启用套接字,用于--account
自定义 Router 的 MySQL 用户名,
如果帐户尚不存在,则设置为仅引导--account-create
;
always
并创建它。此示例假定名为的 InnoDB ClustermyCluster
已经存在。
$> mysqlrouter --bootstrap root@localhost:3310 --directory /tmp/myrouter --conf-use-sockets --account routerfriend --account-create always
Please enter MySQL password for root:
# Bootstrapping MySQL Router instance at '/tmp/myrouter'...
Please enter MySQL password for routerfriend:
- Creating account(s)
- Verifying account (using it to run SQL queries that would be run by Router)
- Storing account in keyring
- Adjusting permissions of generated files
- Creating configuration /tmp/myrouter/mysqlrouter.conf
# MySQL Router configured for the InnoDB Cluster 'myCluster'
After this MySQL Router has been started with the generated configuration
$ mysqlrouter -c /tmp/myrouter/mysqlrouter.conf
the cluster 'myCluster' can be reached by connecting to:
## MySQL Classic protocol
- Read/Write Connections: localhost:6446, /tmp/myrouter/mysql.sock
- Read/Only Connections: localhost:6447, /tmp/myrouter/mysqlro.sock
## MySQL X protocol
- Read/Write Connections: localhost:6448, /tmp/myrouter/mysqlx.sock
- Read/Only Connections: localhost:6449, /tmp/myrouter/mysqlxro.sock
此时,引导进程已在
mysqlrouter.conf
指定目录中创建了一个包含所需文件的文件,结果将向您展示如何启动此 MySQL Router 实例。生成的 MySQL Router 目录类似于:
$> ls -l | awk '{print $9}'
data/
log/
mysqlrouter.conf
mysqlrouter.key
run/
start.sh
stop.sh
生成的 MySQL 路由器配置文件 ( mysqlrouter.conf
) 类似于:
# File automatically generated during MySQL Router bootstrap
[DEFAULT]
logging_folder=/tmp/myrouter/log
runtime_folder=/tmp/myrouter/run
data_folder=/tmp/myrouter/data
keyring_path=/tmp/myrouter/data/keyring
master_key_path=/tmp/myrouter/mysqlrouter.key
connect_timeout=15
read_timeout=30
dynamic_state=/tmp/myrouter/data/state.json
[logger]
level = INFO
[metadata_cache:myCluster]
cluster_type=gr
router_id=1
user=routerfriend
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
socket=/tmp/myrouter/mysql.sock
destinations=metadata-cache://myCluster/?role=PRIMARY
routing_strategy=first-available
protocol=classic
[routing:myCluster_ro]
bind_address=0.0.0.0
bind_port=6447
socket=/tmp/myrouter/mysqlro.sock
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
socket=/tmp/myrouter/mysqlx.sock
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
socket=/tmp/myrouter/mysqlx.sock
destinations=metadata-cache://myCluster/?role=SECONDARY
routing_strategy=round-robin-with-fallback
protocol=x
在此示例中,MySQL Router 配置了四个端口和四个套接字。端口是默认添加的,套接字是通过传入添加的
--conf-use-sockets
。名为“myCluster”的 InnoDB Cluster 是元数据的来源,destinations
使用 InnoDB Cluster 元数据缓存来动态配置主机信息。相关的命令行选项:
--conf-use-sockets
: Optionally enable UNIX domain sockets for all four connection types, as demonstrated in the example.--conf-skip-tcp
: Optionally disable TCP ports, an option to pass in with--conf-use-sockets
if you only want sockets.--conf-base-port
: Optionally change the range of ports rather than using the default ports. This sets the port for classic read-write (PRIMARY) connections, and defaults to 6446.--conf-bind-address
: Optionally change the bind_address value for each route.
To demonstrate MySQL Router's behavior, the following client (application) connects to port 6446 but is connected to a MySQL instance on port 3310.
$> mysql -u root -h 127.0.0.1 -P 6446 -p
...
mysql> select @@port;
+--------+
| @@port |
+--------+
| 3310 |
+--------+
1 row in set (0.00 sec)
有关其他示例,请参阅 设置 MySQL 服务器沙箱 和部署生产 InnoDB 集群。