php與dw怎么做校園網(wǎng)站seo教程
問題場景:
??????? 最近在學習ShardingSphere,跟著教程一步步做shardingJDBC,但是想在開啟數(shù)據(jù)分片的時候還能使用讀寫分離,一直失敗,開始是一直能讀寫分離,但是分偏見規(guī)則感覺不生效,一直好像是走不進去[sharding]這個配置中,后來debug調(diào)試可以找到相關(guān)配置,又感覺是什么代碼給覆蓋了或者不生效了。
問題解決:
??????? 后來找資料一直沒有,看到教程下有人一直在問讀寫分離和數(shù)據(jù)分片沒法一起使用嗎?我就試了下關(guān)閉讀寫分離,真的就可以數(shù)據(jù)分片了,后來查資料:
單獨的讀寫分離配置之后,數(shù)據(jù)分片就無法生效了,是兩塊分開的單獨功能;如果既想使用讀寫分離又想數(shù)據(jù)分片,可以使用如下配置,主要看sharding->master-slave-rules設(shè)置。
spring:shardingsphere:props:sql:show: true # 參數(shù)配置,顯示sqldatasource: # 配置數(shù)據(jù)源# 給每個數(shù)據(jù)源取別名,下面的ds1,ds2,ds3任意取名字names: master,salve1# 給master-ds1每個數(shù)據(jù)源配置數(shù)據(jù)庫連接信息master:# 配置druid數(shù)據(jù)源type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3307/springboot?useUnicode=true&characterEncoding=utf8&tinyInt1isBit=false&useSSL=false&serverTimezone=GMTusername: rootpassword: rootmaxPoolSize: 100minPoolSize: 5# 配置ds2-slavesalve1:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3308/springboot?useUnicode=true&characterEncoding=utf8&tinyInt1isBit=false&useSSL=false&serverTimezone=GMTusername: rootpassword: rootmaxPoolSize: 100minPoolSize: 5# 配置默認數(shù)據(jù)源masterslave: # 配置數(shù)據(jù)源的讀寫分離,但是數(shù)據(jù)庫一定要做主從復(fù)制# 配置主從名稱,可以任意取名字name: ms# 配置主庫master,負責數(shù)據(jù)的寫入master-data-source-name: master# 配置從庫slave節(jié)點slave-data-source-names: salve1# 配置slave節(jié)點的負載均衡均衡策略,采用輪詢機制load-balance-algorithm-type: round_robinsharding:master-slave-rules: # 在使用數(shù)據(jù)分片功能情況下,配置讀寫分離功能ds0: # 自定義一個虛擬數(shù)據(jù)源名字,用于自動路由下方主從數(shù)據(jù)源masterDataSourceName: master # 指定主數(shù)據(jù)源slaveDataSourceNames: # 指定從數(shù)據(jù)源- salve1loadBalanceAlgorithmType: round_robinbinding-tables:- fa_user # 指明了分庫分表要處理的虛擬表名字tables:# user_table 邏輯表名fa_user:# 數(shù)據(jù)節(jié)點:數(shù)據(jù)源$->{0..N}.邏輯表名$->{0..N}actualDataNodes: ds0.fa_user_$->{2022..2023}# 拆分庫策略
# database-strategy:
# standard:
# sharding-column: create_time
# precise-algorithm-class-name: com.wpj.user.shardingSphere.UserDataBaseRule# 拆分表策略table-strategy:standard:sharding-column: create_timeprecise-algorithm-class-name: com.wpj.user.shardingSphere.UserTableRule