在windows安裝部署ShardingSphere-Proxy 分庫分表中間件



當前端口:

-- mysql端口:3316;數據庫:myshop1;表:t_product_1、t_product_2
-- mysql端口:3326;數據庫:myshop2;表:t_product_1、t_product_2

分庫分表策略:按照 id%2 分庫,按照 create_time%2 分表。

 

 

1、下載ShardingSphere-Proxy
ShardingSphere-Proxy 二進制包: [ TAR ]

下載地址:https://shardingsphere.apache.org/document/current/cn/downloads/

當前版本是:apache-shardingsphere-5.0.0-alpha-shardingsphere-proxy

 

 

2、修改bin目錄的配置config-sharding.yaml內容


schemaName: sharding_db

dataSourceCommon:
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
maintenanceIntervalMilliseconds: 30000

dataSources:
ds_0:
url: jdbc:mysql://localhost:3316/myshop1?useUnicode=true&characterEncoding=utf-8
ds_1:
url: jdbc:mysql://localhost:3326/myshop2?useUnicode=true&characterEncoding=utf-8

rules:
- !SHARDING
tables:
t_product:
actualDataNodes: ds_${0..1}.t_product_${0..1}
tableStrategy:
standard:
shardingColumn: create_time
shardingAlgorithmName: t_product_inline
keyGenerateStrategy:
column: id
keyGeneratorName: snowflake
bindingTables:
- t_product
defaultDatabaseStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: database_inline
defaultTableStrategy:
none:

shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expression: ds_${id % 2}
t_product_inline:
type: INLINE
props:
algorithm-expression: t_product_${create_time % 2}

keyGenerators:
snowflake:
type: SNOWFLAKE
props:
worker-id: 123

 

3、修改bin目錄的配置server.yaml內容

 

governance:
name: governance_ds
registryCenter:
type: ZooKeeper
serverLists: localhost:2181
props:
retryIntervalMilliseconds: 500
timeToLiveSeconds: 60
maxRetries: 3
operationTimeoutMilliseconds: 500
overwrite: false

authentication:
users:
root:
password: root
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
check-table-metadata-enabled: false

 

4、添加驅動包

mysql-connector-java-8.0.23.jar

要與你的mysql版本一致,不然會報錯的:com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.

 

5、啟動zookeeper

配置文件的內容會存到zk中。

啟動shardingsphere-proxy之后,會把配置信息存到zk的。如果修改了配置,再次啟動shardingsphere-proxy,發現zk的沒有同步修改,需要手動刪掉zk的數據,shardingsphere-proxy啟動后會再生成的。

 

6、啟動shardingsphere-proxy

點擊bin/start.bat

如果最后命令行顯示: [main] o.a.s.p.frontend.ShardingSphereProxy - ShardingSphere-Proxy start success.,就表示成功了。

ShardingSphereProxy會在3307端口啟用一個mysql連接。

連接mysql,端口3307,用戶名密碼:root,root。

然后就可以查詢和操作了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM