当前位置:网站首页>Mysql5.6 (5.7-8) is based on shardingsphere5.1.1 sharding proxy mode. Read / write separation
Mysql5.6 (5.7-8) is based on shardingsphere5.1.1 sharding proxy mode. Read / write separation
2022-06-23 06:38:00 【Mumunu-】
This article is based on mysql5.6 , In practice mysql5.7 ,8 Consistent configuration , Can be used in general
First build mysql Master-slave , Master slave mysql Manage yourself , Let's not go over this ..
1. preparation
download ShardingSphere-Proxy
Official website address
http://shardingsphere.apache.org/index_zh.html
Download jump
https://shardingsphere.apache.org/document/current/cn/downloads/
download MySQL Driving dependency
5 edition :
https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar
8 edition :
https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.11/mysql-connector-java-8.0.11.jar
Other versions :
https://repo1.maven.org/maven2/mysql/mysql-connector-java/
install java
Just install it in the way you like java8
Will download okay MySQL Move the driver to the extracted middleware file lib Next
Get into conf Catalog
Here you need to configure two files :server.yaml,config-readwrite-splitting.yaml
Regardless of use Sharding-Proxy Everything needs to be configured server.yaml file , He is a starter Sharding-Proxy Service for .
To configure server.yaml
At first the file was full of comments , We only need two nodes to configure read-write separation
rules:
- !AUTHORITY
users:
- [email protected]%:123456 # User password to start the service
- [email protected]:123456 # User password to start the service It means to log in with this password shardingshare Generated simulation mysql
provider:
type: NATIVE
props:
max-connections-size-per-query: 1 # The maximum number of connections that a query request can use in each database instance .
kernel-executor-size: 16 # Thread pool size The default value is : CPU Check the number
kernel-acceptor-size: 16 # Used to set the number of worker threads that receive client requests , The default is CPU Check the number *2
proxy-frontend-flush-threshold: 128 # Set the number of transmitted data IO Refresh threshold
proxy-opentracing-enabled: false # Whether the link tracking function is enabled , The default is not on
proxy-hint-enabled: false # Is it enabled? hint Algorithm forced routing Default false
sql-show: ture # Whether or not to print sql Default falsefalse
# show-process-list-enabled: false
# Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy.
# The default value is -1, which means set the minimum value for different JDBC drivers.
proxy-backend-query-fetch-size: -1
check-duplicate-table-enabled: false
sql-comment-parse-enabled: false
proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide.
# Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution
# if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL.
proxy-backend-executor-suitable: OLAP
# proxy-frontend-max-connections: 0 # Less than or equal to 0 means no limitation.
# sql-federation-enabled: false
- To configure config-readwrite-splitting.yaml
schemaName: test # Give your connection a name
# Logical library , It is equivalent to an intermediate library between independent master and slave , After setting up the service, you should use the logical library
# Note that a logical library has been configured and started , When modifying this logical library, you must first pause the service and then start it .
dataSources:
write_ds:
url: jdbc:mysql://192.168.1.1:3306/test?allowPublicKeyRetrieval=true&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000 # Connection timeout
idleTimeoutMilliseconds: 60000 # Idle connection recycle timeout milliseconds
maxLifetimeMilliseconds: 1800000 # Maximum connection lifetime in milliseconds
maxPoolSize: 50 # maximum connection
minPoolSize: 1 # Minimum connections
read_ds_0:
url: jdbc:mysql://192.168.1.2:3306/test?allowPublicKeyRetrieval=true&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
rules:
- !READWRITE_SPLITTING
dataSources:
readwrite_ds:
type: Static
props:
write-data-source-name: write_ds
read-data-source-names: read_ds_0
- Start the service
bin/start.shThe default port is 3307
Stop as :./stop.sh
netstat -nltp You can check whether the port is up
Why don't you get up and read the log
verification
To verify read-write separation, you need to close the master-slave replication now , First go to the slave machine to sql Thread shutdown , Then restart the services of the two machines .
Here we will not only talk about the steps :
First, create the same database and table in the master and slave respectively , And insert different data into the two tables of the master and the slave .
Connect Sharding-Proxy service
mysql -h Service ip -P Port of service -p
1
Use show databases; When you view the library with the command, you will find that the name of the library is the same as that of the logical library we configured to separate reading and writing , Then we cut into the library and use show tables; When viewing a table, it will automatically have a table that is the same as the master and slave
Query the data of this table , It will be the same as the data from the table , When inserting data into the table , In the query , It is found that the data just inserted is not displayed
Connect The host MySQL Service query Table for host , It is found that the data just inserted is displayed , Then prove MySQL8 be based on Sharding-Proxy5 The setup of read / write separation is successful !
Some problems encountered in deployment
The connection fails
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection refused: connect
STACKTRACE:
java.net.ConnectException: Connection refused: connect
You need to check the corresponding MySQL Whether the service is up , Whether the corresponding port is exposed
Public Key Retrieval is not allowed
stay config-readwrite-splitting.yaml In file , Configure each of the master and slave url Followed by allowPublicKeyRetrieval=true
边栏推荐
- Day_05 传智健康项目-预约管理-预约设置
- 如何实现与FDA保持邮件通信安全加密?
- Leetcode topic resolution remove nth node from end of list
- 百度URL參數之LINK?URL參數加密解密研究(代碼實例)
- Day_07 传智健康项目-Freemarker
- LeetCode笔记:Weekly Contest 298
- Synchronous switching power supply reduces EMI layout dv/dt di/dt
- Docker实战 -- 部署Redis集群与部署微服务项目
- Link of Baidu URL parameter? Research on URL parameter encryption and decryption (code example)
- SAP execution transaction code mrrl error -no message was found for partner 100065-
猜你喜欢

Detailed explanation of redis persistence, master-slave and sentry architecture

Softing dataFEED OPC Suite将西门子PLC数据存储到Oracle数据库中

C # database reports errors. Let's have a look

Day_ 13 smart health project - Chapter 13

Measurement principle and thickness measurement mode of spectral confocal

索引——MySQL

Docker practice - redis cluster deployment and micro service deployment project

Day_ 03 smart communication health project - appointment management - inspection team management

Haas 506 2.0 Tutoriel de développement - bibliothèque de composants avancés - modem. SMS (ne prend en charge que les versions supérieures à 2,2)

Day_04 傳智健康項目-預約管理-套餐管理
随机推荐
Linked Storage
Leetcode topic resolution valid Sudoku
Index - MySQL
SAP execution transaction code mrrl error -no message was found for partner 100065-
CVE-2021-20038
Leetcode topic resolution remove nth node from end of list
Sklearn classification in sklearn_ Report & accuracy / recall /f1 value
English语法_副词 - ever / once
Haas 506 2.0 Tutoriel de développement - bibliothèque de composants avancés - modem. SMS (ne prend en charge que les versions supérieures à 2,2)
设计师需要懂的数据指标与数据分析模型
业务逻辑安全思路总结
How to batch produce QR codes that can be read online after scanning
The central network and Information Technology Commission issued the National Informatization Plan for the 14th five year plan, and the network security market entered a period of rapid growth
直播带货这么火,如何在小程序中实现视频通话及直播互动功能?
Global attribute lang attribute
Dora's Google SEO tutorial (1) SEO novice guide: establishment of preliminary optimization thinking
RF content learning
CPU的功能和基本结构
Day_ 05 smart communication health project - appointment management - appointment settings
How to maintain secure encryption of email communication with FDA?