客户端访问数据的查询请求和写请求分别给不同的数据库服务器处理
减轻单台服务器的并发访问压力,提高机器硬件的利用率
处理写数据的服务器做master,读数据服务器做slave
2.在150上安装maxscale-2.1.2-1.rhel.7.x86_64.rpm
修改配置文件:/etc/maxscale.cnf,添加两个server
[maxscale]threads=auto #运行的线程的数量[server1] #定义数据库服务器type=serveraddress=10.10.10.101port=3306protocol=MySQLBackend #后端数据库[server2]type=serveraddress=10.10.10.102port=3306protocol=MySQLBackend[server3]type=serveraddress=10.10.10.103port=3306protocol=MySQLBackend[MySQL Monitor] #定义监控的数据库服务器type=monitormodule=mysqlmonservers=server1,server2,server3 #监控的数据库列表,不能写ipuser=scalemon #监视数据库服务器时连接的用户名scalemonpasswd=123456 #密码123456monitor_interval=10000 #监视的频率 单位为秒[Read-Write Service] #定义读写分离服务type=servicerouter=readwritesplitservers=server1,server2,server3user=maxscaled #用户名 验证连接代理服务时访问数据库服务器的用户是否存在passwd=123456max_slave_connections=100%[MaxAdmin Service] #定义管理服务type=servicerouter=cli[Read-Write Listener] #读写服务使用的端口号type=listenerservice=Read-Write Serviceprotocol=MySQLClientport=4006[MaxAdmin Listener] #管理服务使用的端口号type=listenerservice=MaxAdmin Serviceprotocol=maxscaledsocket=defaultport=4099 #手动添加,不指定时使用的是默认端口在启动服务以后可以知道默认端口是多少
3.根据配置文件的设置在两台服务器上添加监控用户和路由用户
replication slave #监控主从同步 replication client #监控服务状态grant replication slave,replication client on *.* to scalemon@"%" identified by "123456"grant select on mysql.user to maxscaled@"%" identified by "123456"
4.在150上启动服务
验证授权用户启动服务:maxscale -f /etc/maxscale.cnf停止服务:killall -9 maxscale
5.测试配置
查看管理信息(150主机自己访问自己) maxadmin -uadmin -pmariadb -P4099 list servers客户端连接57访问数据
6.测试数据读写分离
在主数据库上授权访问的用户
客户端连接中间件服务器:mysql -h10.10.10.150 -P4006 -uyaya8 -p123456
联系客服