10.Mysql Router

1.Mysql Router 是 Innodb cluster 集群的一部分,是轻量级中间件,为应用程序和后端Mysql服务器之前提供透明路由,下面就是它的一个架构设计。

2.现在Mysql routerer二进制安装包:https://dev.mysql.com/downloads/router/

3.安装并初始化并启动

  3.1 Bootstrapping  MySQL Router

  mysqlrouter --bootstrap  root@db01:3306 --directory /tmp/myrouter  --conf-use-sockets --account routerfriend --account-create always

      结果输出:

[mysql@db04 ~]$ mysqlrouter --bootstrap  root@db01:3306 --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 'ClusterTest'     ##这里是mysqlrouter识别出的innodb cluster 集群名称
 
After this MySQL Router has been started with the generated configuration

    $ mysqlrouter -c /tmp/myrouter/mysqlrouter.conf                ##这里是mysqlrouter配置文件

the cluster 'ClusterTest' 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 --bootstrap  root@db01:3306 --directory /tmp/myrouter  --conf-use-sockets --account routerfriend --account-create always

--bootstrap: 通过在提供的URI上连接到InnoDB集群元数据服务器来执行MySQL路由器引导的主要选项。MySQL Router根据从InnoDB集群元数据服务器检索到的信息进行配置,后面跟上集群中某一个数据库节点
--directory:指定mysqlrouter安装位置
--conf-use-sockets: 通过socket方式连接
--account:自定义路由器的mysql用户名
--account-create:当设置为always时仅在不存在时引导,并创建它。

 3.2 启动MysqlRouter

    cd  /tmp/myrouter

    ./start.sh

4.连接测试

[root@db04 myrouter]# mysql -u root -h 127.0.0.1 -P 6446 -p123   #6446是RW节点

[root@db04 myrouter]# mysql -u root -h 127.0.0.1 -P 6447 -p123   #6447是RO节点

 参考:https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-preface.html

关于配置文件文件中的说明可以参考: https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-conf-options.html

[DEFAULT]

master_total_connections:路由器允许的客户端连接的最大总数,默认是512,这个参数主要是防止文件描述符耗尽

thread_stack_size: 分配给每个线程堆栈的内存大小(以KB为单位),默认是64k

posted on 2022-07-08 22:08  太白金星有点烦  阅读(732)  评论(0编辑  收藏  举报

导航