{"id":2167,"date":"2023-04-02T13:43:13","date_gmt":"2023-04-02T05:43:13","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2167"},"modified":"2023-04-02T13:58:47","modified_gmt":"2023-04-02T05:58:47","slug":"spring-cloud-alibaba-integrate-sentinel","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/02\/spring-cloud-alibaba-integrate-sentinel\/","title":{"rendered":"Spring Cloud Alibaba\u96c6\u6210Sentinel"},"content":{"rendered":"<h2>\u4ec0\u4e48\u662f Sentinel<\/h2>\n<p>\u968f\u7740\u5fae\u670d\u52a1\u7684\u6d41\u884c\uff0c\u670d\u52a1\u548c\u670d\u52a1\u4e4b\u95f4\u7684\u7a33\u5b9a\u6027\u53d8\u5f97\u8d8a\u6765\u8d8a\u91cd\u8981\u3002Sentinel \u662f\u9762\u5411\u5206\u5e03\u5f0f\u670d\u52a1\u67b6\u6784\u7684\u6d41\u91cf\u63a7\u5236\u7ec4\u4ef6\uff0c\u4e3b\u8981\u4ee5\u6d41\u91cf\u4e3a\u5207\u5165\u70b9\uff0c\u4ece\u6d41\u91cf\u63a7\u5236\u3001\u7194\u65ad\u964d\u7ea7\u3001\u7cfb\u7edf\u81ea\u9002\u5e94\u4fdd\u62a4\u7b49\u591a\u4e2a\u7ef4\u5ea6\u6765\u5e2e\u52a9\u60a8\u4fdd\u969c\u5fae\u670d\u52a1\u7684\u7a33\u5b9a\u6027\u3002<\/p>\n<p><!-- more --><\/p>\n<p>Github\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/alibaba\/Sentinel\">https:\/\/github.com\/alibaba\/Sentinel<\/a><br \/>\n\u5b98\u7f51\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/sentinelguard.io\/\">https:\/\/sentinelguard.io\/<\/a><\/p>\n<h2>Sentinel \u7684\u7279\u5f81<\/h2>\n<ul>\n<li>\n<p>\u4e30\u5bcc\u7684\u5e94\u7528\u573a\u666f\uff1aSentinel \u627f\u63a5\u4e86\u963f\u91cc\u5df4\u5df4\u8fd1 10 \u5e74\u7684\u53cc\u5341\u4e00\u5927\u4fc3\u6d41\u91cf\u7684\u6838\u5fc3\u573a\u666f\uff0c\u4f8b\u5982\u79d2\u6740\uff08\u5373\u7a81\u53d1\u6d41\u91cf\u63a7\u5236\u5728\u7cfb\u7edf\u5bb9\u91cf\u53ef\u4ee5\u627f\u53d7\u7684\u8303\u56f4\uff09\u3001\u6d88\u606f\u524a\u5cf0\u586b\u8c37\uff08\u5bf9\u4e8e\u7a81\u7136\u5230\u6765\u7684\u5927\u91cf\u8bf7\u6c42\uff0c\u53ef\u4ee5\u914d\u7f6e\u6d41\u63a7\u89c4\u5219\uff0c\u4ee5\u7a33\u5b9a\u7684\u901f\u5ea6\u9010\u6b65\u5904\u7406\u8fd9\u4e9b\u8bf7\u6c42\uff0c\u4ece\u800c\u907f\u514d\u6d41\u91cf\u7a81\u523a\u9020\u6210\u7cfb\u7edf\u8d1f\u8f7d\u8fc7\u9ad8\uff09\u3001\u96c6\u7fa4\u6d41\u91cf\u63a7\u5236\u3001\u5b9e\u65f6\u7194\u65ad\u4e0b\u6e38\u4e0d\u53ef\u7528\u5e94\u7528\u7b49<\/p>\n<\/li>\n<li>\n<p>\u5b8c\u5907\u7684\u5b9e\u65f6\u76d1\u63a7\uff1a Sentinel \u540c\u65f6\u63d0\u4f9b\u5b9e\u65f6\u7684\u76d1\u63a7\u529f\u80fd\u3002\u53ef\u4ee5\u5728\u63a7\u5236\u53f0\u4e2d\u770b\u5230\u63a5\u5165\u5e94\u7528\u7684\u5355\u53f0\u673a\u5668\u79d2\u7ea7\u6570\u636e\uff0c\u751a\u81f3 500 \u53f0\u4ee5\u4e0b\u89c4\u6a21\u7684\u96c6\u7fa4\u7684\u6c47\u603b\u8fd0\u884c\u60c5\u51b5<\/p>\n<\/li>\n<li>\n<p>\u5e7f\u6cdb\u7684\u5f00\u6e90\u751f\u6001\uff1a Sentinel \u63d0\u4f9b\u5f00\u7bb1\u5373\u7528\u7684\u4e0e\u5176\u5b83\u5f00\u6e90\u6846\u67b6 \/ \u5e93\u7684\u6574\u5408\u6a21\u5757\uff0c\u4f8b\u5982\u4e0e Spring Cloud\u3001Dubbo\u3001gRPC \u7684\u6574\u5408\u3002\u53ea\u9700\u8981\u5f15\u5165\u76f8\u5e94\u7684\u4f9d\u8d56\u5e76\u8fdb\u884c\u7b80\u5355\u7684\u914d\u7f6e\u5373\u53ef\u5feb\u901f\u5730\u63a5\u5165 Sentinel<\/p>\n<\/li>\n<li>\n<p>\u5b8c\u5584\u7684 SPI \u6269\u5c55\u70b9\uff1a Sentinel \u63d0\u4f9b\u7b80\u5355\u6613\u7528\u3001\u5b8c\u5584\u7684 SPI \u6269\u5c55\u63a5\u53e3\u3002\u53ef\u4ee5\u901a\u8fc7\u5b9e\u73b0\u6269\u5c55\u63a5\u53e3\u6765\u5feb\u901f\u5730\u5b9a\u5236\u903b\u8f91\u3002\u4f8b\u5982\u5b9a\u5236\u89c4\u5219\u7ba1\u7406\u3001\u9002\u914d\u52a8\u6001\u6570\u636e\u6e90\u7b49<\/p>\n<\/li>\n<\/ul>\n<h2>Sentinel \u7684\u4e3b\u8981\u7279\u6027<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Java\/sentinel-features-overview-en.png\" alt=\"sentinel features overview\" \/><\/p>\n<h2>Sentinel \u7684\u7ec4\u6210<\/h2>\n<p>\u6838\u5fc3\u5e93\uff08Java \u5ba2\u6237\u7aef\uff09\uff1a \u4e0d\u4f9d\u8d56\u4efb\u4f55\u6846\u67b6 \/ \u5e93\uff0c\u80fd\u591f\u8fd0\u884c\u4e8e\u6240\u6709 Java \u8fd0\u884c\u65f6\u73af\u5883\uff0c\u540c\u65f6\u5bf9 Dubbo \/ Spring<br \/>\nCloud \u7b49\u6846\u67b6\u4e5f\u6709\u8f83\u597d\u7684\u652f\u6301<br \/>\n\u63a7\u5236\u53f0\uff08Dashboard\uff09\uff1a \u57fa\u4e8e Spring Boot \u5f00\u53d1\uff0c\u6253\u5305\u540e\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\uff0c\u4e0d\u9700\u8981\u989d\u5916\u7684 Tomcat \u7b49\u5e94\u7528\u5bb9\u5668<\/p>\n<h2>Sentinel \u63a7\u5236\u53f0<\/h2>\n<p>Sentinel \u63d0\u4f9b\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u5f00\u6e90\u63a7\u5236\u53f0\uff0c\u5b83\u63d0\u4f9b\u673a\u5668\u53d1\u73b0\u4ee5\u53ca\u5065\u5eb7\u60c5\u51b5\u7ba1\u7406\u3001\u76d1\u63a7\uff08\u5355\u673a\u548c\u96c6\u7fa4\uff09\uff0c\u89c4\u5219\u7ba1\u7406\u548c\u63a8\u9001\u7684\u529f\u80fd\u3002<\/p>\n<p>Sentinel \u63a7\u5236\u53f0\u5305\u542b\u5982\u4e0b\u529f\u80fd:<\/p>\n<ul>\n<li>\u67e5\u770b\u673a\u5668\u5217\u8868\u4ee5\u53ca\u5065\u5eb7\u60c5\u51b5\uff1a\u6536\u96c6 Sentinel \u5ba2\u6237\u7aef\u53d1\u9001\u7684\u5fc3\u8df3\u5305\uff0c\u7528\u4e8e\u5224\u65ad\u673a\u5668\u662f\u5426\u5728\u7ebf\u3002<\/li>\n<li>\u76d1\u63a7 (\u5355\u673a\u548c\u96c6\u7fa4\u805a\u5408)\uff1a\u901a\u8fc7 Sentinel \u5ba2\u6237\u7aef\u66b4\u9732\u7684\u76d1\u63a7 API\uff0c\u5b9a\u671f\u62c9\u53d6\u5e76\u4e14\u805a\u5408\u5e94\u7528\u76d1\u63a7\u4fe1\u606f\uff0c\u6700\u7ec8\u53ef\u4ee5\u5b9e\u73b0\u79d2\u7ea7\u7684\u5b9e\u65f6\u76d1\u63a7\u3002<\/li>\n<li>\u89c4\u5219\u7ba1\u7406\u548c\u63a8\u9001\uff1a\u7edf\u4e00\u7ba1\u7406\u63a8\u9001\u89c4\u5219\u3002<\/li>\n<li>\u9274\u6743\uff1a\u751f\u4ea7\u73af\u5883\u4e2d\u9274\u6743\u975e\u5e38\u91cd\u8981\u3002\u8fd9\u91cc\u6bcf\u4e2a\u5f00\u53d1\u8005\u9700\u8981\u6839\u636e\u81ea\u5df1\u7684\u5b9e\u9645\u60c5\u51b5\u8fdb\u884c\u5b9a\u5236\u3002<\/li>\n<\/ul>\n<h3>\u542f\u52a8\u63a7\u5236\u53f0<\/h3>\n<p>\uff081\uff09\u83b7\u53d6 Sentinel \u63a7\u5236\u53f0<\/p>\n<p>\u53ef\u4ee5\u4ece <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/alibaba\/Sentinel\/releases\" title=\"release \u9875\u9762\">release \u9875\u9762<\/a> \u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684\u63a7\u5236\u53f0 jar \u5305\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4ece\u6700\u65b0\u7248\u672c\u7684\u6e90\u7801\u81ea\u884c\u6784\u5efa Sentinel \u63a7\u5236\u53f0\uff1a<\/p>\n<ul>\n<li>\u4e0b\u8f7d <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/alibaba\/Sentinel\/tree\/master\/sentinel-dashboard\" title=\"\u63a7\u5236\u53f0\">\u63a7\u5236\u53f0<\/a> \u5de5\u7a0b<\/li>\n<li>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u4ee3\u7801\u6253\u5305\u6210\u4e00\u4e2a fat jar: <code>mvn clean package<\/code><\/li>\n<\/ul>\n<p>\uff082\uff09\u542f\u52a8<\/p>\n<blockquote>\n<p>\u6ce8\u610f\uff1a\u542f\u52a8 Sentinel \u63a7\u5236\u53f0\u9700\u8981 JDK \u7248\u672c\u4e3a 1.8 \u53ca\u4ee5\u4e0a\u7248\u672c<\/p>\n<\/blockquote>\n<p>\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u542f\u52a8\u63a7\u5236\u53f0\uff1a<\/p>\n<pre><code class=\"language-bash\">java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar<\/code><\/pre>\n<p>\u5176\u4e2d<code>-Dserver.port=8080<\/code>\u7528\u4e8e\u6307\u5b9a Sentinel \u63a7\u5236\u53f0\u7aef\u53e3\u4e3a<code>8080<\/code><\/p>\n<blockquote>\n<p>\u4ece Sentinel 1.6.0 \u8d77\uff0cSentinel \u63a7\u5236\u53f0\u5f15\u5165\u57fa\u672c\u7684\u767b\u5f55\u529f\u80fd\uff0c\u9ed8\u8ba4\u7528\u6237\u540d\u548c\u5bc6\u7801\u90fd\u662f sentinel\u3002\u53ef\u4ee5\u53c2\u8003 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/sentinelguard.io\/zh-cn\/docs\/dashboard.html#\u9274\u6743\u6a21\u5757\u6587\u6863\" title=\"\u9274\u6743\u6a21\u5757\u6587\u6863\">\u9274\u6743\u6a21\u5757\u6587\u6863<\/a> \u914d\u7f6e\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<\/p>\n<p>\u6ce8\uff1a\u82e5\u60a8\u7684\u5e94\u7528\u4e3a Spring Boot \u6216 Spring Cloud \u5e94\u7528\uff0c\u53ef\u4ee5\u901a\u8fc7 Spring \u914d\u7f6e\u6587\u4ef6\u6765\u6307\u5b9a\u914d\u7f6e\uff0c\u8be6\u60c5\u8bf7\u53c2\u8003 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/spring-cloud-incubator\/spring-cloud-alibaba\/wiki\/Sentinel\" title=\"Spring Cloud Alibaba Sentinel \u6587\u6863\">Spring Cloud Alibaba Sentinel \u6587\u6863<\/a>\u3002<\/p>\n<\/blockquote>\n<h3>\u9274\u6743\u914d\u7f6e<\/h3>\n<p>\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u53c2\u6570\u8fdb\u884c\u914d\u7f6e<\/p>\n<ul>\n<li><code>-Dsentinel.dashboard.auth.username=sentinel<\/code> \u7528\u4e8e\u6307\u5b9a\u63a7\u5236\u53f0\u7684\u767b\u5f55\u7528\u6237\u540d\u4e3a sentinel<\/li>\n<li><code>-Dsentinel.dashboard.auth.password=123456<\/code> \u7528\u4e8e\u6307\u5b9a\u63a7\u5236\u53f0\u7684\u767b\u5f55\u5bc6\u7801\u4e3a 123456\uff1b\u5982\u679c\u7701\u7565\u8fd9\u4e24\u4e2a\u53c2\u6570\uff0c\u9ed8\u8ba4\u7528\u6237\u548c\u5bc6\u7801\u5747\u4e3a sentinel<\/li>\n<li><code>-Dserver.servlet.session.timeout=7200<\/code> \u7528\u4e8e\u6307\u5b9a Spring Boot \u670d\u52a1\u7aef session \u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u5982 7200 \u8868\u793a 7200 \u79d2\uff1b60m \u8868\u793a 60 \u5206\u949f\uff0c\u9ed8\u8ba4\u4e3a 30 \u5206\u949f<\/li>\n<\/ul>\n<h3>\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f<\/h3>\n<p>\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee <a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/localhost:8080\/#\/login\">http:\/\/localhost:8080\/#\/login<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/user-images.githubusercontent.com\/9434884\/56669344-94b4d880-66e3-11e9-9553-731d67651a11.png\" alt=\"sentinel login\" \/><\/p>\n<h2>Sentinel \u5ba2\u6237\u7aef\u63a5\u5165<\/h2>\n<h3>\u6dfb\u52a0\u4f9d\u8d56<\/h3>\n<pre><code class=\"language-xml\">&lt;dependency&gt;\n    &lt;groupId&gt;com.alibaba.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-alibaba-sentinel&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<h3>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u589e\u52a0\u5bf9 Sentinel \u7684\u652f\u6301<\/p>\n<pre><code class=\"language-yml\">spring: \n  application:\n    # \u670d\u52a1\u540d\n    name: service-consumer\n  cloud:\n    nacos:\n      discovery:\n        # \u670d\u52a1\u6ce8\u518c\u4e2d\u5fc3\n        server-addr: 192.168.141.132:8848\n      config:\n        # \u670d\u52a1\u914d\u7f6e\u4e2d\u5fc3\n        server-addr: 192.168.141.132:8848\n    # \u7194\u65ad\u9650\u6d41\n    sentinel:\n      transport:\n        dashboard: localhost:8888\n\n#\u5f00\u542f Feign \u5bf9 Sentinel \u7684\u652f\u6301\nfeign:\n  sentinel:\n    enabled: true\n\nserver:\n  # \u670d\u52a1\u7aef\u53e3\n  port: 8080\n\nmanagement:\n  # \u7aef\u70b9\u68c0\u67e5\uff08\u5065\u5eb7\u68c0\u67e5\uff09\n  endpoints:\n    web:\n      exposure:\n        include: &quot;*&quot;<\/code><\/pre>\n<h3>\u914d\u7f6e\u7194\u65ad\u7c7b<\/h3>\n<p>\u7f16\u5199\u4e00\u4e2a Feign \u63a5\u53e3\u7684\u5b9e\u73b0\u7c7b\u5e76\u589e\u52a0<code>@Component<\/code>\u6ce8\u89e3<\/p>\n<pre><code class=\"language-java\">import org.springframework.stereotype.Component;\n\n@Component\npublic class EchoServiceFallback implements EchoService {\n\n    @Override\n    public String echo(String string) {\n        return &quot;echo fallback&quot;;\n    }\n}<\/code><\/pre>\n<h3>\u4fee\u6539 Feign \u63a5\u53e3<\/h3>\n<p>\u5728<code>@FeignClient<\/code>\u63a5\u53e3\u4e0a\u589e\u52a0 fallback \u5c5e\u6027\u6307\u5b9a\u7194\u65ad\u7c7b\u5373\u53ef<\/p>\n<pre><code class=\"language-java\">@FeignClient(value = &quot;service-provider&quot;, fallback = EchoServiceFallback.class)\npublic interface EchoService {\n\n    @GetMapping(value = &quot;\/echo\/{string}&quot;)\n    String echo(@PathVariable(&quot;string&quot;) String string);\n\n}<\/code><\/pre>\n<h3>\u6d4b\u8bd5\u7194\u65ad<\/h3>\n<p>\u542f\u52a8<code>service-consumer<\/code>\u670d\u52a1\u5e76\u505c\u6b62<code>service-provider<\/code>\u670d\u52a1\uff0c\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u8be5\u670d\u52a1\u5373\u53ef<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Java\/Sentinel\u7194\u65ad\u6d4b\u8bd5.png\" alt=\"Sentinel\u7194\u65ad\u6d4b\u8bd5\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f Sentinel \u968f\u7740\u5fae\u670d\u52a1\u7684\u6d41\u884c\uff0c\u670d\u52a1\u548c\u670d\u52a1\u4e4b\u95f4\u7684\u7a33\u5b9a\u6027\u53d8\u5f97\u8d8a\u6765\u8d8a\u91cd\u8981\u3002Sentinel \u662f\u9762\u5411\u5206\u5e03 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[539],"class_list":["post-2167","post","type-post","status-publish","format-standard","hentry","category-spring-cloud","tag-sentinel"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2167"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2167\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}