mysql读写分离,负载均衡中间件MaxScale
MaxScale 出手于 MariaDB 开源社区,品质有保障,以下配置摘自6.4.0版本,此版本与网上搜索得到的文章中的配置2.X版本,有很大的区别,且我没有找到可以在重启前进行配置检查的方法,重启不成功则服务就停了,尬
使用maxscale前先搭建好数据库主从复制服务,数据库同步复制正常。
配置生成工具:https://sc.toolnb.com/tools/mysqlslave.html
主从复制错误修复工具:https://github.com/hcymysql/pt-slave-repair
如果在使用读写分离时,主库也想参与读查询,需要使用 master_accept_reads=true (允许使用主服务器进行读取,默认是false)
读写分离模块的文档参考:https://mariadb.com/kb/en/mariadb-maxscale-6-readwritesplit
# MaxScale documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-6/
# Global parameters
#
# Complete list of configuration options:
# https://mariadb.com/kb/en/mariadb-maxscale-6-mariadb-maxscale-configuration-guide/
[maxscale]
threads=auto
# Server definitions
#
# Set the address of the server to the network
# address of a MariaDB server.
#
[server1]
type=server
address=172.19.0.10
port=3306
protocol=MariaDBBackend
[server2]
type=server
address=172.19.0.14
port=3306
protocol=MariaDBBackend
[server3]
type=server
address=172.19.0.15
port=3306
protocol=MariaDBBackend
# Monitor for the servers
#
# This will keep MaxScale aware of the state of the servers.
# MariaDB Monitor documentation:
# https://mariadb.com/kb/en/maxscale-6-monitors/
[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
#servers=server1
user=scalemon
password=rseEk2zHc2nFTEz7
monitor_interval=2000
# Service definitions
#
# Service Definition for a read-only service and
# a read/write splitting service.
#
# ReadConnRoute documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-6-readconnroute/
#[Read-Only-Service]
#type=service
#router=readconnroute
#servers=server1
#user=maxscale
#password=maxscale
#router_options=slave
# ReadWriteSplit documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-6-readwritesplit/
[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=teaidata
password=rseEk2zHc2nFTEz7
#允许使用主服务器进行读取
master_accept_reads=true
# Listener definitions for the services
#
# These listeners represent the ports the
# services will listen on.
#
#[Read-Only-Listener]
#type=listener
#service=Read-Only-Service
#protocol=MariaDBClient
#port=4008
[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MariaDBClient
port=4006
address=0.0.0.0
版权属于:Joyber
本文链接:https://blog.qqvbc.com/default/589.html
转载时须注明出处及本声明