{"id":2231,"date":"2024-06-07T17:02:41","date_gmt":"2024-06-07T09:02:41","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=2231"},"modified":"2024-06-07T17:02:41","modified_gmt":"2024-06-07T09:02:41","slug":"config-service%ef%bc%9a%e5%ad%a6%e4%b9%a0%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84%e5%92%8c%e5%81%a5%e5%ba%b7%e6%a3%80%e6%9f%a5","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2024\/06\/07\/config-service%ef%bc%9a%e5%ad%a6%e4%b9%a0%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84%e5%92%8c%e5%81%a5%e5%ba%b7%e6%a3%80%e6%9f%a5\/","title":{"rendered":"config-service\uff1a\u5b66\u4e60\u7aef\u53e3\u6620\u5c04\u548c\u5065\u5eb7\u68c0\u67e5"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">1. config-service \u7684\u89d2\u8272<\/h4>\n\n\n\n<p>config-service \u662f\u4e00\u4e2a\u914d\u7f6e\u670d\u52a1\uff0c\u901a\u5e38\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\u7528\u4e8e\u96c6\u4e2d\u7ba1\u7406\u548c\u5206\u53d1\u914d\u7f6e\u6587\u4ef6\u3002\u5b83\u4f7f\u5f97\u4e0d\u540c\u670d\u52a1\u53ef\u4ee5\u4ece\u4e2d\u5fc3\u4f4d\u7f6e\u83b7\u53d6\u914d\u7f6e\u4fe1\u606f\uff0c\u4ece\u800c\u7b80\u5316\u914d\u7f6e\u7ba1\u7406\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. \u914d\u7f6e\u89e3\u8bfb<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>version: \"3.7\"\nservices:\n  config-service:\n    image: piomin\/config-service:1.1-SNAPSHOT\n    ports:\n      - \"8088:8088\"\n    healthcheck:\n      test: curl --fail http:\/\/localhost:8088\/employee\/docker || exit 1\n      interval: 5s\n      timeout: 2s\n      retries: 3\n<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. \u7aef\u53e3\u6620\u5c04<\/h4>\n\n\n\n<p>\u7aef\u53e3\u6620\u5c04\u662f\u5c06\u5bb9\u5668\u5185\u90e8\u7684\u7aef\u53e3\u66b4\u9732\u7ed9\u4e3b\u673a\uff0c\u4f7f\u5916\u90e8\u6d41\u91cf\u53ef\u4ee5\u901a\u8fc7\u4e3b\u673a\u7aef\u53e3\u8bbf\u95ee\u5bb9\u5668\u5185\u90e8\u7684\u670d\u52a1\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\u8bed\u6cd5<\/strong>: <code>\"\u4e3b\u673a\u7aef\u53e3:\u5bb9\u5668\u7aef\u53e3\"<\/code><\/li><li><strong>\u793a\u4f8b<\/strong>: <code>\"8088:8088\"<\/code><\/li><\/ul>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u914d\u7f6e\u4e2d\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><code>ports: [\"8088:8088\"]<\/code><\/strong>: \u8fd9\u884c\u914d\u7f6e\u5c06\u4e3b\u673a\u76848088\u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u5668\u76848088\u7aef\u53e3\u3002\u8fd9\u610f\u5473\u7740\u5f53\u4f60\u8bbf\u95ee\u4e3b\u673a\u4e0a\u7684<code>http:\/\/localhost:8088<\/code>\u65f6\uff0c\u8bf7\u6c42\u4f1a\u88ab\u8f6c\u53d1\u5230\u8fd0\u884c\u5728\u5bb9\u5668\u4e2d\u7684config-service\u76848088\u7aef\u53e3\u3002<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4. \u5065\u5eb7\u68c0\u67e5\uff08Health Check\uff09<\/h4>\n\n\n\n<p>\u5065\u5eb7\u68c0\u67e5\u7528\u4e8e\u5b9a\u671f\u68c0\u67e5\u670d\u52a1\u662f\u5426\u5065\u5eb7\u53ef\u7528\u3002Docker Compose\u4f1a\u6839\u636e\u5065\u5eb7\u68c0\u67e5\u7ed3\u679c\u6765\u51b3\u5b9a\u662f\u5426\u91cd\u65b0\u542f\u52a8\u5bb9\u5668\u6216\u8005\u5728\u542f\u52a8\u65f6\u4f9d\u8d56\u5176\u4ed6\u670d\u52a1\u7684\u5065\u5eb7\u72b6\u6001\u3002<\/p>\n\n\n\n<p>\u5065\u5eb7\u68c0\u67e5\u914d\u7f6e\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>healthcheck:\n  test: curl --fail http:\/\/localhost:8088\/employee\/docker || exit 1\n  interval: 5s\n  timeout: 2s\n  retries: 3\n<\/code><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><code>test<\/code><\/strong>: \u6307\u5b9a\u68c0\u67e5\u547d\u4ee4\u3002\u5728\u8fd9\u91cc\uff0c\u4f7f\u7528<code>curl --fail http:\/\/localhost:8088\/employee\/docker<\/code>\u6765\u68c0\u67e5config-service\u662f\u5426\u6b63\u5e38\u8fd0\u884c\u3002\u5982\u679ccurl\u547d\u4ee4\u5931\u8d25\uff0c\u5219\u547d\u4ee4\u4f1a\u8fd4\u56de\u975e\u96f6\u9000\u51fa\u7801\uff0c\u8868\u793a\u5065\u5eb7\u68c0\u67e5\u5931\u8d25\u3002<\/li><li><strong><code>interval<\/code><\/strong>: \u5065\u5eb7\u68c0\u67e5\u7684\u95f4\u9694\u65f6\u95f4\uff08\u8fd9\u91cc\u662f5\u79d2\uff09\u3002\u6bcf\u96945\u79d2\u949f\u8fdb\u884c\u4e00\u6b21\u5065\u5eb7\u68c0\u67e5\u3002<\/li><li><strong><code>timeout<\/code><\/strong>: \u5065\u5eb7\u68c0\u67e5\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u8fd9\u91cc\u662f2\u79d2\uff09\u3002\u5982\u679ccurl\u547d\u4ee4\u57282\u79d2\u5185\u6ca1\u6709\u8fd4\u56de\u7ed3\u679c\uff0c\u5219\u8ba4\u4e3a\u5065\u5eb7\u68c0\u67e5\u5931\u8d25\u3002<\/li><li><strong><code>retries<\/code><\/strong>: \u6700\u5927\u91cd\u8bd5\u6b21\u6570\uff08\u8fd9\u91cc\u662f3\u6b21\uff09\u3002\u5982\u679c\u8fde\u7eed3\u6b21\u5065\u5eb7\u68c0\u67e5\u5931\u8d25\uff0c\u5219\u8ba4\u4e3a\u5bb9\u5668\u4e0d\u5065\u5eb7\u3002<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">5. \u5065\u5eb7\u68c0\u67e5\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u4f5c\u7528<\/h4>\n\n\n\n<p>\u5065\u5eb7\u68c0\u67e5\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u81ea\u52a8\u5316\u5730\u68c0\u6d4b\u548c\u54cd\u5e94\u670d\u52a1\u6545\u969c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\u81ea\u6211\u4fee\u590d<\/strong>\uff1a\u5f53\u670d\u52a1\u68c0\u6d4b\u5230\u67d0\u4e2a\u5bb9\u5668\u4e0d\u5065\u5eb7\u65f6\uff0c\u53ef\u4ee5\u81ea\u52a8\u91cd\u542f\u5bb9\u5668\u3002<\/li><li><strong>\u4f9d\u8d56\u7ba1\u7406<\/strong>\uff1a\u53ef\u4ee5\u786e\u4fdd\u670d\u52a1\u5728\u542f\u52a8\u65f6\u4f9d\u8d56\u7684\u5176\u4ed6\u670d\u52a1\u5df2\u7ecf\u5065\u5eb7\u53ef\u7528\u3002<\/li><li><strong>\u63d0\u5347\u53ef\u9760\u6027<\/strong>\uff1a\u901a\u8fc7\u5b9a\u671f\u68c0\u67e5\u548c\u81ea\u52a8\u4fee\u590d\uff0c\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u9760\u6027\u548c\u53ef\u7528\u6027\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u7ed3\u8bba<\/h3>\n\n\n\n<p>\u901a\u8fc7\u7406\u89e3\u548c\u914d\u7f6e\u7aef\u53e3\u6620\u5c04\u548c\u5065\u5eb7\u68c0\u67e5\uff0c\u4f60\u53ef\u4ee5\u66f4\u597d\u5730\u7ba1\u7406Docker\u5bb9\u5668\u4e2d\u7684\u670d\u52a1\u3002\u7aef\u53e3\u6620\u5c04\u4f7f\u5916\u90e8\u8bf7\u6c42\u53ef\u4ee5\u8bbf\u95ee\u5bb9\u5668\u5185\u7684\u670d\u52a1\uff0c\u800c\u5065\u5eb7\u68c0\u67e5\u5219\u5e2e\u52a9\u76d1\u63a7\u548c\u7ef4\u62a4\u670d\u52a1\u7684\u5065\u5eb7\u72b6\u6001\u3002\u8fd9\u4e9b\u914d\u7f6e\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u7528\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. config-servic&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2231","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=2231"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2231\/revisions"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=2231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=2231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=2231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}