安装maxscale MySql读写分离

安装rpm

yum install gnutls libaio.x86_64 libaio-devel.x86_64 novacom-server.x86_64 libedit -y
wget https://downloads.mariadb.com/MaxScale/2.2.0/centos/7server/x86_64/maxscale-2.2.0-1.centos.7.x86_64.rpm
rpm -ivh maxscale-2.2.0-1.centos.7.x86_64.rpm

MaxScale服务器修改配置

vi /etc/maxscale.cnf
[maxscale]
threads=1

# 主服务器  3306
[server1]
type=server
address=192.168.91.108
port=3306
protocol=MySQLBackend

# 配置从服务器  3306
[server2]
type=server
address=192.168.91.109
port=3306
protocol=MySQLBackend

[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1,server2
user=root
passwd=123456
monitor_interval=10000
detect_stale_master=true

[Read-Write Service]
type=service
router=readwritesplit
servers=server1,server2
user=root
passwd=123456
max_slave_connections=100%
use_sql_variables_in=master
enable_root_user=1
max_slave_replication_lag=3600

[MaxAdmin Service]
type=service
router=cli

[Read-Write Listener]
type=listener
service=Read-Write Service
protocol=MySQLClient
port=3306

[MaxAdmin Listener]
type=listener
service=MaxAdmin Service
protocol=maxscaled
socket=default

启动maxscale服务

maxscale --config=/etc/maxscale.cnf
netstat -ntelp   #主要查询3306 端口是否监听

查看maxscale 服务状态

maxadmin

> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server             | Address         | Port  | Connections | Status              
-------------------+-----------------+-------+-------------+--------------------
server1            | 主服务器ip  | 10336 |           0 | Master, Running
server2            | 从服务器ip  | 10336 |           0 | Slave, Running
-------------------+-----------------+-------+-------------+--------------------


至此,完成MaxScale中间件实现MySQL读写分离。

你可能感兴趣的:(mysql,读写分离)