单机从源码编译部署使用ShardingProxy

以下步骤全部在一台电脑执行的,电脑上请先安装

  • docker环境
  • jdk8
  • idea

一、下载源码

https://github.com/apache/shardingsphere

二、使用IDEA 打开项目

三、生成依赖代码

Linux在项目根目录下执行
./mvnw -Dcheckstyle.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true -Djacoco.skip=true -DskipITs -DskipTests install -T1C

Windows在项目根目录下执行
mvnw.cmd -Dcheckstyle.skip=true -Drat.skip=true -Dmaven.javadoc.skip=true -Djacoco.skip=true -DskipITs -DskipTests install -T1C

四、搭建环境

1.搭建zookeeper
教程:https://www.cnblogs.com/caoweixiong/p/12325410.html
2.搭建主从同步Mysql集群
教程:https://blog.csdn.net/THMAIL/article/details/125297958

3. 获取驱动
https://dev.mysql.com/downloads/connector/j/下载MySQL Connector/J,放到Java\jdk1.8.0_191\lib路径下

五、配置Sharding PRoxy

1、在shardingsphere-5.1.1\shardingsphere-proxy\shardingsphere-proxy-bootstrap\src\main\resources\conf目录下配置server.yaml文件如下:

mode:
  type: Cluster
  repository:
    type: ZooKeeper
    props:
      namespace: governance_ds
      server-lists: 127.0.0.1:2181
      retryIntervalMilliseconds: 500
      timeToLiveSeconds: 60
      maxRetries: 3
      operationTimeoutMilliseconds: 500
  overwrite: false

rules:
  - !AUTHORITY
    users:
      - root@%:root
      - sharding@:sharding
    provider:
      type: ALL_PRIVILEGES_PERMITTED

2、编辑config-readwrite-splitting.yaml内容如下:


######################################################################################################
#
# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.
#
######################################################################################################

schemaName: readwrite_splitting_db

dataSources:
  write_ds:
  #url改成你自己的
    url: jdbc:mysql://10.7.107.210:3309/testdb?serverTimezone=UTC&useSSL=false
    username: root
    password: 12345678
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  read_ds_0:
    url: jdbc:mysql://10.7.107.210:3308/testdb?serverTimezone=UTC&useSSL=false
    username: root
    password: 12345678
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
rules:
  - !READWRITE_SPLITTING
    dataSources:
      readwrite_splitting_db:
        type: Dynamic
        props:
#          以下一项仅在type:Dynamic时有效
          auto-aware-data-source-name: readwrite_ds
#          以下两项在type:Static时有效
#          write-data-source-name: write_ds
#          read-data-source-names: read_ds_0

### 主从发现规则:指定datasource使用指定主从发现规则 ###
  - !DB_DISCOVERY
    dataSources:
      readwrite_ds:  #与auto-aware-data-source-name一致
        dataSourceNames:
          - write_ds
          - read_ds_0
        discoveryHeartbeatName: SSS-heartbeat  #从discoveryHeartbeats中定义的heartbeats选择
        discoveryTypeName: SHOW_SLAVE_STATUS#从discoveryTypes中定义的types选择
    discoveryHeartbeats:
      SSS-heartbeat:
        props:
          keep-alive-cron: '0/5 * * * * ?'
    discoveryTypes:
      SHOW_SLAVE_STATUS:  
        type: SHOW_SLAVE_STATUS
        props:
          delay-milliseconds-threshold: 3000
          group-name: 92504d5b-6dec-11e8-91ea-246e9612aaf1
六、启动项目

在这里插入图片描述

FAQ:

1、若发生错误,报autogent包不存在错误,直接maven reload项目即可
在这里插入图片描述

参考:
https://shardingsphere.apache.org/document/5.1.1/cn/reference/faq/

https://blog.csdn.net/u010882234/article/details/120087396

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

THMAIL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值