当前位置:网站首页>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_ 11 smart communication health project - graphic report and poi Report
- Day_ 01 smart communication health project - project overview and environmental construction
- idea的去除转义的复制粘贴
- Golang regular regexp package use -04- use regular replacement (replaceall(), replaceallliteral(), replaceallfunc())
- Qt使用多线程编译项目的方法
- C language stepping on the pit: document coding error, resulting in Base64 Chinese coding error
- 图解 Google V8 # 17:消息队列:V8是怎么实现回调函数的?
- Illuminate\Support\Collection 去重 unique 列表去重
- Qt 中 QVariant 使用总结
- Skilled use of slicing operations
猜你喜欢
随机推荐
将TensorFlow1.x改写为pytorch
Open source to the world (Part 2): the power of open source from the evolution of database technology BDTC 2021
Link of Baidu URL parameter? Research on URL parameter encryption and decryption (code example)
Illuminate\support\collection de duplication unique list de duplication
索引——MySQL
原址 交换
图解 Google V8 # 18 :异步编程(一):V8是如何实现微任务的?
Detailed explanation of redis persistence, master-slave and sentry architecture
常见设置模式(抽象工厂&责任链模式&观察者模式)
如何查看本机IP
Possible pits in mongodb project
射频内容学习
Machine learning artifact scikit learn minimalist tutorial
设计师需要懂的数据指标与数据分析模型
LeetCode笔记:Weekly Contest 298
C Advanced Learning -- Reflection
Day_ 02 smart communication health project - appointment management - inspection item management
Kubesphere offline deployment without network environment
图解 Google V8 # 17:消息队列:V8是怎么实现回调函数的?
了解学习 JSX 的工作方式









