Sentinel

suaxi
2021-04-29 / 0 评论 / 203 阅读 / 正在检测是否收录...

一、安装

1、下载

sentinel地址:https://github.com/alibaba/Sentinel

2、运行

java -jar sentinel-dashboard-1.8.1.jar

3、注意事项

sentinel默认8080端口,需注意端口冲突的问题

二、微服务整合Sentinel

1、启动Nacos

windows环境或Linux环境下启动startup.cmdstartup.sh

2、新建Sentinel8401模块

pom
<!-- API 通用pom根据自己情况而定-->
<dependency>
    <groupId>com.sw</groupId>
    <artifactId>cloud-api-commons</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

<!-- Nacos -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

<!-- sentinel -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

<!-- openfign -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

<!-- lombok -->
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>


yml
server:
  port: 8401

spring:
  application:
    name: cloud-alibaba-sentinel-service
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
    sentinel:
      transport:
        # sentinel dashboard地址
        dashboard: localhost:8080
        # 默认8719端口,如果8719被占用,默认递增
        port: 8719

management:
  endpoints:
    web:
      exposure:
        include: '*'


启动类
@SpringBootApplication
@EnableDiscoveryClient
public class MainApp8401 {
    public static void main(String[] args) {
        SpringApplication.run(MainApp8401.class, args);
    }
}


controller
@Slf4j
@RestController
public class FlowLimitController {

    @GetMapping("/testa")
    public String testA() {
        return "-----testA------";
    }

    @GetMapping("/testb")
    public String testB() {
        log.info(Thread.currentThread().getName() + "\t" + "处理了/testb请求!");
        return "-----testB------";
    }
}


3、启动测试

Sentinel默认的账号密码都是sentinel

因为sentinel是懒加载机制,所以需先完成一次请求,才能在sentinel控制面板看到簇点链路


1.启动测试.png

0

评论 (0)

取消