sharding在application中的配置

2021-10-10 02:38:37 字數 3721 閱讀 3965

server.port=8080

# 駝峰轉換

mybatis.configuration.map-underscore-to-camel-case=true

# 開啟sharding日誌

spring.shardingsphere.props.sql.show=true

# 允許bean覆蓋,防止bean和springboot注入衝突

spring.main.allow-bean-definition-overriding=true

# 各日誌級別設定

logging.level.root=info

logging.level.org.springframework.web=info

logging.level.com.example.sharding=debug

logging.level.druid.sql=debug

單資料來源資料水平分表設定

# 配置多資料來源

spring.shardingsphere.datasource.names=m1

spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.druiddatasource

spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.jdbc.driver

spring.shardingsphere.datasource.m1.username=root

spring.shardingsphere.datasource.m1.password=12345

spring.shardingsphere.datasource.m1.url=jdbc:mysql://localhost:3306/temporary?characterencoding=utf-8&usessl=false

#表節點指定

spring.shardingsphere.sharding.tables.student.actual-data-nodes=m1.student$->

#對映到不同的資料庫

spring.shardingsphere.sharding.tables.student.actual-data-nodes=m1.student$->

#指定表主鍵生成策略及唯一性

spring.shardingsphere.sharding.tables.student.key-generator.column=id

spring.shardingsphere.sharding.tables.student.key-generator.type=snowflake

#指定邏輯插入方式分片策略

spring.shardingsphere.sharding.tables.student.table-strategy.inline.sharding-column=id

spring.shardingsphere.sharding.tables.student.table-strategy.inline.algorithm-expression=student$->

# 配置多資料來源

spring.shardingsphere.datasource.names=m1,m2

spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.druiddatasource

spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.jdbc.driver

spring.shardingsphere.datasource.m1.username=root

spring.shardingsphere.datasource.m1.password=12345

spring.shardingsphere.datasource.m1.url=jdbc:mysql://localhost:3306/temporary?characterencoding=utf-8&usessl=false

spring.shardingsphere.datasource.m2.type=com.alibaba.druid.pool.druiddatasource

spring.shardingsphere.datasource.m2.driver-class-name=com.mysql.jdbc.driver

spring.shardingsphere.datasource.m2.username=root

spring.shardingsphere.datasource.m2.password=12345

#可以設定不同的資料庫,可以是同一臺伺服器上的不同資料庫,也可以是不同伺服器上的不同資料庫,分別對應水平分庫和垂直分庫

spring.shardingsphere.datasource.m2.url=jdbc:mysql://localhost:3306/private?characterencoding=utf-8&usessl=false

#分庫策略配置

spring.shardingsphere.sharding.tables.student.database-strategy.inline.sharding-column=user_id

#根據表示式將$替換,最終表示對應資料來源的名稱

spring.shardingsphere.sharding.tables.student.database-strategy.inline.algorithm-expression=m$->

#對映到不同的資料庫

spring.shardingsphere.sharding.tables.student.actual-data-nodes=m$->.student$->

#指定表主鍵生成策略及唯一性

spring.shardingsphere.sharding.tables.student.key-generator.column=id

spring.shardingsphere.sharding.tables.student.key-generator.type=snowflake

#指定邏輯插入方式分片策略

spring.shardingsphere.sharding.tables.student.table-strategy.inline.sharding-column=id

spring.shardingsphere.sharding.tables.student.table-strategy.inline.algorithm-expression=student$->

因為垂直分表是將乙個表中按照字段使用頻率拆分成兩個或多個,表名之間沒有相關性了,實際操作中是操作不同的資料表,sql不相互干涉

垂直分庫是按照業務邏輯,將原來乙個資料庫中的多個資料表拆分到不同的資料庫中,所以實際操作就是單資料庫單資料表的操作,所以只需要配置對映的資料庫和表的資料節點

spring.shardingsphere.sharding.tables.student.actual-data-nodes=m$->.student$->
繫結表必須從tables[0]開始,使用的是陣列方式

# 繫結表

spring.shardingsphere.sharding.binding-tables[0]=product_info,product_descript

SolrCloud之Sharding路由介紹

img size medium 在solr4.4之後,solr提供了solrcloud分布式集群的模式,它帶來的主要好處是 1 大資料量下更高的效能 2 更好擴充套件性 3 更高的可靠性 4 更簡單易用 什麼時候應該使用solrcloud shard 呢?1 更大的資料量 2 更大的索引體積 3 想...

MongoDB 分片sharding概述

當mongodb由於儲存的資料越來越多,由於效能原因,或者單個主機資源限制,垂直擴容沒有辦法進一步的時候,我們就需要開始考慮水平擴容了。與垂直擴容不同的是,水平擴容不需要新新增的機器有多麼強大的功能,它的設計理念是將業務資料盡可能平均的劃分成一段一段的,每一段分布在一台機器上,這樣,當系統需要進一步...

Mongodb分片 Sharding 功能實現

在mongodb裡面存在另一種集群,就是分片技術,可以滿足mongodb資料量大量增長的需求。當mongodb儲存海量的資料時,一台機器可能不足以儲存資料,也可能不足以提供可接受的讀寫吞吐量。這時,我們就可以通過在多台機器上分割資料,使得資料庫系統能儲存和處理更多的資料。下圖展示了在mongodb中...