ShardingSphere-Proxy:从实际场景出发,快速上手(二)

Handpc
发布于 2022-6-22 17:14
浏览
0收藏

 

三、如何开始
ShardingSphere-Proxy 的启动方式有三种:二进制包、Docker、Helm,并分为单机部署和集群部署。文章以单机二进制包的方式启动。

  1. 通过 下载页面[1] 获取 ShardingSphere-Proxy 二进制安装包;
  2. 解压缩后修改 conf/server.yaml 和以 config- 前缀开头的文件,进行分片、读写分离等规则配置;
  3. Linux 操作系统请运行 bin/start.sh,Windows 操作系统请运行 bin/start.bat 启动 ShardingSphere-Proxy。


下载后的文件目录如下:

├── LICENSE
├── NOTICE
├── README.txt
├── bin # 启动停止脚本
├── conf # 服务配置,分库分表、读写分离、数据加密等功能的配置文件
├── lib # Jar 包
└── licenses

 

1. 将 MySQL 的 JDBC 驱动复制到 ext-lib 包
下载驱动 mysql-connector-java-5.1.47.jar[2] 或者 mysql-connector-java-8.0.11.jar[3] 放入 ext-lib 包。因为初始目录中并没有 ext-lib,需要自行创建。

 

2. 修改 conf/server.yaml 配置文件
server.yaml 配置中默认集群运行模式,这里提供一份单机的运行配置。

mode:
 type: Standalone # 单机模式
 repository:
   type: File
   props:
     path: /Users/xxx/software/apache-shardingsphere-5.1.0-shardingsphere-proxy/file # 元数据配置等持久化文件路径
 overwrite: false # 是否覆盖已存在的元数据

rules: # 认证信息
 - !AUTHORITY
   users: # 初始化用户
     - root@%:root
     - sharding@:sharding
   provider:
     type: ALL_PRIVILEGES_PERMITTED
 - !TRANSACTION
   defaultType: XA
   providerType: Atomikos
 - !SQL_PARSER
   sqlCommentParseEnabled: true
   sqlStatementCache:
     initialCapacity: 2000
     maximumSize: 65535
     concurrencyLevel: 4
   parseTreeCache:
     initialCapacity: 128
     maximumSize: 1024
     concurrencyLevel: 4

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
 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
   # and block other clients if client connections are more than `proxy-frontend-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
   # Available proxy backend driver type: JDBC (default), ExperimentalVertx
 proxy-backend-driver-type: JDBC

 

需要注意,如果启动单机 ShardingSphere-Proxy,后续需要 Proxy 配置变更,建议将 mode.overwrite 设置为 true,这样 ShardingSphere-Proxy 在启动时就会重新加载元数据。


3. 启动 ShardingSphere-Proxy
执行启动命令:sh bin/start.sh。默认启动端口 3307,可以通过启动脚本命令追加参数的方式替换端口:sh bin/start.sh 3308。

 

查看 ShardingSphere-Proxy 是否启动成功,执行查看日志命令:tail -100f logs/stdout.log。如最后一行出现下述信息,即为启动成功:

[INFO ] xxx-xx-xx xx:xx:xx.xxx [main] o.a.s.p.frontend.ShardingSphereProxy - ShardingSphere-Proxy Standalone mode started successfully

 

文章转自公众号:龙台的技术笔记

已于2022-6-22 17:14:24修改
收藏
回复
举报
回复
    相关推荐