当前位置: 首页 > news >正文

用服务器ip做网站seo思维

用服务器ip做网站,seo思维,网页qq登录保护功能怎么关闭,wordpress匿名评论插件前言 Apache ShardingSphere 是一款分布式的数据库生态系统, 可以将任意数据库转换为分布式数据库,并通过数据分片、弹性伸缩、加密等能力对原有数据库进行增强。 Apache ShardingSphere 设计哲学为 Database Plus,旨在构建异构数据库上层的…

前言

Apache ShardingSphere 是一款分布式的数据库生态系统, 可以将任意数据库转换为分布式数据库,并通过数据分片、弹性伸缩、加密等能力对原有数据库进行增强。

Apache ShardingSphere 设计哲学为 Database Plus,旨在构建异构数据库上层的标准和生态。 它关注如何充分合理地利用数据库的计算和存储能力,而并非实现一个全新的数据库。 它站在数据库的上层视角,关注它们之间的协作多于数据库自身。

1、ShardingSphere-JDBC

ShardingSphere-JDBC 定位为轻量级 Java 框架,在 Java 的 JDBC 层提供的额外服务。

1.1、应用场景

Apache ShardingSphere-JDBC 可以通过Java 和 YAML 这 2 种方式进行配置,开发者可根据场景选择适合的配置方式。

  • 数据库读写分离
  • 数据库分表分库

1.2、原理

  • Sharding-JDBC中的路由结果是通过分片字段和分片方法来确定的,如果查询条件中有 id 字段的情况还好,查询将会落到某个具体的分片
  • 如果查询没有分片的字段,会向所有的db或者是表都会查询一遍,让后封装结果集给客户端。
    在这里插入图片描述

1.3、spring boot整合

1.3.1、添加依赖

<!-- 分表分库依赖 -->
<dependency><groupId>org.apache.shardingsphere</groupId><artifactId>sharding-jdbc-spring-boot-starter</artifactId><version>4.1.1</version>
</dependency>

1.3.2、添加配置

spring:main:# 一个实体类对应多张表,覆盖allow-bean-definition-overriding: trueshardingsphere:datasource:ds0:#配置数据源具体内容,包含连接池,驱动,地址,用户名和密码driver-class-name: com.mysql.cj.jdbc.Driverjdbc-url: jdbc:mysql://127.0.0.1:3306/account?autoReconnect=true&allowMultiQueries=truepassword: roottype: com.zaxxer.hikari.HikariDataSourceusername: rootds1:driver-class-name: com.mysql.cj.jdbc.Driverjdbc-url: jdbc:mysql://127.0.0.1:3306/account?autoReconnect=true&allowMultiQueries=truepassword: roottype: com.zaxxer.hikari.HikariDataSourceusername: root# 配置数据源,给数据源起名称names: ds0,ds1props:sql:show: truesharding:tables:user_info:#指定 user_info 表分布情况,配置表在哪个数据库里面,表名称都是什么actual-data-nodes: ds0.user_info_${0..9}database-strategy:standard:preciseAlgorithmClassName: com.xxxx.store.account.config.PreciseDBShardingAlgorithmrangeAlgorithmClassName: com.xxxx.store.account.config.RangeDBShardingAlgorithmsharding-column: idtable-strategy:standard:preciseAlgorithmClassName: com.xxxx.store.account.config.PreciseTablesShardingAlgorithmrangeAlgorithmClassName: com.xxxx.store.account.config.RangeTablesShardingAlgorithmsharding-column: id

1.3.3、制定分片算法

1.3.3.1、精确分库算法

/*** 精确分库算法*/
public class PreciseDBShardingAlgorithm implements PreciseShardingAlgorithm<Long> {/**** @param availableTargetNames 配置所有的列表* @param preciseShardingValue 分片值* @return*/@Overridepublic String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> preciseShardingValue) {Long value = preciseShardingValue.getValue();//后缀 0,1String postfix = String.valueOf(value % 2);for (String availableTargetName : availableTargetNames) {if(availableTargetName.endsWith(postfix)){return availableTargetName;}}throw new UnsupportedOperationException();}}

1.3.3.2、范围分库算法

/*** 范围分库算法*/
public class RangeDBShardingAlgorithm implements RangeShardingAlgorithm<Long> {@Overridepublic Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {return collection;}
}

1.3.3.3、精确分表算法

/*** 精确分表算法*/
public class PreciseTablesShardingAlgorithm implements PreciseShardingAlgorithm<Long> {/**** @param availableTargetNames 配置所有的列表* @param preciseShardingValue 分片值* @return*/@Overridepublic String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> preciseShardingValue) {Long value = preciseShardingValue.getValue();//后缀String postfix = String.valueOf(value % 10);for (String availableTargetName : availableTargetNames) {if(availableTargetName.endsWith(postfix)){return availableTargetName;}}throw new UnsupportedOperationException();}}

1.3.3.4、范围分表算法

/*** 范围分表算法*/
public class RangeTablesShardingAlgorithm implements RangeShardingAlgorithm<Long> {@Overridepublic Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {Collection<String> result = new ArrayList<>();Range<Long> valueRange = rangeShardingValue.getValueRange();Long start = valueRange.lowerEndpoint();Long end = valueRange.upperEndpoint();Long min = start % 10;Long max = end % 10;for (Long i = min; i < max +1; i++) {Long finalI = i;collection.forEach(e -> {if(e.endsWith(String.valueOf(finalI))){result.add(e);}});}return result;}}

1.3.4、数据库建表

DROP TABLE IF EXISTS `user_info_0`;
CREATE TABLE `user_info_0` (`id` bigint(20) NOT NULL,`account` varchar(255) DEFAULT NULL,`user_name` varchar(255) DEFAULT NULL,`pwd` varchar(255) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

1.3.5、业务应用

1.3.5.1、定义实体类

@Data
@TableName(value = "user_info")
public class UserInfo {/*** 主键*/private Long id;/*** 账号*/private String account;/*** 用户名*/private String userName;/*** 密码*/private String pwd;}

1.3.5.2、定义接口

public interface UserInfoService{/*** 保存* @param userInfo* @return*/public UserInfo saveUserInfo(UserInfo userInfo);public UserInfo getUserInfoById(Long id);public List<UserInfo> listUserInfo();
}

1.3.5.3、实现类

@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {@Override@Transactionalpublic UserInfo saveUserInfo(UserInfo userInfo) {userInfo.setId(IdUtils.getId());this.save(userInfo);return userInfo;}@Overridepublic UserInfo getUserInfoById(Long id) {return this.getById(id);}@Overridepublic List<UserInfo> listUserInfo() {QueryWrapper<UserInfo> userInfoQueryWrapper = new QueryWrapper<>();userInfoQueryWrapper.between("id",1623695688380448768L,1623695688380448769L);return this.list(userInfoQueryWrapper);}
}

1.3.6、生成ID - 雪花算法

package com.xxxx.tore.common.utils;import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;/*** 生成各种组件ID*/
public class IdUtils {/*** 雪花算法* @return*/public static long getId(){Snowflake snowflake = IdUtil.getSnowflake(0, 0);long id = snowflake.nextId();return id;}
}

1.4、seata与sharding-jdbc整合

https://github.com/seata/seata-samples/tree/master/springcloud-seata-sharding-jdbc-mybatis-plus-samples

1.4.1、common中添加依赖

<!--seata依赖-->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-seata</artifactId><version>2021.0.4.0</version>
</dependency>
<!-- sharding-jdbc整合seata分布式事务-->
<dependency><groupId>org.apache.shardingsphere</groupId><artifactId>sharding-transaction-base-seata-at</artifactId><version>4.1.1</version>
</dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId><version>2021.0.4.0</version><exclusions><exclusion><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId></exclusion></exclusions>
</dependency>
<dependency><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId><version>1.4.2</version>
</dependency>

1.4.2、改造account-service服务

@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {@Autowiredprivate OrderService orderService;@Autowiredprivate StorageService storageService;/*** 存放商品编码及其对应的价钱*/private static Map<String,Integer> map = new HashMap<>();static {map.put("c001",3);map.put("c002",5);map.put("c003",10);map.put("c004",6);}@Override@Transactional@ShardingTransactionType(TransactionType.BASE)public void debit(OrderDTO orderDTO) {//扣减账户余额int calculate = this.calculate(orderDTO.getCommodityCode(), orderDTO.getCount());AccountDTO accountDTO = new AccountDTO(orderDTO.getUserId(), calculate);QueryWrapper<Account> objectQueryWrapper = new QueryWrapper<>();objectQueryWrapper.eq("id",1);objectQueryWrapper.eq(accountDTO.getUserId() != null,"user_id",accountDTO.getUserId());Account account = this.getOne(objectQueryWrapper);account.setMoney(account.getMoney() - accountDTO.getMoney());this.saveOrUpdate(account);//扣减库存this.storageService.deduct(new StorageDTO(null,orderDTO.getCommodityCode(),orderDTO.getCount()));//生成订单this.orderService.create(orderDTO);      }/*** 计算购买商品的总价钱* @param commodityCode* @param orderCount* @return*/private int calculate(String commodityCode, int orderCount){//商品价钱Integer price = map.get(commodityCode) == null ? 0 : map.get(commodityCode);return price * orderCount;}
}

注意:调单生成调用的逻辑修改,减余额->减库存->生成订单。调用入口方法注解加上:@ShardingTransactionType(TransactionType.BASE)

1.4.3、修改business-service服务

@Service
public class BusinessServiceImpl implements BusinessService {@Autowiredprivate OrderService orderService;@Autowiredprivate StorageService storageService;@Autowiredprivate AccountService accountService;@Overridepublic void purchase(OrderDTO orderDTO) {//扣减账号中的钱accountService.debit(orderDTO);        }
}

1.4.4、修改order-service服务

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements OrderService {/*** 存放商品编码及其对应的价钱*/private static Map<String,Integer> map = new HashMap<>();static {map.put("c001",3);map.put("c002",5);map.put("c003",10);map.put("c004",6);}@Override@Transactional@ShardingTransactionType(TransactionType.BASE)public Order create(String userId, String commodityCode, int orderCount) {int orderMoney = calculate(commodityCode, orderCount);Order order = new Order();order.setUserId(userId);order.setCommodityCode(commodityCode);order.setCount(orderCount);order.setMoney(orderMoney);//保存订单this.save(order);try {TimeUnit.SECONDS.sleep(30);} catch (InterruptedException e) {e.printStackTrace();}if(true){throw new RuntimeException("回滚测试");}return order;}/*** 计算购买商品的总价钱* @param commodityCode* @param orderCount* @return*/private int calculate(String commodityCode, int orderCount){//商品价钱Integer price = map.get(commodityCode) == null ? 0 : map.get(commodityCode);return price * orderCount;}
}

1.4.5、配置文件参考

server:port: 8090spring:main:# 一个实体类对应多张表,覆盖allow-bean-definition-overriding: trueshardingsphere:datasource:ds0:#配置数据源具体内容,包含连接池,驱动,地址,用户名和密码driver-class-name: com.mysql.cj.jdbc.Driverjdbc-url: jdbc:mysql://127.0.0.1:3306/account?autoReconnect=true&allowMultiQueries=truepassword: roottype: com.zaxxer.hikari.HikariDataSourceusername: rootds1:driver-class-name: com.mysql.cj.jdbc.Driverjdbc-url: jdbc:mysql://127.0.0.1:3306/account?autoReconnect=true&allowMultiQueries=truepassword: roottype: com.zaxxer.hikari.HikariDataSourceusername: root# 配置数据源,给数据源起名称names: ds0,ds1props:sql:show: truesharding:tables:account_tbl:actual-data-nodes: ds0.account_tbl_${0..1}database-strategy:standard:preciseAlgorithmClassName: com.xxxx.store.account.config.PreciseDBExtShardingAlgorithm#rangeAlgorithmClassName: com.xxxx.store.account.config.RangeDBShardingAlgorithmsharding-column: idtable-strategy:standard:preciseAlgorithmClassName: com.xxxx.store.account.config.PreciseTablesExtShardingAlgorithm#rangeAlgorithmClassName: com.xxxx.store.account.config.RangeTablesShardingAlgorithmsharding-column: iduser_info:#指定 user_info 表分布情况,配置表在哪个数据库里面,表名称都是什么actual-data-nodes: ds0.user_info_${0..9}database-strategy:standard:preciseAlgorithmClassName: com.xxxx.store.account.config.PreciseDBShardingAlgorithmrangeAlgorithmClassName: com.xxxx.store.account.config.RangeDBShardingAlgorithmsharding-column: idtable-strategy:standard:preciseAlgorithmClassName: com.xxxx.store.account.config.PreciseTablesShardingAlgorithmrangeAlgorithmClassName: com.xxxx.store.account.config.RangeTablesShardingAlgorithmsharding-column: id#以上是sharding-jdbc配置cloud:nacos:discovery:server-addr: localhost:8848namespace: 1ff3782d-b62d-402f-8bc4-ebcf40254d0aapplication:name: account-service  #微服务名称
#  datasource:
#    username: root
#    password: root
#    url: jdbc:mysql://127.0.0.1:3306/account
#    driver-class-name: com.mysql.cj.jdbc.Driverseata:enabled: trueenable-auto-data-source-proxy: falseapplication-id: account-servicetx-service-group: default_tx_groupservice:vgroup-mapping:default_tx_group: defaultdisable-global-transaction: falseregistry:type: nacosnacos:application: seata-serverserver-addr: 127.0.0.1:8848namespace: 1ff3782d-b62d-402f-8bc4-ebcf40254d0agroup: SEATA_GROUPusername: nacospassword: nacosconfig:nacos:server-addr: 127.0.0.1:8848namespace: 1ff3782d-b62d-402f-8bc4-ebcf40254d0agroup: SEATA_GROUPusername: nacospassword: nacos

文章转载自:
http://dinncomythologem.stkw.cn
http://dinncodevolatilization.stkw.cn
http://dinncoaesthetician.stkw.cn
http://dinncoillfare.stkw.cn
http://dinncoovereaten.stkw.cn
http://dinncoambassadorship.stkw.cn
http://dinncostereotype.stkw.cn
http://dinncorefectioner.stkw.cn
http://dinncoleukemic.stkw.cn
http://dinncoobligor.stkw.cn
http://dinncotrillion.stkw.cn
http://dinncoprocambium.stkw.cn
http://dinncoconfluent.stkw.cn
http://dinncomugho.stkw.cn
http://dinncodiomedes.stkw.cn
http://dinncohempy.stkw.cn
http://dinncosubstantive.stkw.cn
http://dinncogentlehood.stkw.cn
http://dinncofascisti.stkw.cn
http://dinncofritting.stkw.cn
http://dinncodubitation.stkw.cn
http://dinncounscrupulously.stkw.cn
http://dinncoosmoregulatory.stkw.cn
http://dinncolandscape.stkw.cn
http://dinncocursing.stkw.cn
http://dinncocontinentality.stkw.cn
http://dinncogreenpeace.stkw.cn
http://dinncorockslide.stkw.cn
http://dinncofederal.stkw.cn
http://dinncocrotchet.stkw.cn
http://dinncokibbutznik.stkw.cn
http://dinncodiabetologist.stkw.cn
http://dinncodixie.stkw.cn
http://dinncodeflection.stkw.cn
http://dinncobaruch.stkw.cn
http://dinncosuspirious.stkw.cn
http://dinncoamatory.stkw.cn
http://dinncoloo.stkw.cn
http://dinncoblacklist.stkw.cn
http://dinncohemorrhage.stkw.cn
http://dinncoantianginal.stkw.cn
http://dinncobiramose.stkw.cn
http://dinncotritoma.stkw.cn
http://dinncojadotville.stkw.cn
http://dinncohauler.stkw.cn
http://dinncounordinary.stkw.cn
http://dinncosapiential.stkw.cn
http://dinncoimproperly.stkw.cn
http://dinncouncap.stkw.cn
http://dinnconegligent.stkw.cn
http://dinncotracheotomy.stkw.cn
http://dinncofining.stkw.cn
http://dinncoarchaeozoic.stkw.cn
http://dinncohaircurling.stkw.cn
http://dinncoportuguese.stkw.cn
http://dinncoincoherency.stkw.cn
http://dinncosixain.stkw.cn
http://dinncoimmanuel.stkw.cn
http://dinncoalmanack.stkw.cn
http://dinncoodontoblast.stkw.cn
http://dinncopuppet.stkw.cn
http://dinncoequip.stkw.cn
http://dinncomalachi.stkw.cn
http://dinncorhodinal.stkw.cn
http://dinncodiscomfiture.stkw.cn
http://dinncosloughy.stkw.cn
http://dinncodownless.stkw.cn
http://dinncochecker.stkw.cn
http://dinncostamping.stkw.cn
http://dinncoelectrocution.stkw.cn
http://dinnconigaragua.stkw.cn
http://dinncovervain.stkw.cn
http://dinncogross.stkw.cn
http://dinncoepimer.stkw.cn
http://dinncoimplead.stkw.cn
http://dinncobrotherliness.stkw.cn
http://dinncoshirker.stkw.cn
http://dinncorecuperator.stkw.cn
http://dinncolimaceous.stkw.cn
http://dinncocrossover.stkw.cn
http://dinncotransmutability.stkw.cn
http://dinncoincubous.stkw.cn
http://dinncocountable.stkw.cn
http://dinncocrunchy.stkw.cn
http://dinncoabsolutism.stkw.cn
http://dinncojovian.stkw.cn
http://dinncooversleep.stkw.cn
http://dinncoplicate.stkw.cn
http://dinncooptician.stkw.cn
http://dinncoteacupful.stkw.cn
http://dinncoirregularity.stkw.cn
http://dinncoracecourse.stkw.cn
http://dinncodreary.stkw.cn
http://dinncotehsil.stkw.cn
http://dinncodeepen.stkw.cn
http://dinncoradcm.stkw.cn
http://dinncochildbearing.stkw.cn
http://dinncofrigate.stkw.cn
http://dinncofloridly.stkw.cn
http://dinncoconey.stkw.cn
http://www.dinnco.com/news/127519.html

相关文章:

  • 点击最多的网站百度推广网址是多少
  • 一个公司做几个网站免费建立个人网站申请
  • 怎么添加网站程序企业培训内容有哪些
  • 无锡专业做网站的公司哪家好yandere搜索引擎入口
  • 银川微信网站制作草根seo视频大全网站
  • 建立网站有怎么用途加强服务保障满足群众急需ruu7
  • 长沙网站制作好公司职业技能培训网
  • 做seo网站空间十五种常见的销售策略
  • 东莞哪里建设网站好美国疫情最新数据消息
  • 南宁本地网站有哪些广东免费网络推广软件
  • 西安的网站制作公司用手机制作自己的网站
  • 重庆企业网站制作外包上海十大公关公司排名
  • 宜昌做网站要什么条件百度怎么发布短视频
  • wordpress移动端底部导航栏seo网站推广费用
  • 手机网站建设规划书企业网站系统
  • 日本一级做a在线播放免费视频网站西安百度搜索排名
  • 一个网站做seo跟我学seo从入门到精通
  • laravel网站开发步骤青岛seo排名公司
  • 做网站优化的价格优化大师官网下载
  • 福清哪有做网站的地方网上接单平台
  • 网络绿化网站建设哪家权威软文接单平台
  • 上海网站营销微商软文范例大全100
  • 网站推广的目的是什网络营销方法有哪几种
  • 临沂建设局网站官网日结app推广联盟
  • 做网站策划用什么软件磁力帝
  • 联通网站备案系统郑州百度推广seo
  • 找钢网网站建设友情链接获取的途径有哪些
  • 做那个网站百度推广关键词和创意
  • 网站建设怎样把网页连接起来免费广告投放网站
  • 做类似电影天堂的网站违法吗想要网站推广页