nacos_sentinel_seata

 

----------------------------------------------------------------------------------------
###################  spring cloud alibaba nacos #########################################
http://localhost:8848/nacos
复制端口步骤
copy configuration
name: 9011
vm options: -DServer.port=9011

http://localhost:9001/payment/nacos/1
http://localhost:9011/payment/nacos/1
http://localhost:83/consumer/payment/nacos/11
#切换成CP模式
curl -X PUT '$NACOS_SERVER:8848/nacos/v1/ns/operator/switches?entry=serverMode&value=CP'

# ${spring.application.name}-${spring.profile.active}.${spring.cloud.nacos.config.file-extension}
# nacos-config-client-dev.yaml

http://localhost:3377/config/info

默认情况:Name    space=public,Group=DEFAULT_GROUP,默认Cluster是DEFAULT。

nacos-server-1.1.4
新建nacos_config数据库,脚本在对应config目录下。

application.properties增加内容:

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root

修改cluster.conf文档
192.168.0.211:3333
192.168.0.211:4444
192.168.0.211:5555

命令: ./startup.sh -p 3333

修改startup.sh
while getopts ":m:f:s:c:p:" opt
        p)
            #EMBEDDED_STORAGE=$OPTARG;;
            PORT=$OPTARG;;
nohup "$JAVA" -Dserver.port=${PORT}


修改nginx对应配置
/usr/local/nginx/conf/nginx.conf
新版不一样(可能是指定安装位置的)。

配置文件位置
主配置文件:/etc/nginx/nginx.conf
虚拟主机配置:/etc/nginx/conf.d/目录下的 .conf文件

修改/etc/nginx/conf.d/default.conf文档
upstream cluster{
    server 127.0.0.1:3333;
    server 127.0.0.1:4444;
    server 127.0.0.1:5555;
}
server{
    listen        1111;
    server_name   localhost; 
    location / {
        #root   /usr/share/nginx/html;
        #index  index.html index.htm;
        proxy_pass http://cluster;
    }

}

/usr/local/nginx/sbin目录下运行下面一行
./nginx -C /usr/local/nginx/conf/nginx.conf


ps -ef |grep nacos |grep -v grep |wc -l

----------------------------------------------------------------------------------------

 

 

----------------------------------------------------------------------------------------
###################  spring cloud alibaba sentinel #########################################

http://localhost:8080/
http://localhost:8848/nacos

sentinel懒加载,得至少访问下面一次。
http://localhost:8401/testA
http://localhost:8401/testB
http://localhost:8401/testHotKey
http://localhost:8401/testHotKey?p1=a&p2=b
http://localhost:8401/byResource
http://localhost:8401/rateLimit/customerBlockHandler


http://localhost:9003/paymentSQL/1
http://localhost:9004/paymentSQL/1
http://localhost:84/consumer/fallback/1
http://localhost:84/consumer/paymentSQL/1

http://localhost:8401/rateLimit/byUrl
sentinel-datasource-nacos ,sentinel做持久化
添加Nacos业务规则配置----->
配置管理----->
新建配置(DataID:cloudalibaba-sentinel-service)
json格式:
[
  {
    "resource":"/rateLimit/byUrl",
    "limitApp":"default",
    "grade":1,
    "count":1,
    "strategy":0,
    "controlBehavior":0,
    "clusterMode":false
   }
]
resource:资源名称;
limitApp:来源应用;
grade:阈值类型:0线程数,1QPS
count: 单机阈值;
strategy:流控模式,0直接,1关联,2链路
controlBehavior:流控效果,0快速失败,1warmUp,2排队等待
clusterMode:是否集群
----------------------------------------------------------------------------------------

 

 

----------------------------------------------------------------------------------------
###################  spring cloud alibaba seata #########################################
file.conf文档

service模块
service{
    vgroup_mapping.my_test_tx_group = "fsp_tx_group"
    default.grouplist = "127.0.0.1:8091"
    enableDegrade = false
    disable = false
    max.commit.retry.timeout = "-1"
    max.rollback.retry.timeout = "-1"
}
store{
    mode= "db"

    db{
        url = "jdbc:mysql://127.0.0.1:3306/seata"
        user = "root"
        password = "root"
    }
}

registry.conf配置文档
registry{

    type = "nacos"
    nacos{
        serverAddr = "localhost:8848"
        namespace = ""
        cluster = "default"
    }
}

create database seata_order;
create database seata_storage;
create database seata_account;


CREATE TABLE `t_order`  (
  `id` bigint(11) NOT NULL,
  `user_id` bigint(11) NULL DEFAULT NULL COMMENT '用户id',
  `product_id` bigint(11) NULL DEFAULT NULL COMMENT '产品id',
  `count` int(11) NULL DEFAULT NULL COMMENT '数量',
  `money` decimal(11, 0) NULL DEFAULT NULL COMMENT '金额',
  `status` int(1) NULL DEFAULT NULL COMMENT '订单状态:0:创建中,1:已完结',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

CREATE TABLE `t_storage`  (
  `id` bigint(11) NOT NULL,
  `product_id` bigint(11) NULL DEFAULT NULL COMMENT '产品id',
  `total` int(11) NULL DEFAULT NULL COMMENT '总库存',
  `used` int(11) NULL DEFAULT NULL COMMENT '已用库存',
  `residue` int(11) NULL DEFAULT NULL COMMENT '剩余库存',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

insert into seata_storage.t_storage(id,product_id,total,used,residue)
VALUES('1','1','100','0','100');



CREATE TABLE `t_account`  (
  `id` bigint(11) NOT NULL,
  `user_id` bigint(11) NULL DEFAULT NULL COMMENT '用户id',
  `total` int(11) NULL DEFAULT NULL COMMENT '总额度',
  `used` int(11) NULL DEFAULT NULL COMMENT '已用余额',
  `residue` int(11) NULL DEFAULT NULL COMMENT '剩余可用额度',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

insert into seata_account.t_account(id,user_id,total,used,residue)
VALUES('1','1','1000','0','1000');

三个数据库新建三个各自的回滚日志表
CREATE TABLE `undo_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `context` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int(11) NOT NULL,
  `log_created` datetime NOT NULL,
  `log_modified` datetime NOT NULL,
  `ext` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `ux_undo_log`(`xid`, `branch_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

http://localhost:2001/order/create?userId=1&productId=1&count=10&money=100

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
application.yml

server:
  port: 2001

spring:
  application:
    name: seata-order-service
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848         #Nacos服务注册中心地址
  # ==========applicationName + druid-mysql8 driver===================
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/seata_order?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
    username: root
    password: root
# ========================mybatis===================
mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.ye.entities
  configuration:
    map-underscore-to-camel-case: true

# ========================seata===================
seata:
  registry:
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      namespace: ""
      group: SEATA_GROUP
      application: seata-server
  tx-service-group: default_tx_group # 事务组,由它获得TC服务的集群名称
  service:
    vgroup-mapping: # 点击源码分析
      default_tx_group: default # 事务组与TC服务集群的映射关系
  data-source-proxy-mode: AT

logging:
  level:
    io:
      seata: info








----------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2025-12-13 07:36  yebinghuai-qq-com  阅读(2)  评论(0)    收藏  举报

导航