maxscale+MHA 实现读写分

环境:centos7 mysql5.7

推荐:主从复制,MHA 高可用搭建:https://blog.csdn.net/hailanzi/article/details/82183987

master: 192.168.0.180
slave1:192.168.0.160
slave2:192.168.0.154

master 为主,slave1(备主)和slave2 为从 ,本地资源有限我把maxscale 安装在 slave2 上

一、maxscale安装

安装依赖关系

yum install libaio.x86_64 libaio-devel.x86_64 novacom-server.x86_64 libedit -y

MaxScale 的下载地址:

官网下载:https://downloads.mariadb.com/files/MaxScale

下载 maxscale rpm 包

wget https://downloads.mariadb.com/MaxScale/2.1.0/centos/7server/x86_64/maxscale-2.1.0-1.centos.7.x86_64.rpm

安装maxscale rpm 包

 rpm -ivh maxscale-2.1.0-1.centos.7.x86_64.rpm 

在master 上创建监控用户

mysql> grant replication slave,replication client on *.* to scalemon@'%' identified by '123456';

在master 上创建路由用户

mysql> grant select  on mysql.* to maxscale@'%' identified by '123456';   

mysql> flush privileges;

在slave2 上配置Maxscale服务,配置文件如下:

vi /etc/maxscale.cnf
[server1]
type=server
address=192.168.0.154
port=3306
protocol=MySQLBackend

[server2]
type=server
address=192.168.0.160
port=3306
protocol=MySQLBackend

[server3]
type=server
address=192.168.0.180
port=3306
protocol=MySQLBackend

#[Read-Only Service] //注释掉或者删掉这个模块
#type=service
#router=readconnroute
#servers=server1
#user=myuser
#passwd=mypwd
#router_options=slave

[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1,server2,server3
user=scalemon // 监控用户
passwd=123456 // 监控用户密码
monitor_interval=10000

#[Read-Only Listener] //注释掉或者删掉这个模块
#type=listener
#service=Read-Only Service
#protocol=MySQLClient
#port=4008

[Read-Write Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=maxscale // 路由用户
passwd=123456 // 路由用户密码
max_slave_connections=100%

启动服务

[root@localhost ~]# maxscale --config=/etc/maxscale.cnf
* Error: Failed to open PID file '/var/run/maxscale/maxscale.pid'. (No such file or directory)

报错一个找不到进程的错

//找不到进程 卸载重新安装
[root@localhost src]# rpm -e maxscale-2.1.0-1.x86_64
//重新安装
[root@localhost src]# rpm -ivh maxscale-2.1.0-1.centos.7.x86_64.rpm 

 

测试参考连接 https://www.cnblogs.com/darren-lee/p/7591416.html

你可能感兴趣的:(mysql,组件安装,MySQL,Linux)