当前位置:网站首页>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
边栏推荐
- How to maintain secure encryption of email communication with FDA?
- 【踩坑记录】数据库连接未关闭连接,释放资源的坑
- C language removes line breaks (or other characters) at the end of strings
- Softing dataFEED OPC Suite将西门子PLC数据存储到Oracle数据库中
- English语法_副词 - ever / once
- Kubesphere offline deployment without network environment
- CPU的功能和基本结构
- 30 data visualization tips that can not be ignored
- [resolved] "the unity environment took too long to respond. make sure that: \n“
- haas506 2.0开发教程-高级组件库-modem.voiceCall(仅支持2.2以上版本)
猜你喜欢

Day_05 传智健康项目-预约管理-预约设置

Day_ 13 smart health project - Chapter 13

设计师需要懂的数据指标与数据分析模型

业务逻辑安全思路总结

Measurement principle and thickness measurement mode of spectral confocal

把CSMA/CD、Token Bus、Token Ring说清楚

Haas506 2.0 development tutorial -hota (only supports versions above 2.2)

qt creater搭建osgearth环境(osgQT MSVC2017)

了解学习 JSX 的工作方式

Index - MySQL
随机推荐
Qt使用多线程编译项目的方法
[resolved] "the unity environment took too long to respond. make sure that: \n“
Machine learning artifact scikit learn minimalist tutorial
业务逻辑安全思路总结
Termux
设计师需要懂的数据指标与数据分析模型
C Advanced Learning -- Reflection
haas506 2.0开发教程-高级组件库-modem.sim(仅支持2.2以上版本)
The softing datafeed OPC suite stores Siemens PLC data in an Oracle Database
haas506 2.0开发教程-sntp(仅支持2.2以上版本)
Functions and basic structure of CPU
Day_ 05 smart communication health project - appointment management - appointment settings
Remove the influence of firewall and virtual machine on live555 startup IP address
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)
A review: neural oscillation and brain stimulation in Alzheimer's disease
Word pattern for leetcode topic analysis
直播带货这么火,如何在小程序中实现视频通话及直播互动功能?
Day_06 传智健康项目-移动端开发-体检预约
279.完全平方数
sklearn sklearn中classification_report&精确度/召回率/F1值