shardingsphere初体验-shardingsphere-UI
shardingsphere初体验-shardingsphere-UI
官方介绍
ShardingSphere-UI 是 ShardingSphere 的一个简单而有用的web管理控制台。它用于帮助用户更简单的使用 ShardingSphere 的相关功能,目前提供注册中心管理、动态配置管理、数据库编排等功能。
项目结构上采取了前后端分离的方式,前端使用 Vue 框架,后端采用 Spring Boot 框架。使用标准的 Maven 方式进行打包,部署,同时也可以采用前后端分离的方式本地运行,方便开发调试。
下载链接
ShardingSphere-UI下载链接
https://mirrors.bfsu.edu.cn/apache/shardingsphere/shardingsphere-ui-5.0.0-alpha/apache-shardingsphere-5.0.0-alpha-shardingsphere-ui-bin.tar.gz
对应版本的 shardingsphere-proxy 下载链接
https://archive.apache.org/dist/shardingsphere/5.0.0-alpha/
解压两个文件,然后修改 shardingsphere-proxy 的配置,alpha版本和beta版本配置稍微有些不一样,alpha版本的 server.yaml 的配置如下
authentication:
users:
root:
password: root
sharding:
password: sharding
authorizedSchemas: sharding_db
props:
# max-connections-size-per-query: 1
# acceptor-size: 16 # The default value is available processors count * 2.
# 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
# proxy-opentracing-enabled: false
# proxy-hint-enabled: false
# query-with-cipher-column: true
sql-show: true
# check-table-metadata-enabled: false
体验shardingsphere-ui
然后启动mysql
在启动 shardingsphere-proxy
windos下使用 start.bat命令启动,linux下使用start.sh进行启动。
最后启动 shardingsphere-ui
windos下使用 start.bat命令启动,linux下使用start.sh进行启动。
点击运行状态提示没有注册中心,然后我们点击添加注册中心,可以看到shardingsphere 支持zk和etcd
我们启动zk,然后填上配置,添加注册中心
添加完后,点击右侧的连接,效果如下
但是我们发现查看配置里面还是没有数据,后面发现是,要打开 shardingsphere-proxy 的这段配置,把信息注册到zk上
governance:
name: governance_ds
registryCenter:
type: ZooKeeper
serverLists: localhost:2181
props:
retryIntervalMilliseconds: 500
timeToLiveSeconds: 60
maxRetries: 3
operationTimeoutMilliseconds: 500
overwrite: false
重启 shardingsphere-proxy ,发现重启失败,原来是配置里的实例名称和创建的zk实例名称不一致,重建注册中心如下:
再次重启 shardingsphere-proxy ,虽然还报错,但是可以看到配置信息已经注册上来了,和 server.yaml 里的配置一样
经过一番挣扎,发现proxy的lib目录里面zk的jar版本是3.6.0,而我用的是zk是3.5.8,于是我重新下载了zk
下载链接如下:
http://archive.apache.org/dist/zookeeper/zookeeper-3.6.0/
重新跑一边流程,发现proxy 启动不报错了。
运行 examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/SpringBootStarterExample.java
可以看proxy 控制台的sql输出
试着修改配置,把展示sql改为false
再次运行SpringBootStarterExample.java
可以看到修改的配置生效了,proxy没有打印sql了