使用Maxscale实现mysql读写分离
发表于:2025-11-09 作者:千家信息网编辑
千家信息网最后更新 2025年11月09日,MaxScale 是 MariaDB 的产品之一,可以很方便的实现读写分离方案;并且提供了读写分离的负载均衡和高可用性保障。一、安装配置前提:先配置好mysql的主从,Maxscale会自动的根据主从
千家信息网最后更新 2025年11月09日使用Maxscale实现mysql读写分离
MaxScale 是 MariaDB 的产品之一,可以很方便的实现读写分离方案;并且提供了读写分离的负载均衡和高可用性保障。
一、安装配置
前提:先配置好mysql的主从,Maxscale会自动的根据主从复制信息来判断Master和slave
注:不能配置mysql互为主从,如果互为主从,两台都会被认为slave,在这种情况下,写请求会被拒绝,只接受读请求。
1.1.安装
官网下载对应的rpm包,
wget https://downloads.mariadb.com/MaxScale/2.0.3/centos/6server/x86_64/maxscale-2.0.3-1.centos.6.x86_64.rpmrpm -ivh maxscale-2.0.3-1.centos.6.x86_64.rpm
maxscale的配置文件为:/etc/maxscale.conf,配置文件由多个配置模块组成
vi /etc/maxscale.conf#全局配置:[maxscale]threads=autolog_info=1log_notice=1log_warning=1#后端mysql定义[server1]type=serveraddress=192.168.10.1port=3306protocol=MySQLBackend[server2]type=serveraddress=192.168.10.2port=3306protocol=MySQLBackend#监控配置[MySQL Monitor] type=monitormodule=mysqlmon #监控模块默认使用mysqlmon,当然还有其他可选择的模块servers=server1,server2user=admin #admin监控后端mysql的复制状况,必须具有REPLICATION CLIENT权限 passwd=123456monitor_interval=10000#触发器定义 注意,以下两句的上下顺序不能变,不然无法生效script=/opt/mysql_monitor.sh #定义事件触发脚本执行events=master_down #事件触发器当master down时,执行上面的脚本,maxscale内置了很 多的events#读写分离service[Read-Write Service] type=servicerouter=readwritesplit #读写分离路由模式servers=server1,server2user=maxscale #该用户从后端mysql获取用户信息,对客户端进行身份验证,必须具有mysql.user table的select权限 passwd=maxscalemax_slave_connections=100% max_slave_replication_lag=3600000 #当slave的数据落后master小于3600秒时仍然可用connection_timeout=300 router_options=master_failure_mode=error_on_write #允许master down掉,slave仍然可读#router_options=master_accept_reads=true #允许master接受读请求[Read-Write Listener] type=listenerservice=Read-Write Serviceprotocol=MySQLClientport=3306#管理服务配置 [MaxAdmin Service]type=servicerouter=cli#管理服务监听[MaxAdmin Listener]type=listenerservice=MaxAdmin Serviceprotocol=maxscaledsocket=default
二、管理
Maxscale提供了maxadmin命令用于查看管理
[root@server ~]# maxadmin list -Unknown or missing option for the list command. Valid sub-commands are: clients List all the client connections to MaxScale dcbs List all the DCBs active within MaxScale filters List all the filters defined within MaxScale listeners List all the listeners defined within MaxScale modules List all currently loaded modules monitors List all monitors services List all the services defined within MaxScale servers List all the servers defined within MaxScale sessions List all the active sessions within MaxScale threads List the status of the polling threads in MaxScale
[root@server ~]# maxadmin list serversServers.-------------------+-----------------+-------+-------------+--------------------Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+--------------------server1 | 192.168.10.1 | 3306 | 0 | Master, Runningserver2 | 192.168.10.2 | 3306 | 0 | Slave, Running-------------------+-----------------+-------+-------------+--------------------
三、高可用性
Maxscale默认只提供读的高可用性,要实现写的高可用性,可以使用两种途径:
1.需要使用Multi-MasterMonitor监控模块,不同于上文使用的mysqlmon模块,该模块是通过read_only参数来选举Master和Slave,结合脚本可以实现在Master fail的时候,取消slave的read_only属性,将slave提升为Master
2.使用高可用软件MMM
配置
模块
主从
可用性
监控
管理
脚本
事件
信息
文件
权限
用户
管理服务
触发器
服务
均衡
上下
上文
产品
全局
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
后端软件开发技术面试会问什么
ip网络技术与工程实验论文
厦门易灵网络技术
数据库音乐库管理系统
mc电脑pvp服务器
dealogic数据库使用
命令框快捷键数据库
云服务器 便宜
小学生青少年网络安全
万鹏网络技术有限公司
数据库正则 中文
成都信息工程大学数据库填空
服务器1u2u
jsp 与数据库链接
数据库 查询时间段
我的世界1.8.1服务器
永兴学电脑软件开发学费多少
比亚迪软件开发工资多少
空间网络安全考研
有关网络安全的资料讲座
网络安全指挥大屏
《网络安全阀》
网络安全知识免费课程
北京网络技术有限公司待遇
东莞找大状软件开发
打印服务器连接wifi
天翼关系型数据库使用指南
河北公路软件开发公司
和平精英战神服务器设置
nba2k22服务器在哪