sharding-proxy搭建步骤,实现读写分离

tar -xf apache-shardingsphere-4.1.1-sharding-proxy-bin.tar.gz
mv apache-shardingsphere-4.1.1-sharding-proxy-bin sharding4
cd sharding4/conf
vim server.yaml
==============添加如下配置(注意这个password:root1是sharding登入密码,而不是mysql登入密码)==============
authentication:
  users:
    root:
      password: root1
    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.
  proxy.transaction.type: LOCAL
  proxy.opentracing.enabled: false
  proxy.hint.enabled: false
  query.with.cipher.column: false
  sql.show: false
  allow.range.query.with.inline.sharding: true
=========================================

vim config-sharding.yaml
========================新增如下配置(注意这里的password:root123 为数据库密码,)======================
schemaName: sharding_db
dataSources:
  ds_0:
    url: jdbc:mysql://192.23.74.194:3306/sharding_test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
    username: root
    password: root123
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50

shardingRule:
  tables:
    t_order:
      actualDataNodes: ds_${0}.t_order_${0..1}
      tableStrategy:
        inline:
          shardingColumn: order_id
          algorithmExpression: t_order_${order_id % 2}
      keyGenerator:
        type: SNOWFLAKE
        column: order_id
  bindingTables:
    - t_order
  defaultDatabaseStrategy:
    inline:
      shardingColumn: user_id
      algorithmExpression: ds_${0}
  defaultTableStrategy:
    none:

注意:1.同时把mysql驱动拷贝到lib目录下,注意mysql驱动的版本号和url连接  2.要手动创建url后面的数据库

启动服务:
cd sharding4/bin
./start.sh 3307

查看日志:
tail -200f sharding4/logs/stdout.log

最后看到这行:[INFO ] 11:28:58.090 [epollEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0x2c7904a1, L:/0.0.0.0:3307] ACTIVE
代表启动成功,用Navicat11连接mysql5.7, 不要用Navicat15去连接,否则连接不上
ip:为192.23.74.194  用户名和密码为server.yaml的配置,最后可以连接成功
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值