目錄:Spring Cloud Alibaba系列教程
上一篇:7.Spring Cloud Alibaba 熔斷(Sentinel)
下一篇:9.Spring Cloud Alibaba 路由網(wǎng)關(guān)(Gateway)
Sentinel 控制臺
Sentinel 控制臺提供一個輕量級的控制臺,它提供機器發(fā)現(xiàn)、單機資源實時監(jiān)控、集群資源匯總,以及規(guī)則管理的功能。您只需要對應(yīng)用進(jìn)行簡單的配置,就可以使用這些功能。
注意: 集群資源匯總僅支持 500 臺以下的應(yīng)用集群,有大概 1 - 2 秒的延時。如果想支持更多的集群,那就部署兩個Sentinel嘍

下載并打包
# 下載源碼
git clone https://github.com/alibaba/Sentinel.git
# 編譯打包
mvn clean package
注:下載依賴時間較長,請耐心等待...
啟動控制臺
Sentinel 控制臺是一個標(biāo)準(zhǔn)的 SpringBoot 應(yīng)用,以 SpringBoot 的方式運行 jar 包即可。
cd sentinel-dashboard\target
java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar
如果8080端口沖突請修改-Dserver.port=自定義端口號

訪問服務(wù)
打開瀏覽器訪問:http://localhost:8080/#/dashboard/home

配置控制臺信息
application.yml 配置文件中增加如下配置:
spring:
cloud:
sentinel:
transport:
port: 8719
dashboard: localhost:8080
這里的 spring.cloud.sentinel.transport.port 端口配置會在應(yīng)用對應(yīng)的機器上啟動一個 Http Server,該 Server 會與 Sentinel 控制臺做交互。比如 Sentinel 控制臺添加了 1 個限流規(guī)則,會把規(guī)則數(shù)據(jù) push 給這個 Http Server 接收,Http Server 再將規(guī)則注冊到 Sentinel 中。
測試 Sentinel
使用之前的 Feign 客戶端,application.yml 完整配置如下:
spring:
application:
name: nacos-consumer-feign
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
sentinel:
transport:
port: 8720
dashboard: localhost:8080
server:
port: 9092
feign:
sentinel:
enabled: true
management:
endpoints:
web:
exposure:
include: "*"
注:由于 8719 端口已被 sentinel-dashboard 占用,故這里修改端口號為 8720;不修改也能注冊,會自動幫你在端口號上 + 1;
打開瀏覽器訪問:http://localhost:8080/#/dashboard/home
此時會多一個名為 nacos-consumer-feign 的服務(wù)

目錄:Spring Cloud Alibaba系列教程
上一篇:7.Spring Cloud Alibaba 熔斷(Sentinel)
下一篇:9.Spring Cloud Alibaba 路由網(wǎng)關(guān)(Gateway)