ShardingSphere-Proxy 主从读写 入门使用
基于ShardingSphere5.0.0Alpha
环境准备
MySQL搭建
准备MySQL
- 准备三个mysql,一主二从,搭建教程链接:Mysql docker 主从配置
- 3306:主库
- 3309、3310:从库
配置ShardingSphere-Proxy
这里使用5.0.0版本的
-
2.下载完成后解压放到自己的目录下,比如我这里是放到:D:/temp/ssp
-
4.将MySQL-connect.jar,放到ShardingSphere-Proxy根目录的lib下,比如我这里是:D:/temp/ssp/lib/
-
5.写入配置文件,里面本身就有配置文件,这里需要写入的有两份,如果之前存在的就直接替换:server.xml和config-master_slave.yaml
server.xml 这份感觉不用改,如果和下面的一样就不用改
######################################################################################################
#
# If you want to configure orchestration, authorization and proxy properties, please refer to this file.
#
######################################################################################################
# orchestration:
# name: orchestration_ds
# overwrite: true
# registry:
# type: zookeeper
# serverLists: localhost:2181
# namespace: orchestration
authentication:
users:
root:
password: root
sharding:
password: sharding
authorizedSchemas: test
props:
max.connections.size.per.query: 1
acceptor.size: 16 # The default value is available processors count * 2.
executor.size: 16 # Infinite by default.
proxy.frontend.flush.threshold: 128 # The default value is 128.
# LOCAL: Proxy will run with LOCAL transaction.
# XA: Proxy will run with XA transaction.
# BASE: Proxy will run with B.A.S.E transaction.
proxy.transaction.type: LOCAL
proxy.opentracing.enabled: false
query.with.cipher.column: true
sql.show: false
config-master_slave.yaml,这个文件的配置关键字一定不要安装官方example的那个来,完全不行,要按照官方文档来,比如JDBCURL需要改成url,大致的文件内容如下:
######################################################################################################
#
# Here you can configure the rules for the proxy.
# This example is configuration of master-slave rule.
#
# If you want to use master-slave, please refer to this file;
# if you want to use sharding, please refer to the config-sharding.yaml.
#
######################################################################################################
schemaName: test
dataSources:
master_ds:
url: jdbc:mysql:/