maxscale实现MySQL负载均衡

maxscale实现MySQL负载均衡

原因

因为公司最近的请求量逐渐增加,原本的一主一从服务器无法支撑起系统的稳定运行,需要扩充从库,但从库扩大,如何保证所有的数据库可以进行负载均衡呢?找了一些大佬,了解到可以使用maxscale达到此目的。


准备

服务器基本配置
服务器 配置 备注
阿里云服务器(119) 4核8G master(主库)
阿里云服务器(39) 16核32G slave1(从库一)
电信服务器(59) 8核16G slave2(从库二)
阿里云服务器(40) 2核4G master2(备库)

系统配置
软件 版本 备注
CentOS 7.5
MySQL 5.7
maxscale 2.4

动手

1、首先,配置MySQL主从,实现主从复制

2、配置Maxscale

#maxscale配置
# MaxScale documentation:
# https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-23/

# Global parameters
#
# Complete list of configuration options:
# https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-maxscale-configuration-usage-scenarios/

[maxscale]
threads=auto

# Server definitions
#
# Set the address of the server to the network
# address of a MariaDB server.
#

[server1]
type=server
address=119.*.*.*
port=3306
protocol=MariaDBBackend

[server2]
type=server
address=39.*.*.*
port=3306
protocol=MariaDBBackend

[server3]
type=server
address=59.*.*.*
port=3306
protocol=MariaDBBackend

[server4]
type=server
address=40.*.*.*
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/mariadb-maxscale-23-mariadb-monitor/

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server4
user=
password=
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-23-readconnroute/

[Read-Only-Service]
type=service
router=readconnroute
servers=server2,server3
user=
password=
router_options=slave

# ReadWriteSplit documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-23-readwritesplit/

[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server4
user=
password=

# 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




在maxscale配置中,最新版2.4中容易踩的坑有:

1、2.4中移除MySQL驱动,全部统一使用MariaDB驱动,即上面配置文件中,选择驱动的时候,不需要修改**[MariaDB Monitor][MySQL Monitor]**

2、maxscale连接的字符串为你在主服务器所创建的账号,例如:账号是eee,密码是:123456,那么连接的字符串就是

mysql -ueee -p123456 -H127.0.0.1 -P4006

引用

1、MySQL主从备份方案

2、Maxscale配置方案

3、Maxscale官方文档

你可能感兴趣的:(运维)