sharding-proxy部署
钢翼
编程
1.下载sharding-proxy 4.1.0版本
https://www.apache.org/dyn/closer.cgi?path=shardingsphere/4.1.0/apache-shardingsphere-4.1.0-sharding-proxy-bin.tar.gz
2.解压
记得看下解压后lib文件夹下的jar包名称是否正常,不正常请使用7zip解压。
3.下载 mysql-connector-java-5.1.47
https://cdn.mysql.com/archives/mysql-connector-java-5.1/mysql-connector-java-5.1.47.tar.gz
将mysql-connector-java-5.1.47.jar 拷贝到lib文件夹下,为的是能支持mysql数据库
4.修改配置
/conf/server.yaml
用户名密码自己定
authentication:
users:
root:
password: 123456
sharding:
password: sharding
authorizedSchemas: sharding_db
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
proxy.hint.enabled: false
query.with.cipher.column: true
sql.show: false
allow.range.query.with.inline.sharding: false
/conf/config-sharding.yaml
自己定分表规则,试过只用一个数据源会报错,所以加多了一个没用的。
$->{} 或 ${} 里用的是groovy 表达式
schemaName: sharding_db
dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/db?serverTimezone=UTC&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
ds_1:
url: jdbc:mysql://127.0.0.1:3306/db?serverTimezone=UTC&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
shardingRule:
tables:
tb1:
actualDataNodes: ds_0.tb1_$->{['101','103','005','006','007','999']}
tableStrategy:
inline:
shardingColumn: code
algorithmExpression: tb1_$->{code ? (code.length()>3?code.substring(0,3):code):'999'}
keyGenerator:
type: SNOWFLAKE
column: id
tb2:
actualDataNodes: ds_0.tb2
bindingTables:
- tb1
- tb2
defaultDatabaseStrategy:
none:
defaultTableStrategy:
none: