mysql-router的代理-负载均衡

再做mysql的读写分离时候,尝试了mysql-router中间组件发现mysql-router更多的是负载均衡的内容
centos6.7中yum库中有 mysql-router-community-8.0.13-1.el6.x86_64
直接yum安装后查看安装路径 rpm -ql mysql-router-community-8.0.13-1.el6.x86_64
在这里插入图片描述

[root@mycat3 mysqlrouter]# rpm -ql mysql-router-community-8.0.13-1.el6.x86_64
/etc/init.d/mysqlrouter   #发现已经添加到系统服务中了
/etc/mysqlrouter   #配置文件目录
/etc/mysqlrouter/mysqlrouter.conf #配置文件
/usr/bin/mysqlrouter
/usr/bin/mysqlrouter_plugin_info
/usr/lib64/libmysqlharness.so.1
/usr/lib64/libmysqlrouter.so.1
/usr/lib64/mysqlrouter
/usr/lib64/mysqlrouter/keepalive.so
/usr/lib64/mysqlrouter/metadata_cache.so
/usr/lib64/mysqlrouter/mysql_protocol.so
/usr/lib64/mysqlrouter/routing.so
/usr/lib64/mysqlrouter/syslog.so
/usr/share/doc/mysql-router-community-8.0.13
/usr/share/doc/mysql-router-community-8.0.13/LICENSE.router
/usr/share/doc/mysql-router-community-8.0.13/README.router
/var/log/mysqlrouter
/var/run/mysqlrouter

编辑mysqlrouter.conf配置文件

[root@mycat3 mysqlrouter]# vim /etc/mysqlrouter/mysqlrouter.conf

# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
#
# 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 also distributed 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 included with MySQL.
#
# 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 = /var/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:read_write]      #增加读写组件
bind_address = 192.168.3.3  #代理主机ip
bind_port = 7001   #代理主机的端口
destinations = 192.168.3.7:3306   #后端逻辑库
mode = read-write  #模式为可读可写

  [routing:read_only]    # 增加可读组件
    bind_address = 192.168.3.3  #代理主机ip
    bind_port = 7002   #代理主机端口
    destinations = 192.168.3.8:3306   #后端逻辑库
    mode = read-only   #模式为可读

其中在可读可写组件中可增加多条库名 形成可读可写库池,根据算法来负载均衡,选择哪一条;
也可以在可读组件中添加更多slave库,形成了可读库池,根据算法来负载均衡,选择可读库池中的一条
更像是拿出代理主机的某一个端口,指定来代理某一个功能,可读可写给一个端口,把这个端口指定功能(可读可写)后端逻辑库的池,通过算法来负载均衡,选择库池中的一个。

猜你喜欢

转载自blog.csdn.net/weixin_43945743/article/details/85116647
今日推荐