littlecold
V2EX  ›  问与答

shardingsphere 读写分离之主从配置

  •  
  •   littlecold · Sep 23, 2022 · 1450 views
    This topic created in 1372 days ago, the information mentioned may be changed or developed.

    版本是 5.1.1 ,主从数据库,分表不分库,表 sharding 没啥问题,主从的读写分离就一直不行,请求各位大佬支援。

    spring:
      shardingsphere:
        datasource:
          names: ds0,ds1
          # 主库 1,master 数据库
          ds0:
           xxxxxx
          # 从库 1,slave 数据库
          ds1:
            xxxxx
        props:
          sql-show: true
          sql-simple: false
          # 是否在启动时检查分表元数据一致性
          check-table-metadata-enabled: true
          check-duplicate-table-enabled: false
          sql-comment-parse-enabled: false
          sql-federation-enabled: false
        rules:
          # 分片
          sharding:
            tables:
              xxxxxx:
                actual-data-nodes: ds$->{0..1}.xxxxx$->{0..7}
                table-strategy:
                  standard:
                    sharding-column: uid
                    sharding-algorithm-name: xxxxAl
            default-sharding-column: uid
            binding-tables:
              - xxxxxx
            broadcast-tables:
            default-database-strategy:
              none:
            default-table-strategy:
              none:
    
    
            sharding-algorithms:
              xxxxAl:
                type: INLINE
                props:
                  algorithm-expression: xxxxxx_xxxx
          ### 读写分离
          readwrite-splitting:
            data-sources:
              readwrite_ds:
                type: Static
                load-balancer-name: round_robin
                props:
                  write-data-source-name: ds0
                  read-data-source-names: ds1
            load-balancers:
              round_robin:
                type: ROUND_ROBIN
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   878 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 20:56 · PVG 04:56 · LAX 13:56 · JFK 16:56
    ♥ Do have faith in what you're doing.