Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature:add sharding-proxy #3289

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Expand Up @@ -581,6 +581,9 @@ JENKINS_HOST_HTTP_PORT=8090
JENKINS_HOST_SLAVE_AGENT_PORT=50000
JENKINS_HOME=./jenkins/jenkins_home

### SHARDING-PROXY ###############################################
SHARDING_PROXY_PORT=3308

### CONFLUENCE ###############################################
CONFLUENCE_POSTGRES_INIT=true
CONFLUENCE_VERSION=6.13-ubuntu-18.04-adoptopenjdk8
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Expand Up @@ -545,8 +545,28 @@ services:
- ${MYSQL_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
ports:
- "${MYSQL_PORT}:3306"


### sharding-proxy ###################################################
sharding-proxy:
build:
context: ./sharding-proxy
args:
- SHARDING_PROXY_PORT=${SHARDING_PROXY_PORT}
volumes:
- ./sharding-proxy/conf/:/opt/shardingsphere-proxy/conf
- ./sharding-proxy/ext-lib/:/opt/shardingsphere-proxy/ext-lib
ports:
- "${SHARDING_PROXY_PORT}:${SHARDING_PROXY_PORT}"
expose:
- "${SHARDING_PROXY_PORT}"
extra_hosts:
- "dockerhost:${DOCKER_HOST_IP}"
networks:
- backend
links:
- docker-in-docker


### Percona ################################################
percona:
Expand Down
10 changes: 10 additions & 0 deletions sharding-proxy/Dockerfile
@@ -0,0 +1,10 @@
FROM apache/shardingsphere-proxy:latest
ARG SHARDING_PROXY_PORT
LABEL maintainer="WuweiMing <wwm041544363@gmail.com>"

ENV PORT=${SHARDING_PROXY_PORT}

CMD ["start.sh"]


EXPOSE ${SHARDING_PROXY_PORT}
125 changes: 125 additions & 0 deletions sharding-proxy/conf/config-database-discovery.yaml
@@ -0,0 +1,125 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# 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.
#

######################################################################################################
#
# Here you can configure the rules for the proxy.
# This example is configuration of HA rule.
#
######################################################################################################
#
#schemaName: database_discovery_db
#
#dataSources:
# primary_ds:
# url: jdbc:postgresql://127.0.0.1:5432/demo_primary_ds
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 3000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# replica_ds_0:
# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_0
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 3000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# replica_ds_1:
# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_1
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 3000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
#
#rules:
#- !DB_DISCOVERY
# dataSources:
# pr_ds:
# dataSourceNames:
# - ds_0
# - ds_1
# - ds_2
# discoveryTypeName: mgr
# discoveryTypes:
# mgr:
# type: MGR
# props:
# groupName: 92504d5b-6dec-11e8-91ea-246e9612aaf1
# zkServerLists: 'localhost:2181'
# keepAliveCron: '0/5 * * * * ?'

######################################################################################################
#
# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.
#
######################################################################################################

#schemaName: database_discovery_db
#
#dataSources:
# ds_0:
# url: jdbc:mysql://127.0.0.1:3306/demo_primary_ds?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 3000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# ds_1:
# url: jdbc:mysql://127.0.0.1:3306/demo_replica_ds_0?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 3000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# ds_2:
# url: jdbc:mysql://127.0.0.1:3306/demo_replica_ds_1?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 3000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
#
#rules:
#- !DB_DISCOVERY
# dataSources:
# pr_ds:
# dataSourceNames:
# - ds_0
# - ds_1
# - ds_2
# discoveryTypeName: mgr
# discoveryTypes:
# mgr:
# type: MGR
# props:
# groupName: 92504d5b-6dec-11e8-91ea-246e9612aaf1
# zkServerLists: 'localhost:2181'
# keepAliveCron: '0/5 * * * * ?'
113 changes: 113 additions & 0 deletions sharding-proxy/conf/config-encrypt.yaml
@@ -0,0 +1,113 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# 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.
#

######################################################################################################
#
# Here you can configure the rules for the proxy.
# This example is configuration of encrypt rule.
#
######################################################################################################
#
#schemaName: encrypt_db
#
#dataSources:
# ds_0:
# url: jdbc:postgresql://127.0.0.1:5432/demo_ds_0
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# ds_1:
# url: jdbc:postgresql://127.0.0.1:5432/demo_ds_1
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
#
#rules:
#- !ENCRYPT
# encryptors:
# aes_encryptor:
# type: AES
# props:
# aes-key-value: 123456abc
# md5_encryptor:
# type: MD5
# tables:
# t_encrypt:
# columns:
# user_id:
# plainColumn: user_plain
# cipherColumn: user_cipher
# encryptorName: aes_encryptor
# order_id:
# cipherColumn: order_encrypt
# encryptorName: md5_encryptor

######################################################################################################
#
# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.
#
######################################################################################################
#
#schemaName: encrypt_db
#
#dataSources:
# ds_0:
# url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# ds_1:
# url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
#
#rules:
#- !ENCRYPT
# encryptors:
# aes_encryptor:
# type: AES
# props:
# aes-key-value: 123456abc
# md5_encryptor:
# type: MD5
# tables:
# t_encrypt:
# columns:
# user_id:
# plainColumn: user_plain
# cipherColumn: user_cipher
# encryptorName: aes_encryptor
# order_id:
# cipherColumn: order_cipher
# encryptorName: md5_encryptor
109 changes: 109 additions & 0 deletions sharding-proxy/conf/config-readwrite-splitting.yaml
@@ -0,0 +1,109 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# 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.
#

######################################################################################################
#
# Here you can configure the rules for the proxy.
# This example is configuration of replica-query rule.
#
######################################################################################################
#
#schemaName: readwrite_splitting_db
#
#dataSources:
# primary_ds:
# url: jdbc:postgresql://127.0.0.1:5432/demo_primary_ds
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# replica_ds_0:
# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_0
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# replica_ds_1:
# url: jdbc:postgresql://127.0.0.1:5432/demo_replica_ds_1
# username: postgres
# password: postgres
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
#
#rules:
#- !READWRITE_SPLITTING
# dataSources:
# pr_ds:
# writeDataSourceName: primary_ds
# readDataSourceNames:
# - replica_ds_0
# - replica_ds_1

######################################################################################################
#
# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.
#
######################################################################################################

#schemaName: readwrite_splitting_db
#
#dataSources:
# write_ds:
# url: jdbc:mysql://127.0.0.1:3306/demo_write_ds?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# read_ds_0:
# url: jdbc:mysql://127.0.0.1:3306/demo_read_ds_0?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
# read_ds_1:
# url: jdbc:mysql://127.0.0.1:3306/demo_read_ds_1?serverTimezone=UTC&useSSL=false
# username: root
# password:
# connectionTimeoutMilliseconds: 30000
# idleTimeoutMilliseconds: 60000
# maxLifetimeMilliseconds: 1800000
# maxPoolSize: 50
# minPoolSize: 1
#
#rules:
#- !READWRITE_SPLITTING
# dataSources:
# pr_ds:
# writeDataSourceName: write_ds
# readDataSourceNames:
# - read_ds_0
# - read_ds_1