当前位置:网站首页>Mycat2 deploy master-slave MariaDB
Mycat2 deploy master-slave MariaDB
2022-07-26 08:27:00 【csg103】
mycat Yes Mariadb Support is not perfect , It seems that the current test will not fail over . One master and one slave can be used . But it does not support comment line commands in a friendly way , You need to create your own configuration .
install mycat2
Download address
Two files need to be downloaded
mycat2-install-template-1.21.zip
mycat2-1.22-release-jar-with-dependencies.jar install hold JAR Move to... With compressed files lib Next And give execute file permission
chmod -R 777 mycat wrapper-linux-x86-32 wrapper-linux-x86-64 wrapper-linux-ppc-64 Modify the data source vim /usr/local/mycat/conf/database/prototypeDs.datasource.json
{
"dbType":"mysql",
"idleTimeout":60000,
"initSqls":[],
"initSqlsGetConnection":true,
"instanceType":"READ_WRITE",
"maxCon":1000,
"maxConnectTimeout":3000,
"maxRetryCount":5,
"minCon":1,
"name":"prototypeDs",
"password":"123456",
"type":"JDBC",
"url":"jdbc:mysql://192.168.10.30:3306/mycatdb?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8",
"user":"root",
"weight":0
}start-up

console The front-end start start Background start

Maintenance port 9006 Intranet access 
The use of port 8006
One master and one slave deployment
1. Logical library file
link mycat8066 port , Create a logical library mydb1, Then the corresponding configuration file will be generated mydb1.schema.json, And create a table test Field id name Used for testing .
vi /usr/local/mycat/conf/schemas/mydb1.schema.json
{
"customTables":{},
"globalTables":{},
"normalProcedures":{},
"normalTables":{
"test":{
"createTableSQL":"CREATE TABLE `mydb1`.`test` (\n\t`id` INT NOT NULL,\n\t`name` VARCHAR(45) NULL,\n\tPRIMARY KEY (`id`)\n)",
"locality":{
"schemaName":"mydb1",
"tableName":"test",
"targetName":"mycluse"
}
}
},
"schemaName":"mydb1",
"shardingTables":{},
"targetName":"mycluse", // Here is the cluster name , In the cluster configuration file
"views":{}
}
~2. Cluster files
Unable to execute due to annotation execution ,( May be Yes Mariadb Not compatible ?). So edit the configuration file directly .
vi /usr/local/mycat/conf/clusters/mycluse.cluster.json
{
"clusterType":"MASTER_SLAVE", // Choose master-slave mode here
"heartbeat":{
"heartbeatTimeout":1000,
"maxRetry":3,
"minSwitchTimeInterval":300,
"slaveThreshold":0
},
"masters":[
"rwSepr" Add main services , Fill in the database name
],
"replicas":["rwSepw"], Add a copy of the , Fill in the database name
"maxCon":2000,
"name":"mycluse", The name is consistent with the name filled in the logic library
"readBalanceType":"BALANCE_ALL", Random all readable
"switchType":"SWITCH"
}3. Database instance file
The database cluster has been set up , Refer to the previous article .
vi /usr/local/mycat/conf/datasources/rwSepr.datasource.json
{
"dbType":"mysql",
"idleTimeout":60000,
"initSqls":[],
"initSqlsGetConnection":true,
"instanceType":"READ_WRITE", read Write Reading and writing
"maxCon":1000,
"maxConnectTimeout":3000,
"maxRetryCount":5,
"minCon":1,
"name":"rwSepr", name , Use in the above cluster
"password":"123456",
"type":"JDBC",
"url":"jdbc:mysql://192.168.10.30:3306/mydb1?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8",
"user":"root",
"weight":0
}vi /usr/local/mycat/conf/datasources/rwSepw.datasource.json
Same as above , Only the database is different
{
"dbType":"mysql",
"idleTimeout":60000,
"initSqls":[],
"initSqlsGetConnection":true,
"instanceType":"READ_WRITE",
"maxCon":1000,
"maxConnectTimeout":3000,
"maxRetryCount":5,
"minCon":1,
"name":"rwSepw",
"password":"123456",
"type":"JDBC",
"url":"jdbc:mysql://192.168.10.204:3306/mydb1?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8",
"user":"root",
"weight":0
}Master slave test
restart Mycat
./bin/mycat console

, respectively, Set the two machines where the database is located Hostname
hostnamectl set-hostname mariadb01

hostnamectl set-hostname mariadb02

adopt Mycat Add data

View results

master The server is rwSepr The server of the corresponding database hostname yes mariadb01
Modify the configuration file
mycluse.cluster.json take rwSepr rwSepw Data source exchange , That is, swap the databases of write operations . Re execution Insert hostname


Because my database is multi master , So you can switch at will , It is only used for testing one master and one slave .
边栏推荐
- Burp Suite - Chapter 2 burp suite proxy and browser settings
- 2022 7/5 exam summary
- Kotlin中room数据库的使用
- Shell programming
- Burp suite Chapter 4 advanced options for SSL and proxy
- 2022-7-5 personal qualifying 2 competition experience
- 第三天作业
- Lesson 3: gcc compiler
- Understand microservices bit by bit
- 【C语言】程序员筑基功法——《函数栈帧的创建与销毁》
猜你喜欢

【时间复杂度空间复杂度】

Dev gridcontrol 捕获按键事件

我,35岁了。

Take out brother is the biggest support in this society

Flitter imitates wechat long press pop-up copy recall paste collection and other custom customization

Dev gridcontrol captures key events

Vscode utility shortcut
![[time complexity, space complexity]](/img/f2/f82c7e0a6ab9f893023c2ddbac3431.png)
[time complexity, space complexity]

Date and time function of MySQL function summary

【C语言】程序员筑基功法——《函数栈帧的创建与销毁》
随机推荐
Summary of common skills
VIM cross line matching search
Status management bloc provider geTx
Team members participate in 2022 China multimedia conference
OSPF总结
ORACLE 官方文档
【EndNote】文献模板编排语法详解
Apple's tough new rule: third-party payment also requires a percentage, and developers lose a lot!
Beauty naked chat for a while, naked chat over the crematorium!
Data validation typeerror: qiao Validate is not a function
Template summary
Burp suite Chapter 3 how to use burp suite agent
The first ide overlord in the universe, replaced...
JS工具函数大全
2022-7-5 personal qualifying 2 competition experience
分享高压超低噪声LDO测试结果(High Voltage Ultra-low Noise LDO)
Super nice navigation page (static page)
【EndNote】文献类型与文献类型缩写汇编
Function default parameters, arrow functions, and remaining parameters in ES6 - explanation
SPSS uses kmeans, two-stage clustering and RFM model to study the behavior law data of borrowers and lenders in P2P network finance