网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要体系化学习资料的朋友,可以加我V获取:vip204888 (备注网络安全)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
- ShardingSphere-JDBC 是一个 Jar 包,底层通过重写 JDBC 组件完成 SQL 解析、路由、改写、执行等流程;需要在项目中添加对应功能的配置文件,对应用有一定侵入性;
- ShardingSphere-Proxy 是一个进程服务,大部分情况下定位为辅助开发运维的效率工具。它将自己伪装为数据库,应用对接后对代码是无侵入的;对 SQL 的执行逻辑同 ShardingSphere-JDBC 一致,两者复用同一内核;
- 应用通过 ShardingSphere-JDBC 是直接操作数据库,相当于只有一次网络 IO;而应用连接 ShardingSphere-Proxy 是一次网络 IO,ShardingSphere-Proxy 再操作数据库,又会发生一次网络 IO;
- ShardingSphere-JDBC 适用于 Java 开发的高性能的轻量级 OLTP 应用,ShardingSphere-Proxy 适用于 OLAP 应用以及对分片数据库进行管理和运维的场景。
三. Sharding-Proxy应用
3.1 数据分片SQL
如下sql是对t_order的分片,一共分为两片分别是t_order_0 、t_order_1
`CREATE DATABASE /*!32312 IF NOT EXISTS*/db_0 /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */;`
`USE db_0;``DROP TABLE IF EXISTS t_order_0;``CREATE TABLE t_order_0 (` `oid VARCHAR(100) COLLATE utf8_bin NOT NULL COMMENT '订单号(主键)',` `money DOUBLE DEFAULT NULL COMMENT '支付金额',` `status INT(11) DEFAULT NULL COMMENT '状态0,未支付1,已支付',` `user_id VARCHAR(100) COLLATE utf8_bin,` `PRIMARY KEY (oid)``) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;`
`DROP TABLE IF EXISTS t_order_1;``CREATE TABLE t_order_1 (` `oid VARCHAR(100) COLLATE utf8_bin NOT NULL COMMENT '订单号(主键)',` `money DOUBLE DEFAULT NULL COMMENT '支付金额',` `status INT(11) DEFAULT NULL COMMENT '状态0,未支付1,已支付',` `user_id VARCHAR(100) COLLATE utf8_bin,` `PRIMARY KEY (oid)``) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;`
3.2 Sharding-Proxy安装
前提条件:使用二进制发布包启动 Proxy,需要环境具备 Java JRE 8 或更高版本。
下载连接:https://archive.apache.org/dist/shardingsphere/4.1.1/
安装很简单,只需要解压即可。
3.3 Sharding-Proxy配置
解压安装完毕后,需要进行一些基本配置,配置信息如下:
3.3.1 服务配置
配置文件:conf/server.yaml
主要配置proxy的账户和权限
`# 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.``#`
`######################################################################################################``#` `# If you want to configure orchestration, authorization and proxy properties, please refer to this file.``#` `######################################################################################################``#``#orchestration:``# orchestration_ds:``# orchestrationType: registry_center,config_center,distributed_lock_manager``# instanceType: zookeeper``# serverLists: localhost:2181``# namespace: orchestration``# props:``# overwrite: false``# retryIntervalMilliseconds: 500``# timeToLiveSeconds: 60``# maxRetries: 3``# operationTimeoutMilliseconds: 500``#``authentication:` `users:` `root:` `password: 123` `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` `allow.range.query.with.inline.sharding: false`
3.3.2 分片配置
配置文件:conf/conf-*.yaml
主要配置分片信息,与sharding-jdbc的配置规则一模一样
`#``# If you want to connect to MySQL, you should manually copy MySQL driver to lib directory.``#``schemaName: sharding_db`
`dataSources:` `ds_0:` `url: jdbc:mysql://127.0.0.1:3306/db_0?serverTimezone=UTC&useSSL=false` `username: root` `password: 123456` `connectionTimeoutMilliseconds: 30000` `idleTimeoutMilliseconds: 60000` `maxLifetimeMilliseconds: 1800000` `maxPoolSize: 50``shardingRule:` `tables:` `t_order:` `actualDataNodes: ds_0.t_order_${0..1}` `tableStrategy:` `inline:` `shardingColumn: oid` `algorithmExpression: t_order_${oid % 2}` `defaultDatabaseStrategy:` `inline:` `shardingColumn: user_id` `algorithmExpression: ds_${user_id % 2}` `defaultTableStrategy:` `none:`
3.4 启动
启动脚本如下所示:
`bin/start.bat`
3.5 DBA运维测试
连接proxy mysql -P3307 -uroot -p123
3.6 应用测试
业务开发只需要连接proxy数据库,因为proxy已经屏蔽了分片的底层逻辑。数据源配置文件如下:
本人从事网路安全工作12年,曾在2个大厂工作过,安全服务、售后服务、售前、攻防比赛、安全讲师、销售经理等职位都做过,对这个行业了解比较全面。
最近遍览了各种网络安全类的文章,内容参差不齐,其中不伐有大佬倾力教学,也有各种不良机构浑水摸鱼,在收到几条私信,发现大家对一套完整的系统的网络安全从学习路线到学习资料,甚至是工具有着不小的需求。
最后,我将这部分内容融会贯通成了一套282G的网络安全资料包,所有类目条理清晰,知识点层层递进,需要的小伙伴可以点击下方小卡片领取哦!下面就开始进入正题,如何从一个萌新一步一步进入网络安全行业。
需要体系化学习资料的朋友,可以加我V获取:vip204888 (备注网络安全)
学习路线图
其中最为瞩目也是最为基础的就是网络安全学习路线图,这里我给大家分享一份打磨了3个月,已经更新到4.0版本的网络安全学习路线图。
相比起繁琐的文字,还是生动的视频教程更加适合零基础的同学们学习,这里也是整理了一份与上述学习路线一一对应的网络安全视频教程。
网络安全工具箱
当然,当你入门之后,仅仅是视频教程已经不能满足你的需求了,你肯定需要学习各种工具的使用以及大量的实战项目,这里也分享一份我自己整理的网络安全入门工具以及使用教程和实战。
项目实战
最后就是项目实战,这里带来的是SRC资料&HW资料,毕竟实战是检验真理的唯一标准嘛~
面试题
归根结底,我们的最终目的都是为了就业,所以这份结合了多位朋友的亲身经验打磨的面试题合集你绝对不能错过!
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!