当前位置: 首页 > news >正文

shardingsphere-proxy部署

环境:
Os:Centos 7
版本:5.5.2
说明:
使用二进制分发包启动 Proxy,需要环境具备 Java JRE 8 或更高版本。

[root@localhost shardingsphere-proxy]# java -version
java version "1.8.0_361"
Java(TM) SE Runtime Environment (build 1.8.0_361-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)
You have new mail in /var/spool/mail/root

1.下载
下载地址
https://archive.apache.org/dist/shardingsphere/5.5.2/

下载的文件如下:
apache-shardingsphere-5.5.2-shardingsphere-proxy-bin.tar.gz

 

2.下载jdk
可以在oracle官网下载,我这里下载的文件如下:
mysql-connector-java-8.0.11.tar.gz

 

3.解压安装
[root@localhost shardingsphere-proxy]#tar -xvf apache-shardingsphere-5.5.2-shardingsphere-proxy-bin.tar.gz
[root@localhost shardingsphere-proxy]#mv apache-shardingsphere-5.5.2-shardingsphere-proxy-bin /opt/shardingsphere-proxy

 

4.使用默认配置
在使用默认配置之前,最好备份一下
[root@localhost conf]#cd /opt/shardingsphere-proxy/conf
[root@localhost conf]#cp global.yaml global.yaml.bak
[root@localhost conf]#cp database-sharding.yaml database-sharding_db.yaml.bak

 

5.配置global.yaml
global.yaml主要是进行通用配置,如模式、用户权限等。
我因为是在本地部署,所以使用了 Standalone单机部署。
如果是生产环境,推荐使用Cluster集群部署.

######################################################################################################
# 
# If you want to configure governance, authorization and proxy properties, please refer to this file.
# 
######################################################################################################
#
mode:type: Standalonerepository:type: JDBC
#    props:
#      namespace: governance_ds
#      server-lists: localhost:2181
#      retryIntervalMilliseconds: 500
#      timeToLiveSeconds: 60
#      maxRetries: 3
#      operationTimeoutMilliseconds: 500
#
authority:users:- user: root@%password: hxl3040admin: true
#    - user: sharding
#      password: shardingprivilege:type: ALL_PERMITTED
#
#transaction:
#  defaultType: XA
#  providerType: Atomikos
#
#sqlParser:
#  sqlStatementCache:
#    initialCapacity: 2000
#    maximumSize: 65535
#  parseTreeCache:
#    initialCapacity: 128
#    maximumSize: 1024
#
#logging:
#  loggers:
#  - loggerName: ShardingSphere-SQL
#    additivity: true
#    level: INFO
#    props:
#      enable: false
#
#sqlFederation:
#  sqlFederationEnabled: false
#  executionPlanCache:
#    initialCapacity: 2000
#    maximumSize: 65535
#
#props:
#  system-log-level: INFO
#  max-connections-size-per-query: 1
#  kernel-executor-size: 16  # Infinite by default.
#  proxy-frontend-flush-threshold: 128  # The default value is 128.
#  # sql-show is the same as props in logger ShardingSphere-SQL, and its priority is lower than logging rule
#  sql-show: false
#  check-table-metadata-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
#  proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide.
#  proxy-frontend-max-connections: 0 # Less than or equal to 0 means no limitation.
#  proxy-default-port: 3307 # Proxy default port.
#  proxy-netty-backlog: 1024 # Proxy netty backlog.
#  cdc-server-port: 33071 # CDC server port
#  proxy-frontend-ssl-enabled: false
#  proxy-frontend-ssl-cipher: ''
#  proxy-frontend-ssl-version: TLSv1.2,TLSv1.3

 

6.配置分片规则

more /opt/shardingsphere-proxy/conf/database-sharding.yaml

######################################################################################################
#
# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.
#
######################################################################################################databaseName: hxl_sharding_dbdataSources:ds_0:url: jdbc:mysql://192.168.1.113:3306/db_test?useSSL=false
    username: rootpassword: hxl3040connectionTimeoutMilliseconds: 30000idleTimeoutMilliseconds: 60000maxLifetimeMilliseconds: 1800000maxPoolSize: 50minPoolSize: 1
#  ds_1:
#    url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?useSSL=false
#    username: root
#    password:
#    connectionTimeoutMilliseconds: 30000
#    idleTimeoutMilliseconds: 60000
#    maxLifetimeMilliseconds: 1800000
#    maxPoolSize: 50
#    minPoolSize: 1
#
rules:
- !SHARDINGtables:t_order:actualDataNodes: ds_0.t_order_${0..9} ##通过proxy会创建0-9共10个表tableStrategy:standard:shardingColumn: order_idshardingAlgorithmName: t_order_inlinekeyGenerateStrategy:column: order_idkeyGeneratorName: snowflakeauditStrategy:auditorNames:- sharding_key_required_auditorallowHintDisable: true
#    t_order_item:
#      actualDataNodes: ds_${0..1}.t_order_item_${0..1}
#      tableStrategy:
#        standard:
#          shardingColumn: order_id
#          shardingAlgorithmName: t_order_item_inline
#      keyGenerateStrategy:
#        column: order_item_id
#        keyGeneratorName: snowflake
#  bindingTables:
#    - t_order,t_order_item
#  defaultDatabaseStrategy:
#    standard:
#      shardingColumn: user_id
#      shardingAlgorithmName: database_inline
#  defaultTableStrategy:
#    none:defaultAuditStrategy:auditorNames:- sharding_key_required_auditorallowHintDisable: true
#shardingAlgorithms:
#    database_inline:
#      type: INLINE
#      props:
#        algorithm-expression: ds_${user_id % 2}t_order_inline:type: INLINEprops:algorithm-expression: t_order_${order_id % 10}
#    t_order_item_inline:
#      type: INLINE
#      props:
#        algorithm-expression: t_order_item_${order_id % 2}
#keyGenerators:snowflake:type: SNOWFLAKEauditors:sharding_key_required_auditor:type: DML_SHARDING_CONDITIONS
#
#- !BROADCAST
#  tables:
#    - t_address

 

7.引入MySQL依赖
在sharding-proxy 路径下新建 ext-lib 目录,将 mysql-connector-java-8.0.11.jar 驱动包放进来.
[root@localhost shardingsphere-proxy]# cd /opt/shardingsphere-proxy
[root@localhost shardingsphere-proxy]# mkdir ext-lib
[root@localhost mysql-connector-java-8.0.11]# cp mysql-connector-java-8.0.11.jar /opt/shardingsphere-proxy/ext-lib/

8.启动
验证各种场景
8.1 实际的数据库不存在
启动/停止服务
# 启动
/opt/shardingsphere-proxy/bin/start.sh
报错:
[ERROR] 2026-02-06 10:25:40.879 [main] com.zaxxer.hikari.pool.HikariPool - HikariPool-2 - Exception during pool initialization.
java.sql.SQLSyntaxErrorException: Unknown database 'db_test11'

8.2 实际表不存在
# 启动
/opt/shardingsphere-proxy/bin/start.sh

实际的表不存在,可以启动成功的

 

9.通过 shardingproxy 创建表
启动shardingproxy 会启动的3307端口,需要通过3307端口连接shardingproxy
192.168.1.14

[root@hxl-mysql-211 ~]# /data/middle/mysql57/bin/mysql -h 192.168.1.14 -uroot -pyeemiao3040 -P3307
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.22-ShardingSphere-Proxy 5.5.2 Source distributionCopyright (c) 2000, 2023, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| hxl_sharding_db    |
| information_schema |
| mysql              |
| performance_schema |
| shardingsphere     |
| sys                |
+--------------------+
6 rows in set (0.02 sec)mysql> use hxl_sharding_db;
Database changed
mysql> show tables;
Empty set (0.00 sec)

 

http://www.jsqmd.com/news/365793/

相关文章:

  • 2026年沈阳APM521电能计量表推荐厂家品牌排行榜 - myqiye
  • 基于大数据的淘宝京东电子产品数据分析的设计与实现-爬虫可视化
  • 产后康复+育儿衔接!2026北京月嫂服务公司推荐排行 康复适配/衔接无忧 - 极欧测评
  • 2026 无锡英语雅思培训教育机构推荐;雅思培训课程中心权威口碑榜单 - 老周说教育
  • 直进式拉丝机快速定制费用多少,怎么选更划算 - mypinpai
  • 油品质量分析仪选购指南:性价比、质量与口碑俱佳的品牌有哪些? - 品牌推荐大师1
  • 2026 泉州英语雅思培训教育机构推荐,雅思培训课程中心权威口碑榜单 - 老周说教育
  • 工程采购必看:难燃型改性聚乙烯蜂窝卷材厂家避坑指南 - 深度智识库
  • 2026 深圳英语雅思培训教育机构推荐,雅思培训课程中心权威口碑榜单 - 老周说教育
  • 2026年哈尔滨性价比高的小众技能培训学校排名,技能培训学校优势揭秘 - 工业设备
  • 2026年度杭州会计师事务所综合评估与选型指南 - 品牌推荐
  • 2026 沈阳英语雅思培训教育机构推荐;雅思培训课程中心权威口碑榜单 - 老周说教育
  • 2026全屋通铺纯实木地板品牌推荐:地暖适配+防潮耐用 - 速递信息
  • 哈尔滨汽车维修哪家好,看看解决汽车常见故障的优选 - 工业推荐榜
  • 多芬超级碗广告旨在倡导女孩在体育运动中拥有自信的体态
  • HDFS 从概念到实战详解:大数据分布式存储核心指南
  • 想选国产zeta电位分析仪?2026年这些品牌厂家值得考虑 - 品牌推荐大师
  • 2026上海及全国水泵与供水设备厂家深度盘点:覆盖静音泵、螺杆泵、循环泵 - 品牌推荐大师1
  • 探讨2026年哈尔滨汽车保养服务,汽车保养服务帮我推荐合适的 - 工业品牌热点
  • 2026年深圳标识制作最新推荐厂家:医院标识制作、学校标识制作、智慧商场标识、智慧园区标识、智慧门店标识、飞机场标识制作 - 海棠依旧大
  • 测试:AI如何优化职场工作流(换行修复版)
  • 易营宝智能建站系统是否通过ISO 27001认证?数据存储位置与跨境传输合规说明
  • 冥想第一千七百九十天(1790)
  • 化学镀铜药水厂家选购指南:从合规到增效的全维度决策框架 - 速递信息
  • 危化场所防雷检测哪家专业?2026年北京防雷检测公司推荐与评价,聚焦特殊行业合规痛点 - 品牌推荐
  • 测试:AI如何改变未来的职业版图
  • 测完这批工具 10个降AI率软件降AIGC网站 本科生必看!深度测评与推荐
  • 安全性生长激素推荐:金赛增长效原研赋能儿童规范成长 - 速递信息
  • 基于hadoop的租车网站的数据分析系统的设计与实现_8003i-爬虫可视化
  • 导师推荐 8个一键生成论文工具:本科生毕业论文+开题报告高效写作测评