Sentinel下载和使用,java -jar jar包 --server.port=自定义端口

sentinel官网
下载sentinel地址:https://github.com/alibaba/Sentinel/releases
下载 sentinel-dashboard-1.7.2.jar
在这里插入图片描述
通过java -jar启动sentinel ,默认sentinel占用的端口是8080 --server.port=8888是将端口设置为8888,如果有改端口需求则更改对应端口即可

java  -jar .\sentinel-dashboard-1.7.2.jar --server.port=8888

用户和密码都是sentinel
在这里插入图片描述
加入依赖管理

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

加入依赖

<!--   spring-cloud-starter-alibaba-nacos-discovery  nacos服务注册中心   -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

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

<!-- sentinel-datasource-nacos sentinel持久化数据 -->
<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-datasource-nacos</artifactId>
</dependency>

注意自己修改端口等对应的信息,在这里sentinel使用来自定义的8888端口

server:
  port: 8400
spring:
  application:
    name: sentinel-client  #应用名
  cloud:
    nacos:
      discovery: #服务注册中心地址
        server-addr: 127.0.0.1:8848
      config:  #nacos的配置中心地址,如果不需要用到则暂时注释掉
        server-addr: 127.0.0.1:8848
        file-extension: yml
    sentinel:
      transport:
        dashboard: 127.0.0.1:8888
        port: 8719

启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

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

需要流控的Controller类,示例代码

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SentinelDemoController {

    @GetMapping("/test001")
    public String test001(){
        return "test001";
    }

    @GetMapping("/test002")
    public String test002() {
        return "test002";
    }
    
}

启动nacos,启动sentinel,然后再启动上面这个启动类

需要注意的是sentinel是懒加载的机制,也意味着需要访问一下上面Controller中的 /test001 才会在sentinel后台看到服务
浏览器访问一下 http://localhost:8400/test001
然后刷新一下sentinel后台 http://localhost:8080/#/dashboard/home
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

诗水人间

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值