简介
ShardingSphere‐UI 是 ShardingSphere 提供的 web 管理控制台。它用于帮助用户管理ShardingSphere Proxy配置,目前提供注册中心管理、动态配置管理、运行节点状态监控等功能。 项目结构上采取了前后端分离的方式,前端使用 Vue 框架,后端采用 Spring Boot 框架。使用标准的 Maven 方式进行打包,部署,同时也可以采用前后端分离的方式本地运行,方便开发调试。
运行原理:ShardingSphere‐UI通过注册中心来拉取Sharding Proxy的配置信息,达到对Sharding Proxy的管理。注册中心支持Zookeeper、Etcd两种。
ShardingSphere UI 运行
本次使用:shardingsphere-ui-5.0.0-alpha
1、Zookeeper
下载Zookeeper,shardingsphere-ui-5.0.0-alpha对应Zookeeper版本3.6+,我用的3.7。
进行简单的配置即可
直接运行bin目录下面zkServer.cmd即可
2、shardingsphere-proxy
下载shardingsphere-proxy 5.0.0-alpha版,shardingsphere-ui和shardingsphere-proxy版本要匹配
修改shardingsphere-proxy下conf中的文件server.yaml
governance:
name: governance_ds
registryCenter:
type: ZooKeeper
serverLists: localhost:2181
props:
retryIntervalMilliseconds: 500
timeToLiveSeconds: 60
maxRetries: 3
operationTimeoutMilliseconds: 500
overwrite: false
authentication:
users:
root:
password: root
sharding:
password: sharding
authorizedSchemas: sharding_db
props:
max-connections-size-per-query: 1
executor-size: 16 # Infinite by default.
proxy-frontend-flush-threshold: 128 # The default value is 128.
# LOCAL: Proxy will run with LOCAL transaction.
# XA: Proxy will run with XA transaction.
# BASE: Proxy will run with B.A.S.E transaction.
proxy-transaction-type: LOCAL
xa-transaction-manager-type: Atomikos
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: true
check-table-metadata-enabled: false
lock-wait-timeout-milliseconds: 50000 # The maximum time to wait for a lock
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: fals
config-xxx.yaml文件对应相应策略自行按需配置
启动运行bin目录下start.bat即可
3、shardingsphere-ui
解压下载好的shardingsphere-ui,windows下有可能会存在问题,对于压缩目录中的文件有长度限制
可以参考 shardingsphere.apache.org/document/cu… 中第14条
解压完成后运行bin目录下start.bat即可
server.port=8088
user.admin.username=admin
user.admin.password=admin
登录进入之后,添加注册中心,治理实例名称就是proxy的server.yaml文件中,配置的ZooKeeper模块的name
添加完成之后,点击激活连接
shardingsphere-ui就会拉取Zookeeper中的配置信息
可以动态添加新的schema
运行信息中可以对proxy节点是否启用进行控制
总结
本次针对Shardingsphere ui项目进行了使用学习,了解了该项目的用途:通过Zookeeper这样的注册中心对proxy节点进行可视化管理,实现动态配置。最开始是想通过github上的5.0.0-beta版原码进行构建运行的,但是由于Shardingsphere ui frontend部分中需要的一些依赖,在我本机通过npm构建的时候总是出错,没能实现,这边留个小尾巴。再就是构建Shardingsphere ui原码时发现的一件趣事,对shardingsphere-governance项目中类的调用报错,看了本机shardingsphere-governance的原码没发现问题,最后在github上看shardingsphere的原码时,发现了提交时间为19小时前,果断同步了最新代码,这边我是48小时前pull的代码,完美解决,不得不赞叹shardingsphere开源组织的活跃。后续还会继续深入Shardingsphere的原码学习。