关于开放源代码:ShardingSphere-4x-ShardingScalingAlpha-用户手册

100次阅读

共计 5136 个字符,预计需要花费 13 分钟才能阅读完成。

简介

Sharding-Scaling 是一个提供给用户的通用的 ShardingSphere 数据接入迁徙,及弹性伸缩的解决方案。

4.1.0 开始向用户提供。

部署启动

  1. 执行以下命令,编译生成 sharding-scaling 二进制包:

git clone https://github.com/apache/shardingsphere.git;cd shardingsphere;
mvn clean install -Prelease;

公布包所在目录为:/sharding-distribution/sharding-scaling-distribution/target/apache-shardingsphere-${latest.release.version}-sharding-scaling-bin.tar.gz

  1. 解压缩公布包,批改配置文件conf/server.yaml,这里次要批改启动端口,保障不与本机其余端口抵触,其余值放弃默认即可:
port: 8888
blockQueueSize: 10000
pushTimeout: 1000
workerThread: 30
  1. 启动 sharding-scaling:
sh bin/start.sh
  1. 查看日志logs/stdout.log,确保启动胜利。
  2. 应用 curl 命令再次确认失常运行。
curl -X GET http://localhost:8888/shardingscaling/job/list

应许可为:

{"success":true,"errorCode":0,"errorMsg":null,"model":[]}

完结 Sharding-Scaling

sh bin/stop.sh

利用配置项

利用现有配置项如下,相应的配置可在 conf/server.yaml 中批改:

名称 阐明 默认值
port HTTP 服务监听端口 8888
blockQueueSize 数据传输通道队列大小 10000
pushTimeout 数据推送超时工夫,单位 ms 1000
workerThread 工作线程池大小,容许同时运行的迁徙工作线程数 30

使用手册

环境要求

纯 JAVA 开发,JDK 倡议 1.8 以上版本。

反对迁徙场景如下:

源端 指标端 是否反对
MySQL(5.1.15 ~ 5.7.x) sharding-proxy 反对
PostgreSQL(9.4 ~) sharding-proxy 反对

留神
如果后端连贯 MySQL 数据库,须要下载 MySQL Connector/J,
解压缩后,将 mysql-connector-java-5.1.47.jar 拷贝到 ${sharding-scaling}lib 目录。

权限要求

MySQL 须要开启 binlogbinlog format 为 Row 模式,且迁徙时所应用用户须要赋予 Replication 相干权限。

+-----------------------------------------+---------------------------------------+
| Variable_name                           | Value                                 |
+-----------------------------------------+---------------------------------------+
| log_bin                                 | ON                                    |
| binlog_format                           | ROW                                   |
+-----------------------------------------+---------------------------------------+

+------------------------------------------------------------------------------+
|Grants for ${username}@${host}                                                |
+------------------------------------------------------------------------------+
|GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ${username}@${host}     |
|.......                                                                       |
+------------------------------------------------------------------------------+

PostgreSQL 须要开启 test_decoding

API 接口

弹性迁徙组件提供了简略的 HTTP API 接口

创立迁徙工作

接口形容:POST /shardingscaling/job/start

申请体:

Parameter Describe
ruleConfiguration.sourceDatasource 源端 sharding sphere 数据源相干配置
ruleConfiguration.sourceRule 源端 sharding sphere 表规定相干配置
ruleConfiguration.destinationDataSources.name 指标端 sharding proxy 名称
ruleConfiguration.destinationDataSources.url 指标端 sharding proxy jdbc url
ruleConfiguration.destinationDataSources.username 指标端 sharding proxy 用户名
ruleConfiguration.destinationDataSources.password 指标端 sharding proxy 明码
jobConfiguration.concurrency 迁徙并发度,举例:如果设置为 3,则待迁徙的表将会有三个线程同时对该表进行迁徙,前提是该表有整数型主键

示例:

curl -X POST \
  http://localhost:8888/shardingscaling/job/start \
  -H 'content-type: application/json' \
  -d '{"ruleConfiguration": {"sourceDatasource":"ds_0: !!YamlDataSourceConfiguration\n  dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n  properties:\n    jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n    username: root\n    password: '\''123456'\''\n    connectionTimeout: 30000\n    idleTimeout: 60000\n    maxLifetime: 1800000\n    maxPoolSize: 50\n    minPoolSize: 1\n    maintenanceIntervalMilliseconds: 30000\n    readOnly: false\n","sourceRule":"defaultDatabaseStrategy:\n  inline:\n    algorithmExpression: ds_${user_id % 2}\n    shardingColumn: user_id\ntables:\n  t1:\n    actualDataNodes: ds_0.t1\n    keyGenerator:\n      column: order_id\n      type: SNOWFLAKE\n    logicTable: t1\n    tableStrategy:\n      inline:\n        algorithmExpression: t1\n        shardingColumn: order_id\n  t2:\n    actualDataNodes: ds_0.t2\n    keyGenerator:\n      column: order_item_id\n      type: SNOWFLAKE\n    logicTable: t2\n    tableStrategy:\n      inline:\n        algorithmExpression: t2\n        shardingColumn: order_id\n","destinationDataSources": {"name":"dt_0","password":"123456","url":"jdbc:mysql://127.0.0.1:3306/test2?serverTimezone=UTC&useSSL=false","username":"root"}
   },
   "jobConfiguration": {"concurrency": 3}
}'

返回信息:

{
   "success": true,
   "errorCode": 0,
   "errorMsg": null,
   "model": null
}

查问迁徙工作进度

接口形容:GET /shardingscaling/job/progress/{jobId}

示例:

curl -X GET \
  http://localhost:8888/shardingscaling/job/progress/1

返回信息:

{
   "success": true,
   "errorCode": 0,
   "errorMsg": null,
   "model": {
        "id": 1,
        "jobName": "Local Sharding Scaling Job",
        "status": "RUNNING/STOPPED"
        "syncTaskProgress": [{
            "id": "127.0.0.1-3306-test",
            "status": "PREPARING/MIGRATE_HISTORY_DATA/SYNCHRONIZE_REALTIME_DATA/STOPPING/STOPPED",
            "historySyncTaskProgress": [{
                "id": "history-test-t1#0",
                "estimatedRows": 41147,
                "syncedRows": 41147
            }, {
                "id": "history-test-t1#1",
                "estimatedRows": 42917,
                "syncedRows": 42917
            }, {
                "id": "history-test-t1#2",
                "estimatedRows": 43543,
                "syncedRows": 43543
            }, {
                "id": "history-test-t2#0",
                "estimatedRows": 39679,
                "syncedRows": 39679
            }, {
                "id": "history-test-t2#1",
                "estimatedRows": 41483,
                "syncedRows": 41483
            }, {
                "id": "history-test-t2#2",
                "estimatedRows": 42107,
                "syncedRows": 42107
            }],
            "realTimeSyncTaskProgress": {
                "id": "realtime-test",
                "delayMillisecond": 1576563771372,
                "logPosition": {
                    "filename": "ON.000007",
                    "position": 177532875,
                    "serverId": 0
                }
            }
        }]
   }
}

查问所有迁徙工作

接口形容:GET /shardingscaling/job/list

示例:

curl -X GET \
  http://localhost:8888/shardingscaling/job/list

返回信息:

{
  "success": true,
  "errorCode": 0,
  "model": [
    {
      "jobId": 1,
      "jobName": "Local Sharding Scaling Job",
      "status": "RUNNING"
    }
  ]
}

进行迁徙工作

接口形容:POST /shardingscaling/job/stop

申请体:

Parameter Describe
jobId job id

示例:

curl -X POST \
  http://localhost:8888/shardingscaling/job/stop \
  -H 'content-type: application/json' \
  -d '{"jobId":1}'

返回信息:

{
   "success": true,
   "errorCode": 0,
   "errorMsg": null,
   "model": null
}

通过 UI 界面来操作

Sharding-scaling 与 sharding-ui 集成了用户界面,所以上述所有工作相干的操作都能够通过 UI 界面点点鼠标来实现,当然实质上还是调用了上述根本接口。

更多信息请参考 sharding-ui 我的项目。

正文完
 0