原理:客户端向mysql代理请求服务时,代理会把写的请求交给A 服务器处理,把读的请求交给B处理。
maxscale 代理软件
rpm -ivh maxscale-2.1.2-1.rpm
修改配置文件 vim /etc/maxscale.cnf
[server1]
type=server //定义数据库服务器主机名
address=192.168.4.50
port=3306
protocol=MySQLBackend
[server2]
type=server
address=192.168.4.50
port=3306
protocol=MySQLBackend
[MySQL Montior]
type=montior
module=mysqlmon
servers=server1, server2
user=scalemon
password=123456
monitor_interval=1000
[Read-Write Service]
type=service
router=readwritesplit
servers=server1, server2
user=maxscale
password=123456
max_slave_connections=100%
在主从服务器授权用户
grant replication slave,replication client on *.* to scalemon@'%' identified by "123456"; //创建监控用户
grant select on *.* to maxscale@'%' identifued by '123456' ; //创建路由用户
grant all on *.* to admin@'%' identified by '123456'; //创建访问用户
启动服务
maxscale --config=/etc/maxscale.cnf
访问maxscale代理
mysql -h服务器地址 -P端口 -u用户名 -p密码