一、sentinel 下載
啟動命令:java -Dserver.port=9090 -jar sentinel-dashboard-1.8.1.jar
這裡和只有 sentinel 時一模一樣
二、maven
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
</dependency>
三、設定檔
server:
port: 8057
spring:
application:
name: sentinel-gateway-cloud
main:
allow-bean-definition-overriding: true # 因為報錯的提示,才加的
cloud:
sentinel:
transport:
port: 8719
dashboard: localhost:9090 #對應 sentinel 的 port
eager: true
nacos:
discovery:
server-addr: 127.0.0.1:8848
gateway:
routes:
- id: sentinel_gateway_bruce
uri: lb://provider-cloud
predicates:
- Path=/xxx/**
filters:
- StripPrefix=1
※以上可以寫在 application.yml 或 nacos 之類的伺服器上
四、啟動
啟動專案時要加上 VM 參數 -Dcsp.sentinel.app.type=1
左邊是整合後的畫面;右邊是沒有整合的畫面
沒有留言:
張貼留言