sharding-proxy+sharding-ui安装使用配置(亲测可用)
sharding官网(基于4.0版本)
https://shardingsphere.apache.org/document/legacy/4.x/document/cn/downloads/
运行mysql,zookeeper(已运行则略)
sharding-proxy安装启动配置
下载sharding-proxy(二进制文件)并解压
修改conf vim server.yaml
orchestration:
name: orchestration_ds
overwrite: true
registry:
type: zookeeper
serverLists: localhost:2181
namespace: orchestration
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: false
修改 config-sharding.yaml
schemaName: sharding_db
dataSources:
ds_0:
url: jdbc:mysql://localhost:3306/ds-0?serverTimezone=UTC&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 65
ds_1:
url: jdbc:mysql://localhost:3306/ds-1?serverTimezone=UTC&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 65
shardingRule:
tables:
t_order:
actualDataNodes: ds_$->{0..1}.t_order_$->{0..2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_order_$->{id % 3}
keyGenerator:
type: SNOWFLAKE
column: id
t_order_item:
actualDataNodes: ds_$->{0..1}.t_order_item_$->{0..2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_order_item_$->{order_id % 3}
keyGenerator:
type: SNOWFLAKE
column: id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_config
defaultDataSourceName: ds_0
defaultTableStrategy:
none:
mysql建测试库和表
库名表名要和配置文件内容相匹配,sharding-proxy不会自己给你新建真实库和表
下载mysql驱动mysql-connector-java-5.1.47,解压后将mysql-connector-java-5.1.47.jar放到lib目录下,这里注意mysql驱动要用官网推荐的,不要自己升级或降低版本
启动 bin/start.sh
查看日志 tail -100f stdout.log
启动成功
使用Navicat(V11版本)连接proxy代理数据源
代理数据源的schema和table启动后自己建好了 登录信息在conf目录下的server.yaml
闭坑指南!!!!!navicat要使用12版本之前的版本,实测12,15,16....连接代理数据源都会有问题!!!!
sharding-ui启动使用
下载对应版本的二进制文件
查看sharding-ui的配置文件
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
server.port=8088
user.admin.username=admin
user.admin.password=admin
启动sharding-ui bin/start.sh
查看日志是否成功
浏览器访问服务器ip:8088,端口、用户名、密码在sharding-ui下conf下application.properties配置
添加注册中心,参考sharding-proxy下conf下server.yaml
连接,查看运行状态
查看配置管理
连接后会自动把配置信息展示在界面上
比如我们可以更改数据源中的数据重新定义分库分表规则
也可以定义多个数据源
后端微服务可以配置代理数据源即可实现分库分表