Sentinel控制台整合使用以及遇到的一些问题

下载源码及jar包

sentinel官网

home | Sentinel

github地址

alibaba/Sentinel: A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)

控制台jar包
在这里插入图片描述
控制台工程代码

Sentinel/sentinel-dashboard at master · alibaba/Sentinel
在这里插入图片描述

设置配置文件

下载控制台代码工程,配置logback日志文件。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder charset="UTF-8">
            <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %p %t - %m%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${user.home}/logs/dashboardlogs/rocketmq-dashboard.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${user.home}/logs/csp/sentinel-dashboard.log-%d{yyyy-MM-dd}.%i.log
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>104857600</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <MaxHistory>10</MaxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %p %t - %m%n</pattern>
            <charset class="java.nio.charset.Charset">UTF-8</charset>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>

</configuration> 

修改应用application.properties配置文件,设置日志文件存储、应用账号密码、所占用端口号等。

#spring settings
server.servlet.encoding.force=true
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.enabled=true
server.port=8082
csp.sentinel.dashboard.server=localhost:8082
project.name=sentinel-dashboard

#cookie name setting
server.servlet.session.cookie.name=sentinel_dashboard_cookie

#logging settings
#logging.level.org.springframework.web=INFO
#logging.file.name=${user.home}/logs/csp/sentinel-dashboard.log
#logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
#logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
logging.config=classpath:logback.xml

#auth settings
auth.filter.exclude-urls=/,/auth/login,/auth/logout,/registry/machine,/version
auth.filter.exclude-url-suffixes=htm,html,js,css,map,ico,ttf,woff,png
# If auth.enabled=false, Sentinel console disable login
auth.username=sentinel
auth.password=sentinel

# Inject the dashboard version. It's required to enable
# filtering in pom.xml for this resource file.
sentinel.dashboard.version=@project.version@

打包工程遇到报错

maven:1.skip test 2.clean 3.package报错
在这里插入图片描述
报错日志

[INFO] --- compiler:3.12.0:compile (default-compile) @ sentinel-dashboard ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 111 source files with javac [debug release 17] to target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.443 s
[INFO] Finished at: 2025-04-23T03:09:40+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.12.0:compile (default-compile) on project sentinel-dashboard: Fatal error compiling: 无效的标记: --release -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1

maven官网介绍–release参数是jdk9及以上版本才支持的。

Apache Maven Compiler Plugin – compiler:compile
在这里插入图片描述
在这里插入图片描述
maven-compiler-plugin版本与jdk版本对应关系

Apache Maven Compiler Plugin – Plugin Documentation
在这里插入图片描述
在这里插入图片描述
org.apache.maven.plugins:maven-compiler-plugin:3.12.0 最低要求 jdk8 版本。

sentinel-dashboard父工程要求jdk版本为17
在这里插入图片描述
将Project Structure的语言等级改成jdk17,Java Compiler版本改成17,maven importing改成jdk17,maven runner改成jdk17。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
maven clean成功
在这里插入图片描述
maven package成功
在这里插入图片描述
项目工程中jdk、maven的jdk版本应与pom.xml中jdk编译版本一致。

启动sentinel控制台应用

上传jar包至服务器上
在这里插入图片描述
运行jar包需要配置jdk8及以上环境

后台不挂起运行控制台程序,并且linux系统不输出任何日志,由配置的logback来记录日志。

nohup java -jar sentinel-dashboard.jar > /dev/null 2>&1 &

执行jps -l查看运行的java程序及其所占用端口号

jps -l

在这里插入图片描述

回到logback所记录日志文件夹,查看sentinel-dashboard日志记录情况
在这里插入图片描述
访问sentinel-dashboard应用
在这里插入图片描述
输入默认用户名密码sentinel登入
在这里插入图片描述
配置文件application-ext.yml文件

微服务设置sentinel相关配置,设置sentinel为急加载。

spring:
  cloud:
    # openfeign配置
    openfeign:
      client:
        config:
          # 默认FeignClient配置
          default:
            loggerLevel: full
            connectTimeout: 9000
            readTimeout: 55000
          # ProductFeignClient配置 有指定的feignClient就用指定,没有的用默认
          service-product:
            # 日志级别全记录
            loggerLevel: full
            # 连接超时时间 毫秒为单位
            connectTimeout: 5000
            # 读取超时时间
            readTimeout: 8000
    # sentinel配置
    sentinel:
      transport:
        # sentinel控制台所在地址
        dashboard: 192.168.1.103:8082
      # 取消默认懒加载
      eager: true

# feign客户端开启sentinel熔断
feign:
  sentinel:
    enabled: true

重启微服务后,进入sentinel控制台应用。
在这里插入图片描述

簇点链路

发送了三个请求,取簇点链路查看资源请求。
在这里插入图片描述

流控规则

对service-order服务的/order/create资源创建流控规则
在这里插入图片描述
每秒只给/order/create放行1个请求
在这里插入图片描述
在这里插入图片描述
快速刷新/order/create请求,返回了默认错误
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值