Sharding-Proxy之读写分离

一、简介以及环境准备

        Sharding-Proxy与Sharding-JDBC一样,并不会进行主从复制,主从复制依然是有MySQL自己完成。

mysql读写分离服务器如下:

Master(192.168.56.20)、slave(192.168.56.21)、数据库是user_db

二、Sharding-Proxy 配置

1、修改server.yaml 文件

rules:
  - !AUTHORITY
    users:
      - dhapp@%:Tz@202011
      - sharding@:sharding
    provider:
      type: ALL_PRIVILEGES_PERMITTED
  - !TRANSACTION
    defaultType: XA #支持 XA 事务
    providerType: Atomikos #默认的事务管理器为 Atomikos

props:
  max-connections-size-per-query: 1
  kernel-executor-size: 16  # Infinite by default.
  proxy-frontend-flush-threshold: 128  # The default value is 128.
  proxy-opentracing-enabled: false
  proxy-hint-enabled: false
  sql-show: false
  check-table-metadata-enabled: false
  show-process-list-enabled: false
    # Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy.
    # The default value is -1, which means set the minimum value for different JDBC drivers.
  proxy-backend-query-fetch-size: -1
  check-duplicate-table-enabled: false
  sql-comment-parse-enabled: false
  proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide.
    # Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution
    # if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL.
  proxy-backend-executor-suitable: OLAP
  proxy-frontend-max-connections: 0 # Less than or equal to 0 means no limitation.
  sql-federation-enabled: false

2、修改 config-readwrite-splitting.yaml 文件(此文件为读写分离的配置)

schemaName: readwrite_splitting_db

dataSources:
  write_ds:
    url: jdbc:mysql://192.168.56.20:3306/user_db?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: dhapp
    password: Tz@202011
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  read_ds_0:
    url: jdbc:mysql://192.168.56.21:3306/user_db?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: dhapp
    password: Tz@202011
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1

rules:
- !READWRITE_SPLITTING
  dataSources:
    pr_ds:
      writeDataSourceName: write_ds
      readDataSourceNames:
        - read_ds_0

三、测试

1、启动Sharding-Proxy 服务 

  ./start.sh

2、连接sharding-proxy      

 3、创建数据表

use readwrite_splitting_db;

create table t_order(`order_id` bigint primary key,`user_id` int not null,`status` varchar(50));

insert into t_order(`order_id`,`user_id`,`status`)values(11,1,'test');

到主从库中查询:

master: slave:

 4、只修改slave中的数据(手动修改的)

 

 通过sharding-proxy去查询,看一下是否读写分离,查的是否是slave的数据

 由上可以,实现了读写分离的功能

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这些配置是用于提交 Spark 应用程序的命令行参数,具体说明如下: - `--master`: Spark 应用程序所连接的 Spark 集群的 URL。可以是 local、local[N]、local[*]、spark://HOST:PORT、mesos://HOST:PORT、yarn、yarn-client、yarn-cluster 等。 - `--deploy-mode`: Spark 应用程序的部署模式。可以是 client 或 cluster。 - `--conf`: Spark 应用程序的配置参数,以 key=value 的形式指定。例如,可以使用 `--conf spark.executor.memory=2g` 来设置每个执行器的内存为 2GB。 - `--driver-memory`: 驱动程序所需的内存大小。可以是 1g、2g 等。 - `--executor-memory`: 执行器所需的内存大小。可以是 1g、2g 等。 - `--executor-cores`: 每个执行器所需的 CPU 核心数。 - `--jars`: 逗号分隔的 JAR 包列表,用于向 Spark 应用程序提供额外的依赖项。 - `--class`: 主类的完全限定名称,用于指定 Spark 应用程序的入口点。 - `application-jar`: Spark 应用程序的 JAR 包路径。 - `application-arguments`: Spark 应用程序的命令行参数。 例如,以下是一个提交 Spark 应用程序的示例命令: ``` ./bin/spark-submit \ --master yarn \ --deploy-mode cluster \ --num-executors 10 \ --executor-memory 2g \ --executor-cores 4 \ --jars /path/to/custom.jar,/path/to/another.jar \ --class com.example.MySparkApp \ myapp.jar \ arg1 arg2 arg3 ``` 这个命令将提交一个名为 `MySparkApp` 的 Spark 应用程序到一个 YARN 集群中,使用 cluster 模式进行部署。该应用程序将使用 10 个执行器,每个执行器分配 2GB 的内存和 4 个 CPU 核心。两个额外的 JAR 包 `/path/to/custom.jar` 和 `/path/to/another.jar` 将被添加到 Spark 应用程序的类路径中。应用程序的入口点是 `com.example.MySparkApp` 类的 main 方法,该类位于 `myapp.jar` 中。最后,应用程序将带有三个参数 `arg1`、`arg2` 和 `arg3` 运行。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值