赞
踩
来我的dou音 aa10246666, 看配套视频
角色 | 版本 | 机器名 | IP地址 |
shard1 | pg 14 | node1 | 10.211.55.9 |
shard2 | pg 14 | node2 | 10.211.55.4 |
ShardingSphere-Proxy | 5.1.0 | node3 | 10.211.55.6 |
用于测试连接ShardingSphere-Proxy | pg 14 | node4 | 10.211.55.7 |
create user appuser with password '123';
grant appuser to postgres ;
vim /etc/postgresql/14/main/pg_hba.conf
host all appuser 0.0.0.0/0 md5
重载访问控制文件 select pg_reload_conf();
postgres=# select pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)
shard1上创建数据库 shard1
create database shard1;
shard2上创建数据库 shard2
create database shard2;
安装及配置jdk(jdk的版本要依据你cpu来选择,我用的是mac虚出来的虚机)
tar xzf jdk-8u202-linux-arm64-vfp-hflt.tar.gz
mv jdk1.8.0_202 /usr/local/
/etc/profile最后添加如下配置
PATH=/usr/local/jdk1.8.0_202/bin:$PATH
source /etc/profile
安装及配置ShardingSphere-Proxy
tar xzf apache-shardingsphere-5.1.0-shardingsphere-proxy-bin.tar.gz
mv apache-shardingsphere-5.1.0-shardingsphere-proxy-bin /usr/local/
rules:
- !AUTHORITY
users:
- root@%:123
provider:
type: ALL_PRIVILEGES_PERMITTEDprops:
sql-show: true
schemaName: testdb
dataSources:
ds_0:
url: jdbc:postgresql://10.211.55.9:5432/shard1
username: appuser
password: 123
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:postgresql://10.211.55.4:5432/shard2
username: appuser
password: 123
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1rules:
- !SHARDING
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..15}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_inline
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
# 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,t_order_item
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: database_inline
defaultTableStrategy:
none:
shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expres
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。