MySQL Router
MySQL Router 是 MySQL 官方提供的一款轻量级中间件,用于在应用程序和 MySQL 数据库集群之间进行路由和负载均衡。它通常被用于高可用性和扩展性场景,主要功能包括:
负载均衡:将数据库请求分配到多个 MySQL 实例上,从而提高系统的整体性能和可靠性。
高可用性:在主从复制或 MySQL 集群环境中,自动检测并路由请求到可用的数据库实例,以确保服务的持续可用性。
读写分离:可以根据配置将读操作和写操作分配到不同的数据库实例上,以优化资源使用。
故障转移:在主实例发生故障时,自动将请求路由到备份实例,确保数据库服务的连续性。
简化应用程序配置:应用程序只需连接到 MySQL Router,而不需要知道具体的数据库实例地址和配置,简化了应用程序的部署和管理。
版本:8.4.2
yum install mysql-router -y配置文件:/etc/mysqlrouter/mysqlrouter.conf
# Copyright (c) 2015, 2024, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is designed to work with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have either included with
# the program or referenced in the documentation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# MySQL Router configuration file
#
# Documentation is available at
# http://dev.mysql.com/doc/mysql-router/en/
[DEFAULT]
logging_folder = /var/log/mysqlrouter
runtime_folder = /run/mysqlrouter
config_folder = /etc/mysqlrouter
[logger]
level = INFO
# 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
# [routing:myCluster_rw]
# bind_address=0.0.0.0
# bind_port=3311
# destinations=metadata-cache://myCluster/?role=PRIMARY
# routing_strategy=first-available
# protocol=classic
# [routing:myCluster_ro]
# bind_address=0.0.0.0
# bind_port=3312
# destinations=metadata-cache://myCluster/?role=SECONDARY
# routing_strategy=round-robin-with-fallback
# protocol=classic
# [routing:myCluster_rw]
# bind_address=0.0.0.0
# bind_port=3313
# destinations=metadata-cache://myCluster/?role=PRIMARY
# routing_strategy=first-available
# protocol=classic
[routing:myCluster_rw]
bind_address=0.0.0.0
bind_port=3314
destinations=192.168.160.11:3306
routing_strategy=first-available
protocol=classic服务控制
systemctl start mysqlrouter
systemctl enable mysqlrouter使用
mysql -u user -p -h 127.0.0.1 -P 3314最后更新于