mycat 集群双主双从
作者:互联网
数据库主从备从搭建参考:《mysql主备从》
mycat安装参考:《安装mycat2》
ip端口 | ||
8066 | mycat | |
3307 | master | 主 |
3308 | slave | 从 |
3309 | master01 | 备 |
3310 | slave01 | 从 |
进入master、slave、slave01创建用户,作为数据源连接使用
CREATE USER 'mycat'@'%' IDENTIFIED BY '123123'; GRANT ALL PRIVILEGES ON *.* to 'mycat'@'%'; FLUSH PRIVILEGES;
参考《通过注释配置》
Navicat连接mycat,在Navicat窗口执行如下
# 创建数据源 /*+ mycat:createDataSource{ "dbType":"mysql", "idleTimeout":60000, "initSqls":[], "initSqlsGetConnection":true, "instanceType":"READ_WRITE", "maxCon":1000, "maxConnectTimeout":3000, "maxRetryCount":5, "minCon":1, "name":"master", "password":"123123", "type":"JDBC", "url":"jdbc:mysql://192.168.153.19:3307/mydb1?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8", "user":"mycat", "weight":0 } */; /*+ mycat:createDataSource{ "dbType":"mysql", "idleTimeout":60000, "initSqls":[], "initSqlsGetConnection":true, "instanceType":"READ", "maxCon":1000, "maxConnectTimeout":3000, "maxRetryCount":5, "minCon":1, "name":"slave", "password":"123123", "type":"JDBC", "url":"jdbc:mysql://192.168.153.19:3308/mydb1?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8", "user":"mycat", "weight":0 } */; /*+ mycat:createDataSource{ "dbType":"mysql", "idleTimeout":60000, "initSqls":[], "initSqlsGetConnection":true, "instanceType":"READ_WRITE", "maxCon":1000, "maxConnectTimeout":3000, "maxRetryCount":5, "minCon":1, "name":"master01", "password":"123123", "type":"JDBC", "url":"jdbc:mysql://192.168.153.19:3309/mydb1?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8", "user":"mycat", "weight":0 } */; /*+ mycat:createDataSource{ "dbType":"mysql", "idleTimeout":60000, "initSqls":[], "initSqlsGetConnection":true, "instanceType":"READ", "maxCon":1000, "maxConnectTimeout":3000, "maxRetryCount":5, "minCon":1, "name":"slave01", "password":"123123", "type":"JDBC", "url":"jdbc:mysql://192.168.153.19:3310/mydb1?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8", "user":"mycat", "weight":0 } */;
查看/usr/local/mycat/conf/datasources文件夹下,就会生成相应的数据源配置文件
创建集群配置
/*! mycat:createCluster{ "clusterType":"MASTER_SLAVE", "heartbeat":{ "heartbeatTimeout":1000, "maxRetry":3, "minSwitchTimeInterval":300, "slaveThreshold":0 }, "masters":[ "master","master01" // master节点 ], "maxCon":200, "name":"master-slave", "readBalanceType":"BALANCE_ALL", "replicas":[ "slave","slave","master01" //从库 master01即作为备机也作为从机 ], "switchType":"SWITCH" } */;
创建Schema
/*+ mycat:createSchema{ "customTables":{}, "globalTables":{}, "normalTables":{}, "schemaName":"mydb1", // 物理库 "shardingTables":{}, "targetName":"master-slave" // 配置的集群名称 取/usr/local/mycat/conf/clusters/master-slave.cluster.json 配置中的name } */;
注:可以直接修改原先的mysql.schema.json配置,否则废弃掉mv mysql.schema.json mysql.schema.bak
启动mycat建议用console方便调试
/usr/local/mycat/bin/mycat console
标签:slave,name,mycat,双主双,集群,mysql,master,true 来源: https://www.cnblogs.com/chenjiangbin/p/16459891.html