ShardingSphere-Proxy安装

ShardingSphere-Proxy

一、安装

1、获取安装包(需要用5.1.2版本,schema映射和持久化需求刚好满足)

[root@shardingsphere-proxy ~]$ wget https://archive.apache.org/dist/shardingsphere/5.1.2/apache-shardingsphere-5.1.2-shardingsphere-proxy-bin.tar.gz

2、解压

[root@shardingsphere-proxy ~]$ tar -zxvf apache-shardingsphere-5.1.2-shardingsphere-proxy-bin.tar.gz

3、移动到指定目录

[root@shardingsphere-proxy ~]$ mv apache-shardingsphere-5.1.2-shardingsphere-proxy-bin /data/software/

二、配置

1、进入conf目录

[root@shardingsphere-proxy ~]$ cd /data/software/apache-shardingsphere-5.1.2-shardingsphere-proxy-bin/conf

2、编辑server.yaml文件

[root@shardingsphere-proxy conf]$ vim server.yaml
# 加入如下配置,保存退出
mode:
  type: Standalone
  repository:
    type: File
    props:
      path: /data/software/apache-shardingsphere-5.1.2-shardingsphere-proxy-bin/repo_pg
  overwrite: false #追加
#注意:users为用于登录计算节点的用户名,授权主机和密码的组合。格式:<username>@<hostname>:<password>,hostname 为 % 或空字符串表示不限制授权主机
rules:
  - !AUTHORITY
    users:
      - root@%:root
      - sharding@:sharding
    provider:
      type: ALL_PERMITTED
  - !TRANSACTION
    defaultType: XA
    providerType: Atomikos
  - !SQL_PARSER
    sqlCommentParseEnabled: true
    sqlStatementCache:
      initialCapacity: 2000
      maximumSize: 65535
      #concurrencyLevel: 4
    parseTreeCache:
      initialCapacity: 128
      maximumSize: 1024
      #concurrencyLevel: 4

3、自定义yaml文件(名称自定义就好,需要时.yaml结尾)

[root@shardingsphere-proxy conf]$ vim config-encrypt-dwh.yaml
# 加入如下配置,保存退出
schemaName: testdb

dataSources:
  ds_0:
    url: jdbc:postgresql://ip1:端口1,ip2:端口2,ip3:端口3/dwh
    username: xxx
    password: xxx
    connectionTimeoutMilliseconds: 3000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
# 规则必须得配(如果没有可以随便先配一个,不然启动不了),后续也可以通过sql的方式去动态添加规则
rules:
- !ENCRYPT
  encryptors:
    aes_encryptor:
      type: XXX_DATA_AES
  tables:
    sprm_pr_header:
      columns:
        receiver_email_address:
          cipherColumn: receiver_email_address
          encryptorName: aes_encryptor
        tax_register_bank_account:
          cipherColumn: tax_register_bank_account
          encryptorName: aes_encryptor

三、测试

1、启动(start.sh [port] [confPath])

可以指定端口号和配置文件(默认会解析conf下全部的yaml文件)

[root@shardingsphere-proxy conf]$ ../bin/start.sh 3308

2、通过客户端连接

navicat、dbeaver、datagrip等客户端进行连接测试,注意端口号为上边设置的3308或者其他

3、关闭

[root@shardingsphere-proxy conf]$ ../bin/stop.sh

四、维护

1、加解密规则

#给dws_xxx_58409表中bank_account_num字段加XXX_DATA_AES解密规则(这个规则是我自定义的,官网可查看内置规则)
CREATE ENCRYPT RULE dws_xxx_58409 (
    COLUMNS(
        (NAME=bank_account_num,CIPHER=bank_account_num,TYPE(NAME=XXX_DATA_AES))
));

2、查看解密规则

show encrypt rules from testdb;

3、修改解密规则

#把TYPE中的NAME修改为指定的加密规则
ALTER ENCRYPT RULE dws_xxx_58409 (
    COLUMNS(
        (NAME=bank_account_num,CIPHER=bank_account_num,TYPE(NAME=MD5))
));

4、删除解密规则

DROP ENCRYPT RULE dws_xxx_58409;

五、注意

1、代理PostgreSQL时,如果某个database的不同的schema中有表名相同的表,那么给该表名加解密规则后都会生效。但是如果加了解密规则后,在其他schema中创建了一个同样名字的表,则解密规则不会在后续这张表生效。

2、如果在运行期间通过sql的方式,加了一些规则,那么这些规则会在指定的持久化目录下。当然持久化目录下,还会把当时启动程序时的conf文件都加载过来。

3、如果我们启动了一次shardingsphere,后续重启时,shardingsphere会去加载持久化目录下的配置,而不会加载conf下的配置。(如果我们修改的conf下的配置,我们需要删除掉持久化目录,重新启动shardingsphere。删除持久化目录时也要注意,如果之前运行期间通过sql的方式加了一些规则,那么删除了持久化目录时,这些规则也会被删除掉。需要在删除持久化目录前,自己手动把这些配置移动到conf目录下。)

eg:/data/software/apache-shardingsphere-5.1.2-shardingsphere-proxy-bin/repo_pg/metadata/testdb/versions/0/rules,这个路径是我的testdb下的全部规则,如果运行期间通过sql方式动态添加规则,则这些规则会在这个文件里。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值