zoukankan      html  css  js  c++  java
  • Sentinel简单使用

    1、下载使用

    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

    2、maven方式

    加入依赖管理和依赖

     <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
    

    启动类

    @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 jar包,然后再启动上面这个启动类

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

    原文链接:https://blog.csdn.net/qq_41813208/article/details/106994203

  • 相关阅读:
    windows10 + anaconda + tensorflow-1.5.0 + python-3.6 + keras-2.2.4配置和安装
    k-center问题-学习
    交换机+路由器 网络口连接桥接关系示意
    用scp命令来通过ssh传输文件,ssh推送.py程序到CentOS7服务器端出现lost connection错误
    codevs 1519 过路费 最小生成树+倍增
    10.18 noip模拟试题
    poj 3565 ants
    [国家集训队2011]种树 (神贪心~~)
    poj 1821 Fence 单调队列优化dp
    SPFA 小优化*2
  • 原文地址:https://www.cnblogs.com/ljstudy/p/14484671.html
Copyright © 2011-2022 走看看