MySQL8.0环境下MySQLRouter介绍
MySQL Router是MySQL Proxy的替代⽅案,MySQL官⽅不建议将MySQL Proxy⽤于⽣产环境,并且已经不提供MySQL Proxy的下载。在后期的使⽤中,没有出⾊的表现,因为proxy除了读写分离,没有其他作⽤,也⽆法动态更改配置。
InnoDB Cluster中MySQL Router充当代理,向应⽤程序隐藏⽹络上的多个MySQL实例,并将数据请求映射到其中⼀个集实例。MySQL Router的推荐部署模型是与InnoDB Cluster集成。
功能
oracle查询前10条数据
1.Failover
⼀个⾼可⽤的MySQL设置由⼀个主服务器和多个从服务器组成,由应⽤程序处理故障转移,以防MySQL主服务器变得不可⽤。使⽤MySQL路由器,应⽤程序连接将根据负载平衡策略透明地进⾏路由
2.Load Balancing
MySQL路由器通过在⼀个服务器池中分布数据库连接来提供额外的可伸缩性和性能。例如,如果您有⼀组复制的MySQL服务器,MySQL 路由器可以以循环⽅式将应⽤程序连接分发给它们。
3.Pluggable Architecture:
MySQL⽤户提供了创建⾃⼰的定制插件的能⼒,从⽽提供了⽆限的可能性。MySQL路由器⽬前提供了⼀些核⼼插件,包括:
连接路由插件,它做基于连接的路由,这意味着它将MySQL数据包转发到后端服务器,⽽不检查或修改它们,从⽽提供最⼤的吞吐量。
元数据缓存插件,它提供透明的客户端负载平衡、路由和故障转移到组复制和InnoDB集
Router中间件本⾝不会对请求“拆包”(unpackage),所以⽆法在Router中间件上实现⽐如“SQL审计”、“隔离”、“限流”、“分库分表”等功能。但是Router提供了plugin(C语⾔)机制,⽤户可以开发⾃⼰的plugin来扩展Router的额外特性。
原理:
Router作为⼀个流量转发层,位于应⽤与MySQL服务器之间,其功能类似于LVS。
MySQL Router的⼯作流程如下:
1.MySQL客户端连接到MySQL Router。
2.Router检查可⽤的MySQL服务器。
3.Router打开⼀个适⽤MySQL服务器的TCP连接。
4.Router在应⽤程序和MySQL服务器之间来回转发数据包
5.如果连接的MySQL服务器出现故障, Router将断开连接。当应⽤程序重试连接到Router时,Router选择另⼀个可⽤MySQL服务器。
简单理解,应⽤不再直连MySQL Servers,⽽是与Router相连,根据Router的配置,将会把应⽤程序的读写请求转发给MySQL
Servers。当有多个MySQL Servers,⽆论主、从,Router可以对读写请求进⾏负载均衡。当某个Server失效时,Router可以将其从
Active列表中移除,当其online后再次加⼊Active列表,即提供了Failover特性。如果使⽤InnoDB Cluster模式,那么Router还能基于metaCache(metaServers)机制,感知MySQL的主从切换、从库增减等集拓扑变更,⽽且基于变更能够实现Master⾃动切换、
Slaves列表⾃动装配等。
安装部署:
发现⼀个现象,router之前是2.0之后的版本下载,跟mysql版本⼀样,都有有⼩版本。有些环境下 router版本和mysql 版本不对称,出现
⽐较严重的故障。
1.安装
[root@ss30 softwares]# tar -xvf mysql-router-8.0.19-linux-glibc2.12-x86_
mysql-router-8.0.19-linux-glibc2.12-x86_64/bin/mysqlrouter_keyring
用户管理界面模板mysql-router-8.0.19-linux-glibc2.12-x86_64/bin/mysqlrouter
mysql-router-8.0.19-linux-glibc2.12-x86_64/bin/mysqlrouter_passwd
mysql-router-8.0.19-linux-glibc2.12-x86_64/bin/mysqlrouter_plugin_info
mysql-router-8.0.19-linux-glibc2.12-x86_uter
[root@ss30 softwares]# mv mysql-router-8.0.19-linux-glibc2.12-x86_64 mysqlRouter8.0.19
[root@ss30 bin]# vi /etc/profile
#MySQLRouter8.0.19
export PATH=/opt/idc/softwares/mysqlRouter8.0.19/bin:$PATH
[root@ss30 bin]# source /etc/profile
2.创建⽬录
[root@ss30 mysqlrouter]# mkdir -p /opt/mysqlrouter/data
[root@ss30 mysqlrouter]# mkdir -p /opt/mysqlrouter/log
[root@ss30 mysqlrouter]# mkdir -p /opt/mysqlrouter/run
[root@ss30 mysqlrouter]# mkdir -p /opt/mysqlrouter/config
[root@ss30 mysqlrouter]# cp /opt/idc/softwares/mysqlRouter8.0.19/share/doc/mysqlrouter/sample_m
手机sqlite编辑器
读写分离配置
配置信息:
[root@ss30 mysqlrouter]# vi /opt/mysqlrouter/f [DEFAULT]
mysql无法连接到服务器logging_folder        = /opt/mysqlrouter/log
plugin_folder          = /opt/idc/softwares/mysqlRouter8.0.19/lib/mysqlrouter
ascii标准编码表
config_folder          = /opt/mysqlrouter/config
runtime_folder        = /opt/mysqlrouter/run
data_folder            = /opt/mysqlrouter/data
client_connect_timeout = 2
connect_timeout        = 2
read_timeout          = 30
max_connections        = 2048
# keyring_path = /var/lib/keyring-data
# master_key_path = /var/lib/keyring-key
[logger]
level = DEBUG
timestamp_precision = second
[routing:primary]
# To be more transparent, use MySQL Server port 3306
bind_address    = 0.0.0.0
bind_port        = 7001
routing_strategy = first-available
mode            = read-write
destinations    = 192.168.244.130:3410
[routing:secondary]
# To be more transparent, use MySQL Server port 3306
bind_address    = 0.0.0.0
bind_port        = 7002
routing_strategy =  round-robin
mode            = read-only
destinations    = 192.168.244.144:4310,192.168.244.130:3410
# If no plugin is configured which starts a service, keepalive
# will make sure MySQL Router will not immediately exit. It is
# safe to remove once Router is configured.
[keepalive]
interval        = 60
启动
[root@ss30 mysqlrouter]# mysqlrouter -c /opt/mysqlrouter/f &从安装到部署,⾮常简单。涉及的参数也少。
MGR节点
配置信息:通过命令 相关的配置信息会⾃动⽣成
[root@ss30 mysqlrouter]# mysqlrouter --bootstrap root@192.168.244.129:3380 --directory /opt/mysqlrouter/mgr --user=root
⽬录结构
# File automatically generated during MySQL Router bootstrap [DEFAULT]
user=root
logging_folder=/opt/mysqlrouter/mgr/log
runtime_folder=/opt/mysqlrouter/mgr/run
data_folder=/opt/mysqlrouter/mgr/data
keyring_path=/opt/mysqlrouter/mgr/data/keyring
master_key_path=/opt/mysqlrouter/mgr/mysqlrouter.key connect_timeout=15
read_timeout=30
dynamic_state=/opt/mysqlrouter/mgr/data/state.json
[logger]课程教学网站的设计与实现
level = INFO
[metadata_cache:mgrCluster]
cluster_type=gr
router_id=1
user=mysql_router1_zesa3g471bns
metadata_cluster=mgrCluster
ttl=0.5
use_gr_notifications=0
[routing:mgrCluster_rw]
bind_address=0.0.0.0
bind_port=6446
destinations=metadata-cache://mgrCluster/?role=PRIMARY routing_strategy=first-available
protocol=classic
[routing:mgrCluster_ro]
bind_address=0.0.0.0
bind_port=6447
destinations=metadata-cache://mgrCluster/?role=SECONDARY routing_strategy=round-robin-with-fallback
protocol=classic
[routing:mgrCluster_x_rw]
bind_address=0.0.0.0
bind_port=64460
destinations=metadata-cache://mgrCluster/?role=PRIMARY routing_strategy=first-available
protocol=x
[routing:mgrCluster_x_ro]
bind_address=0.0.0.0
bind_port=64470
destinations=metadata-cache://mgrCluster/?role=SECONDARY routing_strategy=round-robin-with-fallback
protocol=x
mgr,router集创建构成中,创建的账号

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。