{"id":5392,"date":"2021-07-14T15:08:04","date_gmt":"2021-07-14T07:08:04","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=5392"},"modified":"2021-07-14T15:08:04","modified_gmt":"2021-07-14T07:08:04","slug":"5-2-etcd%e7%8e%af%e5%a2%83%e5%ae%89%e8%a3%85%e3%80%81%e5%91%bd%e4%bb%a4%e5%92%8c%e7%bc%96%e7%a8%8b%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/5392","title":{"rendered":"5.2 ETCD\u73af\u5883\u5b89\u88c5\u3001\u547d\u4ee4\u548c\u7f16\u7a0b\u5b9e\u6218"},"content":{"rendered":"<div class=\"WithToc-module_article_2_rhk\">\n<div class=\"DocReader-module_content_2JTe8\">\n<div>\n<article id=\"content\" class=\"article-content\" tabindex=\"0\">\n<div class=\"index-module_header_3qjZG\">\n<div class=\"index-module_title_1s0gC\"><\/div>\n<\/div>\n<div>\n<div class=\"yuque-doc-content\" data-df=\"lake\">\n<div class=\"lake-content\">\n<p id=\"73dd00b94921c822a7567736156f13d9\" class=\"ne-p\"><a href=\"https:\/\/www.yuque.com\/docs\/share\/43806503-5527-4847-9c61-e7682fa5e21c?#\">\u539f\u6587\u5730\u5740<\/a><\/p>\n<p>&nbsp;<\/p>\n<p id=\"9125610b8a71fe9609a1b1110b767e50\" class=\"ne-p\"><span class=\"ne-text\">\u6ca1\u6709go\u73af\u5883\u7684\u5148\u53c2\u8003 \u7b2c\u4e8c\u7ae0\u8282 \u300ago \u5b89\u88c5\u300b\u5148\u5b89\u88c5go\u8bed\u8a00\u73af\u5883\u3002\u9700\u8981go 1.11\u4ee5\u4e0a\u7684\u7248\u672c\u3002\u5efa\u8bae\u5148\u6d4b\u8bd5\u5355\u673a\u7248\u672c\u3002<\/span><\/p>\n<h1 id=\"msaeN\"><span class=\"ne-text\">1 \u7f16\u8bd1ETCD<\/span><\/h1>\n<p id=\"beca7ad858a9430ed5883cc3fff95e13\" class=\"ne-p\"><a class=\"ne-link\" href=\"http:\/\/c.biancheng.net\/view\/123.html\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/c.biancheng.net\/view\/123.html\"><span class=\"ne-text\">http:\/\/c.biancheng.net\/view\/123.html<\/span><\/a><\/p>\n<h2 id=\"8KqFW\"><span class=\"ne-text\">1.1 \u6e90\u7801\u5b89\u88c5<\/span><\/h2>\n<p id=\"ad0479b7e611cf6dad44a4657f63780b\" class=\"ne-p\"><span class=\"ne-text\">\u5b89\u88c5\u597dGolang\u73af\u5883: \u89c1<\/span><a class=\"ne-link\" href=\"https:\/\/www.cnblogs.com\/tool\/golang-config.html\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/www.cnblogs.com\/tool\/golang-config.html\"><span class=\"ne-text\">Golang\u73af\u5883\u914d\u7f6e<\/span><\/a><\/p>\n<pre id=\"vrHXi\" class=\"ne-codeblock\" data-language=\"bash\">\u4e0b\u8f7detcd\r\ngit clone https:\/\/gitee.com\/hcrwang\/etcd.git\r\n\u8bbe\u7f6e\u6e90\u4ee3\u7406\r\ngo env -w GO111MODULE=on\r\ngo env -w GOPROXY=https:\/\/goproxy.cn,direct\r\n\u8fdb\u5165etcd\u76ee\u5f55\r\ncd etcd\r\n\u4e0b\u8f7drelease\u7248\u672c\r\ngit checkout release-3.4\r\ngo mod vendor\r\n.\/build\r\n\u5728etcd\/bin\u76ee\u5f55\u751f\u6210\u5bf9\u5e94\u7684\u6267\u884c\u6587\u4ef6 etcd\u548cetcdctl<\/pre>\n<p id=\"645448b9acc6725e7f04d79615ed4e2c\" class=\"ne-p\"><span class=\"ne-text\">\u542f\u52a8:<\/span><\/p>\n<pre id=\"l4M3R\" class=\"ne-codeblock\" data-language=\"bash\">.\/etcd<\/pre>\n<p id=\"f45745449562c8c411eabe5a37247fa7\" class=\"ne-p\"><a class=\"ne-link\" href=\"https:\/\/github.com\/etcd-io\/etcd.git\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/etcd-io\/etcd.git\"><span class=\"ne-text\">https:\/\/github.com\/etcd-io\/etcd.git<\/span><\/a><\/p>\n<h1 id=\"AnHf8\"><span class=\"ne-text\">2 go\u5b89\u88c5<\/span><\/h1>\n<p id=\"6043ae228c7e21aba06bac03b009d055\" class=\"ne-p\"><a class=\"ne-link\" href=\"https:\/\/golang.google.cn\/dl\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/golang.google.cn\/dl\/\"><span class=\"ne-text\">https:\/\/golang.google.cn\/dl\/<\/span><\/a><\/p>\n<p id=\"9b12eb9d3346c16072d4c98094b23469\" class=\"ne-p\"><span class=\"ne-text\">olang\u5b98\u7f51\u4e0b\u8f7d\u5730\u5740\uff1a<\/span><a class=\"ne-link\" href=\"https:\/\/golang.google.cn\/dl\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/golang.google.cn\/dl\/\"><span class=\"ne-text\">\u00a0https:\/\/golang.google.cn\/dl\/<\/span><\/a><\/p>\n<p id=\"83104543b5c6f8322bfd6b7505cbaeff\" class=\"ne-p\"><img decoding=\"async\" id=\"D5Fzb\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603805296159-8262f3e5-e2bc-4a48-82c5-242d7dd766d1.png\" width=\"1160\" \/><\/p>\n<p id=\"24e9d365d6b8d67e54bc9f5a803ee685\" class=\"ne-p\"><span class=\"ne-text\">\u00a0<\/span><\/p>\n<p id=\"c8e7b6f8ba614a2dec7bb259d0af174d\" class=\"ne-p\"><span class=\"ne-text\">\u00a0\u6ce8\u610f\u7cfb\u7edf\u548c\u7248\u672c\u7684\u533a\u522b<\/span><\/p>\n<p id=\"b7af242a3bb78e709ba1d1d208ea0a69\" class=\"ne-p\"><span class=\"ne-text\">1.\u6253\u5f00\u5b98\u7f51\u4e0b\u8f7d\u5730\u5740\u9009\u62e9\u5bf9\u5e94\u7684\u7cfb\u7edf\u7248\u672c, \u590d\u5236\u4e0b\u8f7d\u94fe\u63a5<\/span><\/p>\n<pre id=\"kHUfW\" class=\"ne-codeblock\" data-language=\"plain\">wget https:\/\/dl.google.com\/go\/go1.15.3.linux-amd64.tar.gz<\/pre>\n<p id=\"a39f3604c6bf695c6b7f9c8deb1c79cf\" class=\"ne-p\"><span class=\"ne-text\">2.\u5c06\u5176\u89e3\u538b\u7f29\u5230\/usr\/local\/(\u4f1a\u5728\/usr\/local\u4e2d\u521b\u5efa\u4e00\u4e2ago\u76ee\u5f55)<\/span><\/p>\n<p id=\"cc91fb16a3e5ab4b41691484923489b9\" class=\"ne-p\"><span class=\"ne-text\">tar -C \/usr\/local -xzf <\/span><span class=\"ne-text\">go<\/span><span class=\"ne-text\">1.15.3<\/span><span class=\"ne-text\">.linux-amd64.tar.gz<\/span><\/p>\n<p id=\"fc217b9fb9e22ba5b62b99eed43465f5\" class=\"ne-p\"><span class=\"ne-text\">3.\u6dfb\u52a0\u73af\u5883\u53d8\u91cf<\/span><\/p>\n<p id=\"a6e3e7c698729f088f2951202d30e0f6\" class=\"ne-p\"><code class=\"ne-code\"><span class=\"ne-text\">vim \/etc\/profile<\/span><\/code><\/p>\n<p id=\"f5d0bfec1e6b0b0572fed0f1f6f32077\" class=\"ne-p\"><span class=\"ne-text\">\u5728\u6253\u5f00\u7684\u6587\u4ef6\u6700\u540e\u6dfb\u52a0\uff1a<\/span><\/p>\n<p id=\"bf895a5c014df93394647dc0e5547d09\" class=\"ne-p\"><span class=\"ne-text\">export GOPATH=~\/go # \u5728home\u76ee\u5f55\u4e0b\u7684go\u76ee\u5f55<\/span><\/p>\n<p id=\"ace69c19db87644d9e916394a8be78cf\" class=\"ne-p\"><span class=\"ne-text\">export GOROOT=\/usr\/local\/go<\/span><\/p>\n<p id=\"682c1d47c9b28b8137fa8f1d01f043b3\" class=\"ne-p\"><span class=\"ne-text\">export PATH=$PATH:\/usr\/local\/go\/bin<\/span><\/p>\n<p id=\"bc3f936aa3385d3f3f2a0ec2dcdc71c8\" class=\"ne-p\"><span class=\"ne-text\">export PATH=$PATH:$GOPATH:$GOROOT:\/bin<\/span><\/p>\n<p id=\"029c248366b1a776f8319f16ffedab54\" class=\"ne-p\"><img decoding=\"async\" id=\"lt7OG\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603805605184-8dab2e65-d869-4e96-8798-5ff859591568.png\" width=\"388\" \/><\/p>\n<p id=\"4dc06dbedcdc6655f2471837e5762490\" class=\"ne-p\"><span class=\"ne-text\">\/\/ wq\u4fdd\u5b58\u9000\u51fa\u540esource\u4e00\u4e0b<\/span><\/p>\n<p id=\"102aacb0f941e06ac68172e504a91f22\" class=\"ne-p\"><span class=\"ne-text\">source \/etc\/profile<\/span><\/p>\n<p id=\"c52eb9e91183e7632eacf99f16d21a59\" class=\"ne-p\"><span class=\"ne-text\">4.\u67e5\u770b\u7248\u672c<\/span><\/p>\n<p id=\"236e1060a1d89a4f690f52eb6a6a04c2\" class=\"ne-p\"><span class=\"ne-text\">go version<\/span><\/p>\n<p id=\"3ef293d5c9a3959b2a16034f9b13d9a5\" class=\"ne-p\"><img decoding=\"async\" id=\"BO50C\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603805786239-417285cb-242f-430f-af35-b401ea3ed2f9.png\" width=\"448\" \/><\/p>\n<p id=\"8cf57b4a54ff4f5c4b981710912ef128\" class=\"ne-p\"><span class=\"ne-text\">\u5982\u679c\u663e\u793a\u5176\u4ed6\u7684\u7248\u672c\uff0c\u8bf4\u660e\u4f60\u81ea\u5df1\u5df2\u7ecf\u5b89\u88c5\u8fc7go\uff0c\u7528which go\u547d\u4ee4\u67e5\u627e<\/span><\/p>\n<p id=\"30995da8f9f5d99e273b4f8cd6b695d6\" class=\"ne-p\"><img decoding=\"async\" id=\"BGH1Z\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1605095974097-744fdf24-9cff-466d-993d-6aa2c896131f.png\" width=\"219.5\" \/><\/p>\n<p id=\"557525abce6e9bf457e5b6556810644d\" class=\"ne-p\"><span class=\"ne-text\">\u7136\u540e\u624b\u52a8\u5c06\/usr\/bin\/go\u5220\u9664\u3002<\/span><\/p>\n<p id=\"a5352097009514c2a270d259d43625ec\" class=\"ne-p\"><span class=\"ne-text\">\u00a05.\u6d4b\u8bd5\u4f7f\u7528<\/span><\/p>\n<p id=\"6e0d13b3caf7b270e80f5676ff5d39e0\" class=\"ne-p\"><span class=\"ne-text\">\u5728\u4f60\u7684\u5de5\u4f5c\u533a\u521b\u5efahello.go<\/span><\/p>\n<pre id=\"QZ0Sn\" class=\"ne-codeblock\" data-language=\"c\">package main\r\nimport \"fmt\"\r\nfunc main() {\r\n fmt.Printf(\"hello, world\\n\")\r\n}<\/pre>\n<p id=\"9ac9ebf40d714672bbc56c2ec9274bfd\" class=\"ne-p\"><span class=\"ne-text\">\u6784\u5efa\u9879\u76ee\uff08Then build it with the <\/span><code class=\"ne-code\"><span class=\"ne-text\">go<\/span><\/code><span class=\"ne-text\"> tool\uff09<\/span><\/p>\n<p id=\"027aa3d68427e45af3b3a2d5a2faf439\" class=\"ne-p\"><span class=\"ne-text\">go build hello.go<\/span><\/p>\n<p id=\"c52d706e9add06e1676753990242c8a9\" class=\"ne-p\"><span class=\"ne-text\">\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3ahello\u7684\u53ef\u6267\u884c\u6587\u4ef6<\/span><\/p>\n<p id=\"0d87425918227c043999d7b7536294ac\" class=\"ne-p\"><span class=\"ne-text\">\u6267\u884c\u9879\u76ee<\/span><\/p>\n<p id=\"c034c3654441b267e64ef696f0b25812\" class=\"ne-p\"><span class=\"ne-text\">$ <\/span><strong><span class=\"ne-text\">.\/hello<\/span><\/strong><\/p>\n<p id=\"3c19397c2ca85b1a91c4627d9d1a9936\" class=\"ne-p\"><span class=\"ne-text\">hello, world<\/span><\/p>\n<p id=\"ca70f0b212e2cc934600e62eb711314f\" class=\"ne-p\"><span class=\"ne-text\">If you see the &#8220;hello, world&#8221; message then your Go installation is working<\/span><\/p>\n<p id=\"10ba4c79fb1da209201b50a5219a23c1\" class=\"ne-p\"><span class=\"ne-text\">\u00a0<\/span><\/p>\n<p id=\"79d63ada020797ee90f21b3a6e285410\" class=\"ne-p\"><span class=\"ne-text\">\u5b98\u7f51\u7248\u672c\u4f7f\u7528\u4ecb\u7ecd\uff1a<\/span><a class=\"ne-link\" href=\"https:\/\/golang.google.cn\/doc\/install?download=go1.13.6.linux-amd64.tar.gz\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/golang.google.cn\/doc\/install?download=go1.13.6.linux-amd64.tar.gz\"><span class=\"ne-text\">https:\/\/golang.google.cn\/doc\/install?download=go<\/span><\/a><span class=\"ne-text\">1.15.3<\/span><a class=\"ne-link\" href=\"https:\/\/golang.google.cn\/doc\/install?download=go1.13.6.linux-amd64.tar.gz\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/golang.google.cn\/doc\/install?download=go1.13.6.linux-amd64.tar.gz\"><span class=\"ne-text\">.linux-amd64.tar.gz<\/span><\/a><span class=\"ne-text\">\u00a0 \u00a0\uff08go<\/span><span class=\"ne-text\">1.15.3<\/span><span class=\"ne-text\">.linux-amd64.tar.gz\u7248\u672c\uff09<\/span><\/p>\n<h1 id=\"jD0RL\"><span class=\"ne-text\">3 Goproxy \u914d\u7f6ego\u5e93\u4ee3\u7406<\/span><\/h1>\n<p id=\"13956d808d3e034a420cb989093592a8\" class=\"ne-p\"><span class=\"ne-text\">\u4e2d\u56fd\u6700\u53ef\u9760\u7684 Go \u6a21\u5757\u4ee3\u7406\u3002<\/span><\/p>\n<p id=\"c4674b41afea9c5df343161a91c1cdac\" class=\"ne-p\"><span class=\"ne-text\">Goproxy \u4e2d\u56fd\u5b8c\u5168\u5b9e\u73b0\u4e86 Go \u7684<\/span><a class=\"ne-link\" href=\"https:\/\/golang.org\/cmd\/go\/#hdr-Module_proxy_protocol\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/golang.org\/cmd\/go\/#hdr-Module_proxy_protocol\"><span class=\"ne-text\">\u6a21\u5757\u4ee3\u7406\u534f\u8bae<\/span><\/a><span class=\"ne-text\">\u3002\u5e76\u4e14\u5b83\u662f\u4e00\u4e2a\u7531\u4e2d\u56fd\u5907\u53d7\u4fe1\u8d56\u7684\u4e91\u670d\u52a1\u63d0\u4f9b\u5546<\/span><a class=\"ne-link\" href=\"https:\/\/www.qiniu.com\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/www.qiniu.com\/\"><span class=\"ne-text\">\u4e03\u725b\u4e91<\/span><\/a><span class=\"ne-text\">\u652f\u6301\u7684\u975e\u8425\u5229\u6027\u9879\u76ee\u3002\u6211\u4eec\u7684\u76ee\u6807\u662f\u4e3a\u4e2d\u56fd\u548c\u4e16\u754c\u4e0a\u5176\u4ed6\u5730\u65b9\u7684 Gopher \u4eec\u63d0\u4f9b\u4e00\u4e2a\u514d\u8d39\u7684\u3001\u53ef\u9760\u7684\u3001\u6301\u7eed\u5728\u7ebf\u7684\u4e14\u7ecf\u8fc7 CDN \u52a0\u901f\u7684\u6a21\u5757\u4ee3\u7406\u3002\u8bf7\u5728 <\/span><a class=\"ne-link\" href=\"https:\/\/status.goproxy.cn\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/status.goproxy.cn\/\"><span class=\"ne-text\">status.goproxy.cn<\/span><\/a><span class=\"ne-text\"> \u8ba2\u9605\u6211\u4eec\u7684\u6709\u5173\u7cfb\u7edf\u6027\u80fd\u7684\u5b9e\u65f6\u548c\u5386\u53f2\u6570\u636e\u3002<\/span><\/p>\n<p id=\"146f5e6558b3576fd79be2af53f28a51\" class=\"ne-p\"><span class=\"ne-text\">\u8bf7\u6ce8\u610f\uff0cGoproxy \u4e2d\u56fd\u53ea\u4e13\u6ce8\u4e8e\u670d\u52a1\u5728 <\/span><a class=\"ne-link\" href=\"https:\/\/goproxy.cn\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/goproxy.cn\/\"><span class=\"ne-text\">https:\/\/goproxy.cn<\/span><\/a><span class=\"ne-text\"> \u7684 Web \u5e94\u7528\u672c\u8eab\u7684\u5f00\u53d1\u3002\u5982\u679c\u4f60\u6b63\u5728\u5bfb\u627e\u4e00\u79cd\u6781\u5176\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u642d\u5efa\u4f60\u81ea\u5df1\u7684 Go \u6a21\u5757\u4ee3\u7406\uff0c\u90a3\u4e48\u4f60\u5e94\u8be5\u770b\u4e00\u4e0b <\/span><a class=\"ne-link\" href=\"https:\/\/github.com\/goproxy\/goproxy\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/goproxy\/goproxy\"><span class=\"ne-text\">Goproxy<\/span><\/a><span class=\"ne-text\">\uff0cGoproxy \u4e2d\u56fd\u5c31\u662f\u57fa\u4e8e\u5b83\u5f00\u53d1\u7684\u3002<\/span><\/p>\n<p id=\"2fcb92d0c39dba910e111e1836605b50\" class=\"ne-p\"><span class=\"ne-text\">\u6109\u5feb\u5730\u7f16\u7801\u5427\uff0cGopher \u4eec\uff01;-)<\/span><\/p>\n<p id=\"e0c2658c1576d6ef5bc0e949c98244a7\" class=\"ne-p\"><strong><em><span class=\"ne-text\">\u6ce8\u610f\uff0c\u4e3a\u4e86\u5e2e\u52a9 Gopher \u4eec\u66f4\u597d\u5730\u53bb\u4f7f\u7528 Go \u6a21\u5757\uff0cGoproxy \u4e2d\u56fd\u73b0\u5728\u652f\u6301\u56de\u7b54\u548c Go \u6a21\u5757\u76f8\u5173\u7684\u6240\u6709\u95ee\u9898\uff08\u4e0d\u518d\u53ea\u662f\u548c Go \u6a21\u5757\u4ee3\u7406\u76f8\u5173\u7684\uff09\uff0c\u4f60\u53ea\u9700\u8981\u9075\u5faa Issue \u6a21\u7248\u5c06\u95ee\u9898\u53d1\u8868\u5728<\/span><\/em><\/strong><a class=\"ne-link\" href=\"https:\/\/github.com\/goproxy\/goproxy.cn\/issues\/new?assignees=&amp;labels=&amp;template=new-question.zh-CN.md&amp;title=%E9%97%AE%E9%A2%98%EF%BC%9A\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/goproxy\/goproxy.cn\/issues\/new?assignees=&amp;labels=&amp;template=new-question.zh-CN.md&amp;title=%E9%97%AE%E9%A2%98%EF%BC%9A\"><strong><em><span class=\"ne-text\">\u8fd9\u91cc<\/span><\/em><\/strong><\/a><strong><em><span class=\"ne-text\">\u5373\u53ef\u3002\u522b\u5fd8\u4e86\u5148\u53bb\u68c0\u67e5\u6211\u4eec\u7684<\/span><\/em><\/strong><a class=\"ne-link\" href=\"https:\/\/goproxy.cn\/faq\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/goproxy.cn\/faq\"><strong><em><span class=\"ne-text\">\u5e38\u89c1\u95ee\u9898<\/span><\/em><\/strong><\/a><strong><em><span class=\"ne-text\">\u9875\u9762\u4e2d\u662f\u5426\u5df2\u7ecf\u6709\u4e86\u4f60\u60f3\u8981\u8be2\u95ee\u7684\u95ee\u9898\u3002<\/span><\/em><\/strong><\/p>\n<h2 id=\"lL0pX\"><span class=\"ne-text\">\u7528\u6cd5<\/span><\/h2>\n<h3 id=\"NeTNI\"><span class=\"ne-text\">Go 1.13 \u53ca\u4ee5\u4e0a\uff08\u63a8\u8350\uff09<\/span><\/h3>\n<p id=\"4a885032e269e85eebe0351cdd30e9fd\" class=\"ne-p\"><span class=\"ne-text\">\u6253\u5f00\u4f60\u7684\u7ec8\u7aef\u5e76\u6267\u884c<\/span><\/p>\n<p id=\"48b9fa02077d7dea6896d3048e686857\" class=\"ne-p\"><span class=\"ne-text\">$ go env -w GO111MODULE=on<\/span><\/p>\n<p id=\"b45c7e25ae6477eb91f4706c4bc44abc\" class=\"ne-p\"><span class=\"ne-text\">$ go env -w GOPROXY=https:\/\/goproxy.cn,direct<\/span><\/p>\n<p id=\"5204b072567c11b68228cd952e9b12cf\" class=\"ne-p\"><span class=\"ne-text\">\u5b8c\u6210\u3002<\/span><\/p>\n<h3 id=\"VKRpz\"><span class=\"ne-text\">macOS \u6216 Linux<\/span><\/h3>\n<p id=\"46fd6097d01d07a1c793955e53a86ec5\" class=\"ne-p\"><span class=\"ne-text\">\u6253\u5f00\u4f60\u7684\u7ec8\u7aef\u5e76\u6267\u884c<\/span><\/p>\n<p id=\"2d294999668cd297dcba0a13deef3e11\" class=\"ne-p\"><span class=\"ne-text\">$ <\/span><span class=\"ne-text\">export<\/span><span class=\"ne-text\"> GO111MODULE=on<\/span><\/p>\n<p id=\"5a7ed32374436d6981d79acf51297340\" class=\"ne-p\"><span class=\"ne-text\">$ <\/span><span class=\"ne-text\">export<\/span><span class=\"ne-text\"> GOPROXY=https:\/\/goproxy.cn<\/span><\/p>\n<p id=\"2f09a1498c97d23b540ac698e3d49a98\" class=\"ne-p\"><span class=\"ne-text\">\u6216\u8005<\/span><\/p>\n<p id=\"2225fd9170dfe9e33c8a4eded2f4118d\" class=\"ne-p\"><span class=\"ne-text\">$ <\/span><span class=\"ne-text\">echo<\/span> <span class=\"ne-text\">&#8220;<\/span><span class=\"ne-text\">export GO111MODULE=on<\/span><span class=\"ne-text\">&#8220;<\/span> <span class=\"ne-text\">&gt;&gt;<\/span> <span class=\"ne-text\">~<\/span><span class=\"ne-text\">\/.profile<\/span><\/p>\n<p id=\"0dbc03603da3bd0e22653d5d1001ecb7\" class=\"ne-p\"><span class=\"ne-text\">$ <\/span><span class=\"ne-text\">echo<\/span> <span class=\"ne-text\">&#8220;<\/span><span class=\"ne-text\">export GOPROXY=https:\/\/goproxy.cn<\/span><span class=\"ne-text\">&#8220;<\/span> <span class=\"ne-text\">&gt;&gt;<\/span> <span class=\"ne-text\">~<\/span><span class=\"ne-text\">\/.profile<\/span><\/p>\n<p id=\"1a52cd0bf6e1105bd0d7ea648ca66f1c\" class=\"ne-p\"><span class=\"ne-text\">$ <\/span><span class=\"ne-text\">source<\/span> <span class=\"ne-text\">~<\/span><span class=\"ne-text\">\/.profile<\/span><\/p>\n<p id=\"ec40d4839d8345382eab23d5847b045a\" class=\"ne-p\"><span class=\"ne-text\">\u5b8c\u6210\u3002<\/span><\/p>\n<h3 id=\"sX3hb\"><span class=\"ne-text\">Windows<\/span><\/h3>\n<p id=\"d19675613e26f0430b1ffc342b0b567c\" class=\"ne-p\"><span class=\"ne-text\">\u6253\u5f00\u4f60\u7684 PowerShell \u5e76\u6267\u884c<\/span><\/p>\n<p id=\"ff81f5d3de3e5af1e1e65cf8e0e52c44\" class=\"ne-p\"><span class=\"ne-text\">C:\\<\/span><span class=\"ne-text\">&gt;<\/span> <span class=\"ne-text\">$<\/span><span class=\"ne-text\">env:<\/span><span class=\"ne-text\">GO111MODULE<\/span> <span class=\"ne-text\">=<\/span> <span class=\"ne-text\">&#8220;<\/span><span class=\"ne-text\">on<\/span><span class=\"ne-text\">&#8220;<\/span><\/p>\n<p id=\"4e70f4dc228bc08b260e47ad09f65247\" class=\"ne-p\"><span class=\"ne-text\">C:\\<\/span><span class=\"ne-text\">&gt;<\/span> <span class=\"ne-text\">$<\/span><span class=\"ne-text\">env:<\/span><span class=\"ne-text\">GOPROXY<\/span> <span class=\"ne-text\">=<\/span> <span class=\"ne-text\">&#8220;<\/span><a class=\"ne-link\" href=\"https:\/\/goproxy.cn\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/goproxy.cn\"><span class=\"ne-text\">https:\/\/goproxy.cn<\/span><\/a><span class=\"ne-text\">&#8220;<\/span><\/p>\n<p id=\"8cd46421a4f2deb9dad7f72bf5e8b1f7\" class=\"ne-p\"><span class=\"ne-text\">\u6216\u8005<\/span><\/p>\n<p id=\"7c390736eb0555d559668906e7fddc93\" class=\"ne-p\"><span class=\"ne-text\">1<\/span><span class=\"ne-text\">. \u6253\u5f00\u201c\u5f00\u59cb\u201d\u5e76\u641c\u7d22\u201cenv\u201d<\/span><\/p>\n<p id=\"afa558fd825d3d944c0c6bf592d6f9fc\" class=\"ne-p\"><span class=\"ne-text\">2<\/span><span class=\"ne-text\">. \u9009\u62e9\u201c\u7f16\u8f91\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u201d<\/span><\/p>\n<p id=\"6aa918217c127aca3593f3e2949a2794\" class=\"ne-p\"><span class=\"ne-text\">3<\/span><span class=\"ne-text\">. \u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u2026\u201d\u6309\u94ae<\/span><\/p>\n<p id=\"ffc4820f2a936b1f54716a520ed832f1\" class=\"ne-p\"><span class=\"ne-text\">4<\/span><span class=\"ne-text\">. \u5728\u201c&lt;\u4f60\u7684\u7528\u6237\u540d&gt; \u7684\u7528\u6237\u53d8\u91cf\u201d\u7ae0\u8282\u4e0b\uff08\u4e0a\u534a\u90e8\u5206\uff09<\/span><\/p>\n<p id=\"3d3866f4343409967d98c2c36fc5d907\" class=\"ne-p\"><span class=\"ne-text\">5<\/span><span class=\"ne-text\">. \u70b9\u51fb\u201c\u65b0\u5efa\u2026\u201d\u6309\u94ae<\/span><\/p>\n<p id=\"2d722bf83a6b3047c33228e52fb4bf65\" class=\"ne-p\"><span class=\"ne-text\">6<\/span><span class=\"ne-text\">. \u9009\u62e9\u201c\u53d8\u91cf\u540d\u201d\u8f93\u5165\u6846\u5e76\u8f93\u5165\u201cGO111MODULE\u201d<\/span><\/p>\n<p id=\"745f0d2868e42929749080748b5b56ea\" class=\"ne-p\"><span class=\"ne-text\">7<\/span><span class=\"ne-text\">. \u9009\u62e9\u201c\u53d8\u91cf\u503c\u201d\u8f93\u5165\u6846\u5e76\u8f93\u5165\u201con\u201d<\/span><\/p>\n<p id=\"d90187203c3f20cbeb8ff02b271246f6\" class=\"ne-p\"><span class=\"ne-text\">8<\/span><span class=\"ne-text\">. \u70b9\u51fb\u201c\u786e\u5b9a\u201d\u6309\u94ae<\/span><\/p>\n<p id=\"0d637b2dfc45808f3880718681ef46a8\" class=\"ne-p\"><span class=\"ne-text\">9<\/span><span class=\"ne-text\">. \u70b9\u51fb\u201c\u65b0\u5efa\u2026\u201d\u6309\u94ae<\/span><\/p>\n<p id=\"589c0e29784ef802921958a632fcd6fd\" class=\"ne-p\"><span class=\"ne-text\">10<\/span><span class=\"ne-text\">. \u9009\u62e9\u201c\u53d8\u91cf\u540d\u201d\u8f93\u5165\u6846\u5e76\u8f93\u5165\u201cGOPROXY\u201d<\/span><\/p>\n<p id=\"9a233128fded9eef3580a900b9330691\" class=\"ne-p\"><span class=\"ne-text\">11<\/span><span class=\"ne-text\">. \u9009\u62e9\u201c\u53d8\u91cf\u503c\u201d\u8f93\u5165\u6846\u5e76\u8f93\u5165\u201c<\/span><a class=\"ne-link\" href=\"https:\/\/goproxy.cn\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/goproxy.cn\"><span class=\"ne-text\">https:\/\/goproxy.cn<\/span><\/a><span class=\"ne-text\">\u201d<\/span><\/p>\n<p id=\"68387ab5cbf46769906890da6e625afe\" class=\"ne-p\"><span class=\"ne-text\">12<\/span><span class=\"ne-text\">. \u70b9\u51fb\u201c\u786e\u5b9a\u201d\u6309\u94ae<\/span><\/p>\n<p id=\"445a83fe6166ab635dfa79a0397142c8\" class=\"ne-p\"><span class=\"ne-text\">\u5b8c\u6210\u3002<\/span><\/p>\n<h2 id=\"cHP8z\"><span class=\"ne-text\">\u5e38\u89c1\u95ee\u9898<\/span><\/h2>\n<h3 id=\"fBuRT\"><span class=\"ne-text\">\u4e3a\u4ec0\u4e48\u521b\u5efa Goproxy \u4e2d\u56fd\uff1f<\/span><\/h3>\n<p id=\"e811dc63e4796fa945b29be194e14f9c\" class=\"ne-p\"><span class=\"ne-text\">\u7531\u4e8e\u4e2d\u56fd\u653f\u5e9c\u7684\u7f51\u7edc\u76d1\u7ba1\u7cfb\u7edf\uff0cGo \u751f\u6001\u7cfb\u7edf\u4e2d\u6709\u7740\u8bb8\u591a\u4e2d\u56fd Gopher \u4eec\u65e0\u6cd5\u83b7\u53d6\u7684\u6a21\u5757\uff0c\u6bd4\u5982\u6700\u8457\u540d\u7684 <\/span><code class=\"ne-code\"><span class=\"ne-text\">golang.org\/x\/...<\/span><\/code><span class=\"ne-text\">\u3002\u5e76\u4e14\u5728\u4e2d\u56fd\u5927\u9646\u4ece GitHub \u83b7\u53d6\u6a21\u5757\u7684\u901f\u5ea6\u4e5f\u6709\u70b9\u6162\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u521b\u5efa\u4e86 Goproxy \u4e2d\u56fd\uff0c\u4f7f\u5728\u4e2d\u56fd\u7684 Gopher \u4eec\u80fd\u66f4\u597d\u5730\u4f7f\u7528 Go \u6a21\u5757\u3002\u4e8b\u5b9e\u4e0a\uff0c\u7531\u4e8e <\/span><a class=\"ne-link\" href=\"https:\/\/goproxy.cn\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/goproxy.cn\/\"><span class=\"ne-text\">goproxy.cn<\/span><\/a><span class=\"ne-text\">\u5df2\u901a\u8fc7 CDN \u52a0\u901f\uff0c\u6240\u4ee5\u5176\u4ed6\u56fd\u5bb6\u7684 Gopher \u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5b83\u3002<\/span><\/p>\n<h3 id=\"JnNxb\"><span class=\"ne-text\">\u4f7f\u7528 Goproxy \u4e2d\u56fd\u662f\u5426\u5b89\u5168\uff1f<\/span><\/h3>\n<p id=\"0d89fdf4655e2877aed8c560a3c2bb2d\" class=\"ne-p\"><span class=\"ne-text\">\u5f53\u7136\uff0c\u548c\u6240\u6709\u5176\u4ed6\u7684 Go \u6a21\u5757\u4ee3\u7406\u4e00\u6837\uff0c\u6211\u4eec\u53ea\u662f\u5c06\u6a21\u5757\u539f\u5c01\u4e0d\u52a8\u5730\u7f13\u5b58\u8d77\u6765\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5411\u4f60\u4fdd\u8bc1\u5b83\u4eec\u7edd\u5bf9\u4e0d\u4f1a\u5728\u6211\u4eec\u8fd9\u8fb9\u88ab\u7be1\u6539\u3002\u4e0d\u8fc7\uff0c\u5982\u679c\u4f60\u8fd8\u662f\u4e0d\u80fd\u591f\u5b8c\u5168\u4fe1\u4efb\u6211\u4eec\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u4f7f\u7528\u6700\u503c\u5f97\u4fe1\u4efb\u7684\u6821\u9a8c\u548c\u6570\u636e\u5e93 <\/span><a class=\"ne-link\" href=\"https:\/\/sum.golang.org\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/sum.golang.org\/\"><span class=\"ne-text\">sum.golang.org<\/span><\/a><span class=\"ne-text\"> \u6765\u786e\u4fdd\u4f60\u4ece\u6211\u4eec\u8fd9\u91cc\u83b7\u53d6\u7684\u6a21\u5757\u6ca1\u6709\u88ab\u7be1\u6539\u8fc7\uff0c\u56e0\u4e3a Goproxy \u4e2d\u56fd\u5df2\u7ecf\u652f\u6301\u4e86<\/span><a class=\"ne-link\" href=\"https:\/\/golang.org\/design\/25530-sumdb#proxying-a-checksum-database\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/golang.org\/design\/25530-sumdb#proxying-a-checksum-database\"><span class=\"ne-text\">\u4ee3\u7406\u6821\u9a8c\u548c\u6570\u636e\u5e93<\/span><\/a><span class=\"ne-text\">\u3002<\/span><\/p>\n<h3 id=\"Q9WzS\"><span class=\"ne-text\">Goproxy \u4e2d\u56fd\u5728\u4e2d\u56fd\u662f\u5408\u6cd5\u7684\u5417\uff1f<\/span><\/h3>\n<p id=\"fa859b6ab03b823853c664e7296318fe\" class=\"ne-p\"><span class=\"ne-text\">Goproxy \u4e2d\u56fd\u662f\u4e00\u4e2a\u7531\u5546\u4e1a\u652f\u6301\u7684\u9879\u76ee\u800c\u4e0d\u662f\u4e00\u4e2a\u4e2a\u4eba\u9879\u76ee\u3002\u5e76\u4e14\u5b83\u5df2\u7ecf ICP \u5907\u6848\u5728\u4e2d\u534e\u4eba\u6c11\u5171\u548c\u56fd\u5de5\u4e1a\u548c\u4fe1\u606f\u5316\u90e8\uff08ICP \u5907\u6848\u53f7\uff1a<\/span><a class=\"ne-link\" href=\"http:\/\/beian.miit.gov.cn\/\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/beian.miit.gov.cn\/\"><span class=\"ne-text\">\u6caaICP\u590711037377\u53f7-56<\/span><\/a><span class=\"ne-text\">\uff09\uff0c\u8fd9\u4e5f\u5c31\u610f\u5473\u7740\u5b83\u5728\u4e2d\u56fd\u5b8c\u5168\u5408\u6cd5\u3002<\/span><\/p>\n<h3 id=\"vO9bV\"><span class=\"ne-text\">\u4e3a\u4ec0\u4e48\u4e0d\u4f7f\u7528 <\/span><a class=\"ne-link\" href=\"https:\/\/proxy.golang.org\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/proxy.golang.org\/\"><span class=\"ne-text\">proxy.golang.org<\/span><\/a><span class=\"ne-text\">\uff1f<\/span><\/h3>\n<p id=\"102475f4d8b859de9f3873f283d57631\" class=\"ne-p\"><span class=\"ne-text\">\u56e0\u4e3a <\/span><a class=\"ne-link\" href=\"https:\/\/proxy.golang.org\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/proxy.golang.org\/\"><span class=\"ne-text\">proxy.golang.org<\/span><\/a><span class=\"ne-text\"> \u5728\u4e2d\u56fd\u5927\u9646\u88ab\u5c4f\u853d\u4e86\uff0c\u6240\u4ee5\uff0c\u4e0d\u4f7f\u7528\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60\u4e0d\u5728\u4e2d\u56fd\u5927\u9646\uff0c\u90a3\u4e48\u6211\u4eec\u5efa\u8bae\u4f60\u4f18\u5148\u8003\u8651\u4f7f\u7528 <\/span><a class=\"ne-link\" href=\"https:\/\/proxy.golang.org\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/proxy.golang.org\/\"><span class=\"ne-text\">proxy.golang.org<\/span><\/a><span class=\"ne-text\">\uff0c\u6bd5\u7adf\u5b83\u770b\u8d77\u6765\u66f4\u52a0\u5b98\u65b9\u3002\u4e00\u65e6\u4f60\u8fdb\u5165\u4e86\u4e2d\u56fd\u5927\u9646\uff0c\u6211\u4eec\u5e0c\u671b\u4f60\u80fd\u5728\u7b2c\u4e00\u65f6\u95f4\u60f3\u5230 <\/span><a class=\"ne-link\" href=\"https:\/\/goproxy.cn\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/goproxy.cn\/\"><span class=\"ne-text\">goproxy.cn<\/span><\/a><span class=\"ne-text\">\uff0c\u8fd9\u4e5f\u662f\u6211\u4eec\u9009\u62e9 <\/span><code class=\"ne-code\"><span class=\"ne-text\">.cn<\/span><\/code><span class=\"ne-text\"> \u4f5c\u4e3a\u57df\u540d\u540e\u7f00\u7684\u4e3b\u8981\u539f\u56e0\u3002<\/span><\/p>\n<h3 id=\"hNSys\"><span class=\"ne-text\">\u8c01\u5c06\u56de\u7b54\u6211\u5728<\/span><a class=\"ne-link\" href=\"https:\/\/github.com\/goproxy\/goproxy.cn\/issues\/new?assignees=&amp;labels=&amp;template=questions-related-to-go-modules.zh-CN.md&amp;title=Go+%E6%A8%A1%E5%9D%97%EF%BC%9A\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/goproxy\/goproxy.cn\/issues\/new?assignees=&amp;labels=&amp;template=questions-related-to-go-modules.zh-CN.md&amp;title=Go+%E6%A8%A1%E5%9D%97%EF%BC%9A\"><span class=\"ne-text\">\u8fd9\u91cc<\/span><\/a><span class=\"ne-text\">\u8be2\u95ee\u7684\u95ee\u9898\uff1f<\/span><\/h3>\n<p id=\"4f6ea9c522ee956da8c18f93382c014c\" class=\"ne-p\"><span class=\"ne-text\">Goproxy \u4e2d\u56fd\u7684\u6210\u5458\u4ee5\u53ca\u6211\u4eec\u4f1f\u5927\u7684 Go \u793e\u533a\u4e2d\u70ed\u5fc3\u80a0\u7684\u5fd7\u613f\u8005\u4eec\u3002\u8bf7\u7262\u8bb0\uff0c\u4e3a\u4e86\u51cf\u8f7b\u4ed6\u4eba\u7684\u5de5\u4f5c\u91cf\uff0c\u522b\u5fd8\u4e86\u5148\u53bb\u68c0\u67e5\u6211\u4eec\u7684<\/span><a class=\"ne-link\" href=\"https:\/\/goproxy.cn\/faq\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/goproxy.cn\/faq\"><span class=\"ne-text\">\u5e38\u89c1\u95ee\u9898<\/span><\/a><span class=\"ne-text\">\u9875\u9762\u4e2d\u662f\u5426\u5df2\u7ecf\u6709\u4e86\u4f60\u60f3\u8981\u95ee\u7684\u95ee\u9898\u3002<\/span><\/p>\n<p id=\"12071d0dae534d94d761e76ccfb30a8d\" class=\"ne-p\"><strong><em><span class=\"ne-text\">\u522b\u5fd8\u4e86\u67e5\u770b\u6211\u4eec\u7684<\/span><\/em><\/strong><a class=\"ne-link\" href=\"https:\/\/goproxy.cn\/faq\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/goproxy.cn\/faq\"><strong><em><span class=\"ne-text\">\u5e38\u89c1\u95ee\u9898<\/span><\/em><\/strong><\/a><strong><em><span class=\"ne-text\">\u9875\u9762\u4ee5\u83b7\u53d6\u66f4\u591a\u7684\u5185\u5bb9\u3002<\/span><\/em><\/strong><\/p>\n<h2 id=\"9bna1\"><span class=\"ne-text\">\u529f\u52b3<\/span><\/h2>\n<ul class=\"ne-ul\">\n<li id=\"4b2414aea6b149b9e9e48699c2637d58\"><span class=\"ne-text\">\u4f5c\u8005\uff1a<\/span><a class=\"ne-link\" href=\"https:\/\/aofeisheng.com\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/aofeisheng.com\/\"><span class=\"ne-text\">\u76db\u50b2\u98de<\/span><\/a><\/li>\n<li id=\"099b871c53fed4d3f32af8eb3e5fa5ea\"><span class=\"ne-text\">\u7ef4\u62a4\u8005\uff1a<\/span><a class=\"ne-link\" href=\"https:\/\/aofeisheng.com\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/aofeisheng.com\/\"><span class=\"ne-text\">\u76db\u50b2\u98de<\/span><\/a><\/li>\n<\/ul>\n<ul class=\"ne-ul\">\n<li id=\"f36a9b28ddbd6a5156f02bfbf30900a4\"><span class=\"ne-text\">\u8d5e\u52a9\u5546\uff1a<\/span><a class=\"ne-link\" href=\"https:\/\/www.qiniu.com\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/www.qiniu.com\/\"><span class=\"ne-text\">\u4e03\u725b\u4e91<\/span><\/a><\/li>\n<li id=\"0753d0f20615b144919ad48e2c40ab79\"><span class=\"ne-text\">\u63a8\u52a8\u8005\uff1a<\/span><a class=\"ne-link\" href=\"https:\/\/baike.baidu.com\/item\/%E8%AE%B8%E5%BC%8F%E4%BC%9F\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/baike.baidu.com\/item\/%E8%AE%B8%E5%BC%8F%E4%BC%9F\"><span class=\"ne-text\">\u8bb8\u5f0f\u4f1f\uff08\u4e03\u725b\u4e91\u7684\u521b\u59cb\u4eba\u517c\u9996\u5e2d\u6267\u884c\u5b98\uff09<\/span><\/a><span class=\"ne-text\">\u3001\u9676\u7eaf\u5802\u3001<\/span><a class=\"ne-link\" href=\"https:\/\/github.com\/forrest-mao\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/forrest-mao\"><span class=\"ne-text\">\u8305\u529b\u592b<\/span><\/a><span class=\"ne-text\">\u548c<\/span><a class=\"ne-link\" href=\"https:\/\/github.com\/eddycjy\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/eddycjy\"><span class=\"ne-text\">\u9648\u5251\u715c<\/span><\/a><\/li>\n<\/ul>\n<h1 id=\"5yLpb\"><span class=\"ne-text\">4 etcd\u5355\u673a\u542f\u52a8<\/span><\/h1>\n<p id=\"9683538eacc8c411e9cf774e7a1c7e67\" class=\"ne-p\"><span class=\"ne-text\">\u7f51\u4e0a\u5230\u5904\u90fd\u662f\u600e\u4e48\u542f\u52a8etcd\u96c6\u7fa4\u6a21\u5f0f\uff0c\u5f88\u5c11\u6709\u4eba\u4ecb\u7ecd\u5982\u4f55\u542f\u52a8\u5355\u673a\u6a21\u5f0f<\/span><\/p>\n<pre id=\"ECdJ8\" class=\"ne-codeblock\" data-language=\"bash\">sudo .\/etcd  --data-dir .\/data.etcd\/  --listen-client-urls http:\/\/0.0.0.0:2379 --advertise-client-urls http:\/\/0.0.0.0:2379  --enable-v2 &amp; &gt;.\/log\/etcd.log<\/pre>\n<h2 id=\"ug8ZS\"><span class=\"ne-text\">-listen-client-urls<\/span><\/h2>\n<pre id=\"agejE\" class=\"ne-codeblock\" data-language=\"plain\">\u7528\u4e8e\u6307\u5b9aetcd\u548c\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u7aef\u53e3<\/pre>\n<h2 id=\"MdvIm\"><span class=\"ne-text\">-advertise-client-urls<\/span><\/h2>\n<pre id=\"3o0f7\" class=\"ne-codeblock\" data-language=\"plain\">\u7528\u4e8e\u6307\u5b9aetcd\u670d\u52a1\u5668\u4e4b\u95f4\u901a\u8baf\u7684\u7aef\u53e3<\/pre>\n<pre id=\"HgKGC\" class=\"ne-codeblock\" data-language=\"plain\">etcd\u6709\u8981\u6c42\uff0c\u5982\u679c-listen-client-urls\u88ab\u8bbe\u7f6e\u4e86\uff0c\u90a3\u4e48\u5c31\u5fc5\u987b\u540c\u65f6\u8bbe\u7f6e-advertise-client-urls\uff0c\u6240\u4ee5\u5373\u4f7f\u8bbe\u7f6e\u548c\u9ed8\u8ba4\u76f8\u540c\uff0c\u4e5f\u5fc5\u987b\u663e\u5f0f\u8bbe\u7f6e.<\/pre>\n<p id=\"2a6361f2d0fb17835bb12fd03a30f143\" class=\"ne-p\"><span class=\"ne-text\">172.17.0.13<\/span><\/p>\n<h1 id=\"Gq6w9\"><span class=\"ne-text\">\uff15\u6b65\u5b8c\u6210etcd\u5355\u673a\u96c6\u7fa4\u90e8\u7f72<\/span><\/h1>\n<h2 id=\"-etcd\"><span class=\"ne-text\">5.1 \u4e0b\u8f7d etcd<\/span><\/h2>\n<p id=\"5ce43c45809747c46f25883161fde1be\" class=\"ne-p\"><span class=\"ne-text\">\u76f8\u5173\u7248\u672c\u5728\uff1a<\/span><a class=\"ne-link\" href=\"https:\/\/github.com\/etcd-io\/etcd\/releases\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/etcd-io\/etcd\/releases\/\"><span class=\"ne-text\">https:\/\/github.com\/etcd-io\/etcd\/releases\/<\/span><\/a><\/p>\n<p id=\"6a02583f583cb329c83f04b6646d0bb9\" class=\"ne-p\"><span class=\"ne-text\">\u8fd9\u91cc\u4ee5ubuntu x64\u4e3e\u4f8b:<\/span><\/p>\n<pre id=\"XP8Yn\" class=\"ne-codeblock\" data-language=\"plain\">wget https:\/\/github.com\/etcd-io\/etcd\/releases\/download\/v3.4.0-rc.3\/etcd-v3.4.0-rc.3-linux-amd64.tar.gz<\/pre>\n<h2 id=\"-\"><span class=\"ne-text\">5.2 \u521b\u5efa\u5982\u4e0b\u76ee\u5f55\u7ed3\u6784<\/span><\/h2>\n<p id=\"a2ff7a0b46ac2acd3cc1b39ae295a31a\" class=\"ne-p\"><img decoding=\"async\" id=\"UvvYO\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603807645140-d13349af-c22d-4d71-880f-dcaa738332b6.png\" width=\"674\" \/><\/p>\n<h2 id=\"irsbZ\"><span class=\"ne-text\">5.3 \u65b0\u589e\u4e09\u4e2a\u914d\u7f6e\u6587\u4ef6<\/span><\/h2>\n<p id=\"c9dad14149241fff3479b5b22e7c559b\" class=\"ne-p\"><span class=\"ne-text\">etcd1\/etcd.conf \u914d\u7f6e\u6587\u4ef6:<\/span><\/p>\n<pre id=\"P9m4l\" class=\"ne-codeblock\" data-language=\"plain\">name: etcd-1\r\ndata-dir: \/home\/xmge\/show\/etcd_cluster\/etcd1\/data   \/\/ \u9700\u8981\u6307\u5b9a\u81ea\u5df1\u76ee\u5f55\u4e0b\u7684\u4f4d\u7f6e\r\nlisten-client-urls: http:\/\/0.0.0.0:2379\r\nadvertise-client-urls: http:\/\/127.0.0.1:2379\r\nlisten-peer-urls: http:\/\/0.0.0.0:2380\r\ninitial-advertise-peer-urls: http:\/\/127.0.0.1:2380\r\ninitial-cluster: etcd-1=http:\/\/127.0.0.1:2380,etcd-2=http:\/\/127.0.0.1:2480,etcd-3=http:\/\/127.0.0.1:2580\r\ninitial-cluster-token: etcd-cluster-my\r\ninitial-cluster-state: new<\/pre>\n<p id=\"f011250ade54343ce839e8879c69d92b\" class=\"ne-p\"><span class=\"ne-text\">etcd2\/etcd.conf \u914d\u7f6e\u6587\u4ef6:<\/span><\/p>\n<pre id=\"rh8vc\" class=\"ne-codeblock\" data-language=\"plain\">name: etcd-2\r\ndata-dir: \/home\/xmge\/show\/etcd_cluster\/etcd2\/data   \/\/ \u9700\u8981\u6307\u5b9a\u81ea\u5df1\u76ee\u5f55\u4e0b\u7684\u4f4d\u7f6e\r\nlisten-client-urls: http:\/\/0.0.0.0:2479\r\nadvertise-client-urls: http:\/\/127.0.0.1:2479\r\nlisten-peer-urls: http:\/\/0.0.0.0:2480\r\ninitial-advertise-peer-urls: http:\/\/127.0.0.1:2480\r\ninitial-cluster: etcd-1=http:\/\/127.0.0.1:2380,etcd-2=http:\/\/127.0.0.1:2480,etcd-3=http:\/\/127.0.0.1:2580\r\ninitial-cluster-token: etcd-cluster-my\r\ninitial-cluster-state: new<\/pre>\n<p id=\"b47f96803de75c93092734dc1c350738\" class=\"ne-p\"><span class=\"ne-text\">etcd3\/etcd.conf \u914d\u7f6e\u6587\u4ef6\uff1a<\/span><\/p>\n<pre id=\"ghgPg\" class=\"ne-codeblock\" data-language=\"plain\">name: etcd-3\r\ndata-dir: \/home\/xmge\/show\/etcd_cluster\/etcd3\/data   \/\/ \u9700\u8981\u6307\u5b9a\u81ea\u5df1\u76ee\u5f55\u4e0b\u7684\u4f4d\u7f6e\r\nlisten-client-urls: http:\/\/0.0.0.0:2579\r\nadvertise-client-urls: http:\/\/127.0.0.1:2579\r\nlisten-peer-urls: http:\/\/0.0.0.0:2580\r\ninitial-advertise-peer-urls: http:\/\/127.0.0.1:2580\r\ninitial-cluster: etcd-1=http:\/\/127.0.0.1:2380,etcd-2=http:\/\/127.0.0.1:2480,etcd-3=http:\/\/127.0.0.1:2580\r\ninitial-cluster-token: etcd-cluster-my\r\ninitial-cluster-state: new<\/pre>\n<h2 id=\"-start-sh-\"><span class=\"ne-text\">5.4 \u65b0\u589e\u542f\u52a8\u811a\u672cstart.sh\u5e76\u542f\u52a8<\/span><\/h2>\n<pre id=\"cCfEo\" class=\"ne-codeblock\" data-language=\"plain\">#!\/bin\/bash\r\nCRTDIR=$(pwd)\r\nservers=(\"etcd1\" \"etcd2\" \"etcd3\")\r\nfor server in ${servers[@]}\r\ndo\r\n        cd ${CRTDIR}\/$server\r\n        nohup .\/etcd --config-file=etcd.conf &amp;\r\n        echo $?\r\ndone<\/pre>\n<p id=\"e57bf55a0018a15a11ebdd762d805f79\" class=\"ne-p\"><span class=\"ne-text\">\u542f\u52a8\u96c6\u7fa4<\/span><\/p>\n<pre id=\"zpLev\" class=\"ne-codeblock\" data-language=\"plain\">chmod +x start.sh\r\n.\/start.sh<\/pre>\n<h2 id=\"Zuv6l\"><span class=\"ne-text\">5.5 \u68c0\u9a8c\u96c6\u7fa4\u662f\u5426\u542f\u52a8\u6210\u529f<\/span><\/h2>\n<p id=\"e565c7a20138491cf5e0af99e9d87064\" class=\"ne-p\"><img decoding=\"async\" id=\"ZWHVE\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603807645117-c9e8c0d8-7673-4c73-a322-d0da2a74076f.png\" width=\"891\" \/><\/p>\n<h1 id=\"uHhVy\"><span class=\"ne-text\">6 etcd\u547d\u4ee4\u884c\u63a5\u53e3\u4f7f\u7528<\/span><\/h1>\n<p id=\"509ade5e7c8224cda83e00659a8a21cc\" class=\"ne-p\"><strong><span class=\"ne-text\">\u83b7\u53d6etcd\u7684\u7248\u672c\u53f7<\/span><\/strong><\/p>\n<p id=\"684e0d4a68862013a3c69939b9e7131a\" class=\"ne-p\"><span class=\"ne-text\">curl -L <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/version\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/version\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/version<\/span><\/a><\/p>\n<p id=\"b38e46eed34677647634bed9876e8a83\" class=\"ne-p\"><img decoding=\"async\" id=\"XA2lx\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603866572193-4072daab-cda2-480e-a13b-d241d0e3d16d.png\" width=\"679\" \/><\/p>\n<p id=\"304ccdfb78253b988eb914243ac872d9\" class=\"ne-p\"><span class=\"ne-text\">\u5065\u5eb7\u72b6\u6001<\/span><\/p>\n<p id=\"df6dc9f5ab21f7730d02d375cb68b810\" class=\"ne-p\"><span class=\"ne-text\"> curl -L http:<\/span><span class=\"ne-text\">\/\/<\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/version\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/version\"><span class=\"ne-text\">127.0.0.1<\/span><\/a><span class=\"ne-text\">:2379\/health<\/span><\/p>\n<p id=\"db73d1911a2a1f8bc1db11821497363b\" class=\"ne-p\"><span class=\"ne-text\">{<\/span><span class=\"ne-text\">&#8220;<\/span><span class=\"ne-text\">health<\/span><span class=\"ne-text\">&#8220;<\/span><span class=\"ne-text\">:<\/span><span class=\"ne-text\">&#8220;<\/span><span class=\"ne-text\">true<\/span><span class=\"ne-text\">&#8220;<\/span><span class=\"ne-text\">}<\/span><\/p>\n<p id=\"a08756ea22b4cd35e1704f3178fa9fdd\" class=\"ne-p\"><strong><span class=\"ne-text\">\u8bbe\u7f6e\u4e00\u4e2akey\u7684value<\/span><\/strong><\/p>\n<p id=\"0d9e82598bae297adc3286ebe14b56c3\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/message\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/message\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/message<\/span><\/a><span class=\"ne-text\"> -XPUT -d value=&#8221;Hello world&#8221;<\/span><\/p>\n<p id=\"5925f07d72f894c4f1da2d5097d1c0a0\" class=\"ne-p\"><img decoding=\"async\" id=\"mC2od\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603856840669-c4827541-f29f-4b0b-9533-27e9e9fe678d.png\" width=\"918\" \/><\/p>\n<p id=\"d44d6f60a1642c1acf9942a7abc20b93\" class=\"ne-p\">\n<p id=\"3b596d79bcfea868fc218aa80c5e84cc\" class=\"ne-p\"><strong><span class=\"ne-text\">\u83b7\u53d6\u4e00\u4e2akey\u7684value<\/span><\/strong><\/p>\n<p id=\"30d50f0c8b9430313ebb4e377228332e\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/message\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/message\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/message<\/span><\/a><\/p>\n<p id=\"9e7d435ec9dcaab1e90edeade7f02c2a\" class=\"ne-p\"><img decoding=\"async\" id=\"h4sLd\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603856840667-5b2eb443-bd5f-489d-8662-ca6f202d953e.png\" width=\"925\" \/><\/p>\n<p id=\"9d8a7891b7d330a22491538079f65360\" class=\"ne-p\">\n<p id=\"28659a1a5630d28df510b76bbe5e985f\" class=\"ne-p\"><strong><span class=\"ne-text\">\u6539\u53d8\u4e00\u4e2akey\u7684value<\/span><\/strong><\/p>\n<p id=\"9435df52393bf85370aba8aa7299d52f\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/message\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/message\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/message<\/span><\/a><span class=\"ne-text\"> -XPUT -d value=&#8221;Hello etcd&#8221;<\/span><\/p>\n<p id=\"d709b6af510a665b99ce873f2cf95ab5\" class=\"ne-p\"><img decoding=\"async\" id=\"En6S0\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603856840674-ce28f327-2c14-41d0-a8f9-510ea7b1b276.png\" width=\"922\" \/><\/p>\n<p id=\"74a3030d7485716a772ee30de9e222b3\" class=\"ne-p\">\n<p id=\"1de85b658eab69b86243090e5aa7c761\" class=\"ne-p\"><strong><span class=\"ne-text\">\u5220\u9664\u4e00\u4e2akey\u8282\u70b9<\/span><\/strong><\/p>\n<p id=\"31c72f1e14338c4f0c8123f5dbe9de09\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/message\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/message\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/message<\/span><\/a><span class=\"ne-text\"> -XDELETE<\/span><\/p>\n<p id=\"94ff060e1b73430b0832786d8c319aff\" class=\"ne-p\"><img decoding=\"async\" id=\"GbPfr\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1603856840684-ec68ddf8-36b0-412c-a938-45a26024da6f.png\" width=\"918\" \/><\/p>\n<p id=\"b092ef613a121fd2c3a37dc6e195425a\" class=\"ne-p\"><strong><span class=\"ne-text\">\u4f7f\u7528ttl\uff08\u5373\u8bbe\u7f6e\u4e00\u4e2akey\u7684\u503c\u5e76\u7ed9\u8fd9\u4e2akey\u52a0\u4e00\u4e2a\u751f\u547d\u5468\u671f\uff0c\u5f53\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\u8be5\u503c\u6ca1\u6709\u88ab\u8bbf\u95ee\u5219\u81ea\u52a8\u88ab\u5220\u9664\uff09<\/span><\/strong><\/p>\n<p id=\"71143fc6eb0175ae3b1d1f48c9da540f\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/foo\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/foo\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/foo<\/span><\/a><span class=\"ne-text\"> -XPUT -d value=bar -d ttl=5<\/span><\/p>\n<p id=\"cba7537be5c4fe4d3c735473ac044329\" class=\"ne-p\"><strong><span class=\"ne-text\">\u7b49\u5f85\u4e00\u4e2a\u503c\u7684\u53d8\u5316<\/span><\/strong><\/p>\n<p id=\"a93dc18fa0529c1cd258ec5595913502\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/foo?wait=true\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/foo?wait=true\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/foo?wait=true<\/span><\/a><\/p>\n<p id=\"92880092fa26f2da83d2b39a172eceab\" class=\"ne-p\"><span class=\"ne-text\">\u8be5\u547d\u4ee4\u8c03\u7528\u4e4b\u540e\u4f1a\u963b\u585e\u8fdb\u7a0b\uff0c\u76f4\u5230\u8fd9\u4e2a\u503c\u53d1\u751f\u53d8\u5316\u624d\u80fd\u8fd4\u56de\uff0c\u5f53\u6539\u53d8\u4e00\u4e2akey\u7684\u503c\uff0c\u6216\u8005\u5220\u9664\u7b49\u64cd\u4f5c\u53d1\u751f\u65f6\uff0c\u8be5\u7b49\u5f85<\/span><\/p>\n<p id=\"2efcd9c16c8261c045cab6812ef4a546\" class=\"ne-p\"><strong><span class=\"ne-text\">\u5c31\u4f1a\u8fd4\u56de<\/span><\/strong><\/p>\n<p id=\"60fd3c9d53874a0ef837c2d49104e4f6\" class=\"ne-p\"><span class=\"ne-text\">\u7279\u522b\u6ce8\u610f\uff0c\u5728\u53d8\u5316\u53d1\u751f\u5ea6\u8f83\u9ad8\u7684\u60c5\u51b5\u4e0b\uff0c\u6700\u597d\u628a\u8fd9\u79cd\u53d8\u5316\u7ed3\u679c\u4ea4\u7ed9\u53e6\u5916\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5904\u7406\uff0c\u76d1\u63a7\u7ebf\u7a0b\u7acb\u5373\u8fd4\u56de\u7ee7\u7eed\u76d1\u63a7\u53d8\u5316\u60c5\u51b5\uff0c\u5f53\u7136etcd\u4e5f\u63d0\u4f9b\u4e86\u83b7\u53d6\u5386\u53f2\u53d8\u5316\u7684\u547d\u4ee4\uff0c\u8fd9\u4e2a\u547d\u4ee4\u4ec5\u4e3a\u4e22\u5931\u76d1\u542c\u4e8b\u4ef6\u7684\u60c5\u51b5\u4e0b\u7684\u8865\u6551\u65b9\u6848\u3002<\/span><\/p>\n<p id=\"d27ad9e8b04e1b3a7efe3037366376e9\" class=\"ne-p\">\n<p id=\"1a68d9faf32c1d28e017b41aa59b43fc\" class=\"ne-p\"><strong><span class=\"ne-text\">\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55<\/span><\/strong><\/p>\n<p id=\"1fcdef90a893bdcfe4dc7d6c36d7f98a\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/dir\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/dir\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/dir<\/span><\/a><span class=\"ne-text\"> -XPUT -d dir=true<\/span><\/p>\n<p id=\"dcd3443188ff6ae050b6422c5ad5dc54\" class=\"ne-p\"><strong><span class=\"ne-text\">\u5217\u4e3e\u4e00\u4e2a\u76ee\u5f55<\/span><\/strong><\/p>\n<p id=\"dc35e09c5d35554d42ec33472267b2bd\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/dir\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/dir\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/dir<\/span><\/a><\/p>\n<p id=\"54393c6efd83aabce68c5194a2edf66f\" class=\"ne-p\"><strong><span class=\"ne-text\">\u9012\u5f52\u5217\u4e3e\u4e00\u4e2a\u76ee\u5f55<\/span><\/strong><\/p>\n<p id=\"72a82aed8b079c27d2f5ea3038b525e3\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/dir?recursive=true\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/dir?recursive=true\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/dir?recursive=true<\/span><\/a><\/p>\n<p id=\"30a0d1245f6b4dc1182056a47a3c1125\" class=\"ne-p\"><span class=\"ne-text\">\u5230\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u7ec4\u5408\u4ee5\u4e0a\u7684\u8bf8\u591a\u7528\u6cd5\u5b9e\u73b0\u81ea\u5df1\u60f3\u8981\u7684\u529f\u80fd\u3002\u4f8b\u5982\u76d1\u63a7\u4e00\u4e2a\u76ee\u5f55\u4e0b\u7684\u6240\u6709key\u7684\u53d8\u5316\uff0c\u5305\u62ec\u5b50\u76ee\u5f55\u7684\u3002\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\uff1a<\/span><\/p>\n<p id=\"acfed1e4dcc384cd3d017f811c0e2bb6\" class=\"ne-p\"><span class=\"ne-text\">curl <\/span><a class=\"ne-link\" href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/dir?recursive=true&amp;wait=true\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/127.0.0.1:2379\/v2\/keys\/dir?recursive=true&amp;wait=true\"><span class=\"ne-text\">http:\/\/127.0.0.1:2379\/v2\/keys\/dir?recursive=true&amp;wait=true<\/span><\/a><\/p>\n<p id=\"345a14792498fc2e6a5f298f0b21a43f\" class=\"ne-p\"><strong><span class=\"ne-text\">\u5220\u9664\u4e00\u4e2a\u76ee\u5f55<\/span><\/strong><\/p>\n<p id=\"89ecbd211c21911ad6264de14d6d4576\" class=\"ne-p\"><span class=\"ne-text\">curl &#8216;http:\/\/127.0.0.1:2379\/v2\/keys\/dir?dir=true&#8217; -XDELETE<\/span><\/p>\n<p id=\"4e7d4018ac898ce50de7b87ee3e7d9a0\" class=\"ne-p\"><span class=\"ne-text\">\u547d\u4ee4\u884c\u63a5\u53e3\u5c31\u4ecb\u7ecd\u8fd9\u4e48\u591a\uff0c\u8be6\u7ec6\u53ef\u4ee5\u53c2\u8003\u4e0b\u8f7d\u7684\u5b89\u88c5\u5305\u91cc\u6587\u6863\u91cc\u9762\u7684api.md\u6587\u4ef6\u6709\u66f4\u52a0\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002<\/span><\/p>\n<h1 id=\"articleContentId\"><span class=\"ne-text\">7 etcdAPI \u6587\u6863<\/span><\/h1>\n<p id=\"85e91fb571391d5cfbab5ebab51bc3fe\" class=\"ne-p\"><span class=\"ne-text\">etcd \u5bf9\u5916\u901a\u8fc7 HTTP API \u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff0c\u8fd9\u79cd\u65b9\u5f0f\u65b9\u4fbf\u6d4b\u8bd5\uff08\u901a\u8fc7 curl \u6216\u8005\u5176\u4ed6\u5de5\u5177\u5c31\u80fd\u548c etcd \u4ea4\u4e92\uff09\uff0c\u4e5f\u5f88\u5bb9\u6613\u96c6\u6210\u5230\u5404\u79cd\u8bed\u8a00\u4e2d\uff08\u6bcf\u4e2a\u8bed\u8a00\u5c01\u88c5 HTTP API \u5b9e\u73b0\u81ea\u5df1\u7684 client \u5c31\u884c\uff09\u3002<\/span><\/p>\n<p id=\"8521515feb103b17b644760ba81bb3d6\" class=\"ne-p\"><span class=\"ne-text\">\u4e0b\u9762\u4ecb\u7ecd\u4e0b etcd \u901a\u8fc7 HTTP API \u63d0\u4f9b\u4e86\u54ea\u4e9b\u529f\u80fd\uff0c\u5e76\u4f7f\u7528 <\/span><code class=\"ne-code\"><span class=\"ne-text\">httpie<\/span><\/code><span class=\"ne-text\"> \u6765\u4ea4\u4e92\uff08\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 curl \u6216\u8005\u5176\u4ed6\u5de5\u5177\uff09\u3002<\/span><\/p>\n<h3 id=\"aYQAd\"><span class=\"ne-text\">1.\u83b7\u53d6 etcd \u670d\u52a1\u7684\u7248\u672c\u4fe1\u606f<\/span><\/h3>\n<pre id=\"7ixRG\" class=\"ne-codeblock\" data-language=\"json\">ubuntu@VM-0-13-ubuntu:~$ http http:\/\/127.0.0.1:2379\/version\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 45\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 06:46:25 GMT\r\n\r\n{\r\n    \"etcdcluster\": \"3.4.0\", \r\n    \"etcdserver\": \"3.4.13\"\r\n}\r\n<\/pre>\n<h3 id=\"vypB3\"><span class=\"ne-text\">2.key \u7684\u65b0\u589e<\/span><\/h3>\n<p id=\"7e9ce83ab9cf792eb154510ef83c99de\" class=\"ne-p\"><span class=\"ne-text\">etcd \u7684\u6570\u636e\u6309\u7167\u6811\u5f62\u7ed3\u6784\u7ec4\u7ec7\uff0c\u7c7b\u4f3c\u4e8e linux \u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u4e5f\u6709\u76ee\u5f55\u548c\u6587\u4ef6\u7684\u533a\u522b\uff0c\u4e0d\u8fc7\u4e00\u822c\u88ab\u79f0\u4e3a nodes\u3002\u6570\u636e\u7684 endpoint \u90fd\u662f\u4ee5 <\/span><code class=\"ne-code\"><span class=\"ne-text\">\/v2\/keys<\/span><\/code><span class=\"ne-text\"> \u5f00\u5934\uff08v2 \u8868\u793a\u5f53\u524d API \u7684\u7248\u672c\uff09\uff0c\u6bd4\u5982 <\/span><code class=\"ne-code\"><span class=\"ne-text\">\/v2\/keys\/names\/cizixs<\/span><\/code><span class=\"ne-text\">\u3002<\/span><\/p>\n<p id=\"3629ddb39767fdc12d1bf4a8c07d2cf8\" class=\"ne-p\"><span class=\"ne-text\">\u8981\u521b\u5efa\u4e00\u4e2a\u503c\uff0c\u53ea\u8981\u4f7f\u7528<\/span> <code class=\"ne-code\"><span class=\"ne-text\">PUT<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5<\/span><span class=\"ne-text\">\u5728\u5bf9\u5e94\u7684 url endpoint \u8bbe\u7f6e\u5c31\u884c\u3002\u5982\u679c\u5bf9\u5e94\u7684 key \u5df2\u7ecf\u5b58\u5728\uff0c <\/span><code class=\"ne-code\"><span class=\"ne-text\">PUT<\/span><\/code><span class=\"ne-text\"> \u4e5f\u4f1a\u5bf9 key \u8fdb\u884c\u66f4\u65b0\u3002<\/span><\/p>\n<pre id=\"JXFOU\" class=\"ne-codeblock\" data-language=\"json\">ubuntu@VM-0-13-ubuntu:~$ http PUT http:\/\/127.0.0.1:2379\/v2\/keys\/message value==\"hello, etcd\"\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 189\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 06:47:15 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 10\r\nX-Raft-Index: 26\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"set\", \r\n    \"node\": {\r\n        \"createdIndex\": 10, \r\n        \"key\": \"\/message\", \r\n        \"modifiedIndex\": 10, \r\n        \"value\": \"hello, etcd\"\r\n    }, \r\n    \"prevNode\": {\r\n        \"createdIndex\": 8, \r\n        \"key\": \"\/message\", \r\n        \"modifiedIndex\": 8, \r\n        \"value\": \"hello, etcd\"\r\n    }\r\n}\r\n<\/pre>\n<p id=\"d5f9c21ab93519d1a7ec463397a001b4\" class=\"ne-p\"><span class=\"ne-text\">\u4e0a\u9762\u8fd9\u4e2a\u547d\u4ee4\u901a\u8fc7 <\/span><code class=\"ne-code\"><span class=\"ne-text\">PUT<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5\u628a <\/span><code class=\"ne-code\"><span class=\"ne-text\">\/message<\/span><\/code><span class=\"ne-text\"> \u8bbe\u7f6e\u4e3a <\/span><code class=\"ne-code\"><span class=\"ne-text\">hello, etcd<\/span><\/code><span class=\"ne-text\">\u3002\u8fd4\u56de\u7684\u683c\u5f0f\u4e2d\uff0c\u5404\u4e2a\u5b57\u6bb5\u7684\u610f\u4e49\u662f\uff1a<\/span><\/p>\n<ul class=\"ne-ul\">\n<li id=\"bdb7b45c933523dfbf6df20c82c8d18b\"><code class=\"ne-code\"><span class=\"ne-text\">action<\/span><\/code><span class=\"ne-text\">\uff1a\u8bf7\u6c42\u51fa\u53d1\u7684\u52a8\u4f5c\uff0c\u8fd9\u91cc\u56e0\u4e3a\u662f\u65b0\u5efa\u4e00\u4e2a key \u5e76\u8bbe\u7f6e\u5b83\u7684\u503c\uff0c\u6240\u4ee5\u662f <\/span><code class=\"ne-code\"><span class=\"ne-text\">set\u3002<\/span><\/code><\/li>\n<li id=\"6c88ef67a5617ade04808018fa7495c4\"><code class=\"ne-code\"><span class=\"ne-text\">node.key<\/span><\/code><span class=\"ne-text\">\uff1akey \u7684 HTTP \u8def\u5f84\u3002<\/span><\/li>\n<\/ul>\n<ul class=\"ne-ul\">\n<li id=\"18273f67dbdbc7b3438d0a59a7aad803\"><code class=\"ne-code\"><span class=\"ne-text\">node.value<\/span><\/code><span class=\"ne-text\">\uff1a\u8bf7\u6c42\u5904\u7406\u4e4b\u540e\uff0ckey \u5bf9\u5e94\u7684value\u503c\u3002<\/span><\/li>\n<li id=\"5683f0c0f2e6c2d892d2b48140489298\"><code class=\"ne-code\"><span class=\"ne-text\">node.createdIndex<\/span><\/code><span class=\"ne-text\">\uff1a createdIndex \u662f\u4e00\u4e2a\u9012\u589e\u7684\u503c\uff0c<\/span><span class=\"ne-text\">\u6bcf\u6b21\u6709 key \u88ab\u521b\u5efa\u7684\u65f6\u5019\u4f1a\u589e\u52a0<\/span><span class=\"ne-text\">\u3002<\/span><\/li>\n<\/ul>\n<ul class=\"ne-ul\">\n<li id=\"a9a575bc8806338cebf4cb5864987ff9\"><code class=\"ne-code\"><span class=\"ne-text\">node.modifiedIndex<\/span><\/code><span class=\"ne-text\">\uff1a\u540c\u4e0a\uff0c<\/span><span class=\"ne-text\">\u53ea\u4e0d\u8fc7\u6bcf\u6b21\u6709 key \u88ab\u4fee\u6539\u7684\u65f6\u5019\u589e\u52a0<\/span><span class=\"ne-text\">\u3002<\/span><\/li>\n<\/ul>\n<p id=\"b4c0dc1b026752d115f8be7c8ebbf519\" class=\"ne-p\"><span class=\"ne-text\">\u9664\u8fd4\u56de\u7684 json \u4f53\u5916\uff0c\u4e0a\u9762\u7684\u60c5\u51b5\u8fd8\u5305\u542b\u4e86\u4e00\u4e9b\u7279\u6b8a\u7684 HTTP \u5934\u90e8\u4fe1\u606f\uff0c\u8fd9\u4e9b\u4fe1\u606f\u8bf4\u660e\u4e86 etcd cluster \u7684\u4e00\u4e9b\u60c5\u51b5\u3002\u5b83\u4eec\u7684\u5177\u4f53\u542b\u4e49\u5982\u4e0b\uff1a<\/span><\/p>\n<ul class=\"ne-ul\">\n<li id=\"e3dfe4b4762dda783b6064b033154af5\"><code class=\"ne-code\"><span class=\"ne-text\">X-Etcd-Index<\/span><\/code><span class=\"ne-text\">\uff1a\u5f53\u524d etcd \u96c6\u7fa4\u7684 index\u3002<\/span><\/li>\n<li id=\"1613dbe0db3440bc2483c2283dbed9fd\"><code class=\"ne-code\"><span class=\"ne-text\">X-Raft-Index<\/span><\/code><span class=\"ne-text\">\uff1araft \u96c6\u7fa4\u7684 index\u3002<\/span><\/li>\n<\/ul>\n<ul class=\"ne-ul\">\n<li id=\"edf84f0af0bdc52e1055e0fec804f16d\"><code class=\"ne-code\"><span class=\"ne-text\">X-Raft-Term<\/span><\/code><span class=\"ne-text\">\uff1araft \u96c6\u7fa4\u7684\u4efb\u671f\uff0c\u6bcf\u6b21\u6709 leader \u9009\u4e3e\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u503c\u5c31\u4f1a\u589e\u52a0\u3002<\/span><\/li>\n<\/ul>\n<h3 id=\"FIKms\"><span class=\"ne-text\">3.key\u7684\u67e5\u770b<\/span><\/h3>\n<p id=\"9002616d51f7d268a8ae8923f9410126\" class=\"ne-p\"><span class=\"ne-text\">\u67e5\u770b\u4fe1\u606f\u6bd4\u8f83\u7b80\u5355\uff0c\u4f7f\u7528 <\/span><code class=\"ne-code\"><span class=\"ne-text\">GET<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5\uff0curl \u6307\u5411\u8981\u67e5\u770b\u7684\u503c\u5c31\u884c\uff1a<\/span><\/p>\n<pre id=\"boMSC\" class=\"ne-codeblock\" data-language=\"json\">ubuntu@VM-0-13-ubuntu:~$ http GET http:\/\/127.0.0.1:2379\/v2\/keys\/message\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 102\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 06:48:27 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 10\r\nX-Raft-Index: 26\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"get\", \r\n    \"node\": {\r\n        \"createdIndex\": 10, \r\n        \"key\": \"\/message\", \r\n        \"modifiedIndex\": 10, \r\n        \"value\": \"hello, etcd\"\r\n    }\r\n}\r\n<\/pre>\n<p id=\"b521f7b79b9212a0967afb53a3eb27d1\" class=\"ne-p\"><span class=\"ne-text\">\u8fd9\u91cc\u7684 <\/span><code class=\"ne-code\"><span class=\"ne-text\">action<\/span><\/code><span class=\"ne-text\"> \u53d8\u6210\u4e86 <\/span><code class=\"ne-code\"><span class=\"ne-text\">get<\/span><\/code><span class=\"ne-text\">\uff0c\u5176\u4ed6\u8fd4\u56de\u7684\u503c\u548c\u4e0a\u9762\u7684\u542b\u4e49\u4e00\u6837\uff0c\u7565\u8fc7\u4e0d\u63d0\u3002<\/span><\/p>\n<p id=\"dada7b8c67cd3faabec19efe5ef5de5b\" class=\"ne-p\"><span class=\"ne-text\">NOTE\uff1a\u8fd9\u4e24\u4e2a\u547d\u4ee4\u5e76\u4e0d\u662f\u8fde\u7740\u6267\u884c\u7684\uff0c\u4e2d\u95f4\u6211\u6709\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\uff0c\u56e0\u6b64 <\/span><code class=\"ne-code\"><span class=\"ne-text\">index<\/span><\/code><span class=\"ne-text\"> \u4f1a\u51fa\u73b0\u4e0d\u8fde\u7eed\u7684\u60c5\u51b5\u3002<\/span><\/p>\n<h3 id=\"eex0X\"><span class=\"ne-text\">4. key\u7684\u66f4\u65b0<\/span><\/h3>\n<p id=\"8c3cb0902cc6733d7680ad1bd3570cc3\" class=\"ne-p\"><code class=\"ne-code\"><span class=\"ne-text\">PUT<\/span><\/code><span class=\"ne-text\"> \u4e5f\u53ef\u7528\u6765\u66f4\u65b0 key \u7684\u503c\u3002<\/span><\/p>\n<pre id=\"UdElv\" class=\"ne-codeblock\" data-language=\"json\">ubuntu@VM-0-13-ubuntu:~$ http PUT http:\/\/127.0.0.1:2379\/v2\/keys\/message value==\"I'm changed\"\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 191\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 06:48:52 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 11\r\nX-Raft-Index: 27\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"set\", \r\n    \"node\": {\r\n        \"createdIndex\": 11, \r\n        \"key\": \"\/message\", \r\n        \"modifiedIndex\": 11, \r\n        \"value\": \"I'm changed\"\r\n    }, \r\n    \"prevNode\": {\r\n        \"createdIndex\": 10, \r\n        \"key\": \"\/message\", \r\n        \"modifiedIndex\": 10, \r\n        \"value\": \"hello, etcd\"\r\n    }\r\n}<\/pre>\n<p id=\"b93b864810393010bc652ffc2d91b503\" class=\"ne-p\"><span class=\"ne-text\">\u548c\u7b2c\u4e00\u6b21\u6267\u884c <\/span><code class=\"ne-code\"><span class=\"ne-text\">PUT<\/span><\/code><span class=\"ne-text\"> \u547d\u4ee4\u4e0d\u540c\u7684\u662f\uff0c\u8fd4\u56de\u4e2d\u591a\u4e86\u4e00\u4e2a\u5b57\u6bb5 <\/span><code class=\"ne-code\"><span class=\"ne-text\">prevNode<\/span><\/code><span class=\"ne-text\">\uff0c\u5b83\u4fdd\u5b58\u7740\u66f4\u65b0\u4e4b\u524d\u8be5 key \u7684\u4fe1\u606f\u3002\u5b83\u7684\u683c\u5f0f\u548c <\/span><code class=\"ne-code\"><span class=\"ne-text\">node<\/span><\/code><span class=\"ne-text\"> \u662f\u4e00\u6837\u7684\uff0c\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u8fd9\u4e2a\u4fe1\u606f\uff0c\u8fd9\u4e2a\u5b57\u6bb5\u4f1a\u88ab\u7701\u7565\u3002<\/span><\/p>\n<h3 id=\"NWxVg\"><span class=\"ne-text\">5.\u5220\u9664 key\u00a0<\/span><\/h3>\n<p id=\"df86ec73ba1e438d4f4f4f737c812301\" class=\"ne-p\"><span class=\"ne-text\">\u5220\u9664 key \u53ef\u4ee5\u901a\u8fc7 <\/span><code class=\"ne-code\"><span class=\"ne-text\">DELETE<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5\u3002<\/span><\/p>\n<pre id=\"T8GvG\" class=\"ne-codeblock\" data-language=\"json\">ubuntu@VM-0-13-ubuntu:~$ http DELETE http:\/\/127.0.0.1:2379\/v2\/keys\/message\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 172\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 06:49:21 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 12\r\nX-Raft-Index: 28\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"delete\", \r\n    \"node\": {\r\n        \"createdIndex\": 11, \r\n        \"key\": \"\/message\", \r\n        \"modifiedIndex\": 12\r\n    }, \r\n    \"prevNode\": {\r\n        \"createdIndex\": 11, \r\n        \"key\": \"\/message\", \r\n        \"modifiedIndex\": 11, \r\n        \"value\": \"I'm changed\"\r\n    }\r\n}\r\n<\/pre>\n<p id=\"b82141ec54dc7b1f49220663000de467\" class=\"ne-p\"><span class=\"ne-text\">\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684 <\/span><code class=\"ne-code\"><span class=\"ne-text\">action<\/span><\/code><span class=\"ne-text\"> \u662f <\/span><code class=\"ne-code\"><span class=\"ne-text\">delete<\/span><\/code><span class=\"ne-text\">\uff0c\u5e76\u4e14 <\/span><code class=\"ne-code\"><span class=\"ne-text\">modifiedIndex<\/span><\/code><span class=\"ne-text\"> \u589e\u52a0\u4e86\uff0c\u4f46\u662f <\/span><code class=\"ne-code\"><span class=\"ne-text\">createdIndex<\/span><\/code><span class=\"ne-text\"> \u6ca1\u6709\u53d8\u5316\uff0c\u56e0\u4e3a\u8fd9\u662f\u4e00\u4e2a\u4fee\u6539\u64cd\u4f5c\uff0c\u4e0d\u662f\u65b0\u5efa\u64cd\u4f5c\u3002<\/span><\/p>\n<h3 id=\"aHgkT\"><span class=\"ne-text\">6. \u67e5\u770bttl<\/span><\/h3>\n<p id=\"2142b5dc655e397c4a48b009099fbc50\" class=\"ne-p\"><strong><span class=\"ne-text\">6.1 etcd \u4e2d\uff0ckey \u53ef\u4ee5\u6709 TTL \u5c5e\u6027\uff0c\u82e5\u8d85\u8fc7\u8fd9\u4e2a\u65f6\u95f4\uff0c\u5c31\u4f1a\u88ab\u81ea\u52a8\u5220\u9664\u3002<\/span><\/strong><\/p>\n<p id=\"79ac57f61039cab8ae74c4bb8ccc7db7\" class=\"ne-p\"><span class=\"ne-text\">\u8bbe\u7f6e\u4e00\u4e2a\u770b\u770b\uff1a<\/span><\/p>\n<pre id=\"q8d0n\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http PUT http:\/\/127.0.0.1:2379\/v2\/keys\/tempkey value==\"Gone with wind\" ttl==5\r\nHTTP\/1.1 201 Created\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 159\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 06:49:51 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 13\r\nX-Raft-Index: 29\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"set\", \r\n    \"node\": {\r\n        \"createdIndex\": 13, \r\n        \"expiration\": \"2020-10-27T06:49:56.260714913Z\", \r\n        \"key\": \"\/tempkey\", \r\n        \"modifiedIndex\": 13, \r\n        \"ttl\": 5, \r\n        \"value\": \"Gone with wind\"\r\n    }\r\n}\r\n<\/pre>\n<p id=\"bae9736b27465ba2e1ce9f2a22962947\" class=\"ne-p\"><span class=\"ne-text\">\u9664\u4e86\u4e00\u822c key \u8fd4\u56de\u7684\u4fe1\u606f\u4e4b\u5916\uff0c\u4e0a\u9762\u591a\u4e86\u4e24\u4e2a\u5b57\u6bb5\uff1a<\/span><\/p>\n<ul class=\"ne-ul\">\n<li id=\"02ea2dd2e8a8d76119672875084f99b5\"><code class=\"ne-code\"><span class=\"ne-text\">expiration<\/span><\/code><span class=\"ne-text\">\uff1a\u4ee3\u8868 key \u8fc7\u671f\u88ab\u5220\u9664\u7684\u65f6\u95f4<\/span><\/li>\n<li id=\"712924c9e539c01d51c6fcec92de223b\"><code class=\"ne-code\"><span class=\"ne-text\">ttl<\/span><\/code><span class=\"ne-text\">\uff1a\u8868\u793a key \u8fd8\u8981\u591a\u5c11\u79d2\u53ef\u4ee5\u5b58\u6d3b\uff08\u8fd9\u4e2a\u503c\u662f\u52a8\u6001\u7684\uff0c\u4f1a\u6839\u636e\u4f60\u8bf7\u6c42\u7684\u65f6\u5019\u548c\u8fc7\u671f\u65f6\u95f4\u8fdb\u884c\u8ba1\u7b97\uff09<\/span><\/li>\n<\/ul>\n<p id=\"8ca7300817cb4286f8aab0d896a895f0\" class=\"ne-p\"><strong><span class=\"ne-text\">\u5982\u679c\u6211\u4eec\u5728 5s \u4e4b\u540e\u518d\u53bb\u8bf7\u6c42\u67e5\u770b\u8be5 key\uff0c\u4f1a\u53d1\u73b0\u62a5\u9519\u4fe1\u606f<\/span><\/strong><span class=\"ne-text\">\uff1a<\/span><\/p>\n<pre id=\"aZbDL\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http http:\/\/127.0.0.1:2379\/v2\/keys\/tempkey\r\nHTTP\/1.1 404 Not Found\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 74\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 06:50:32 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 14\r\n\r\n{\r\n    \"cause\": \"\/tempkey\", \r\n    \"errorCode\": 100, \r\n    \"index\": 14, \r\n    \"message\": \"Key not found\"\r\n}\r\n<\/pre>\n<p id=\"609cce1e78de6b9a77a04da0159cbb66\" class=\"ne-p\"><span class=\"ne-text\">http \u8fd4\u56de\u4e3a <\/span><code class=\"ne-code\"><span class=\"ne-text\">404<\/span><\/code><span class=\"ne-text\">\uff0c\u5e76\u4e14\u8fd4\u56de\u4f53\u4e2d\u7ed9\u51fa\u4e86 <\/span><code class=\"ne-code\"><span class=\"ne-text\">errorCode<\/span><\/code><span class=\"ne-text\"> \u548c\u9519\u8bef\u4fe1\u606f\u3002<\/span><\/p>\n<p id=\"889b46830224334d6dba2196eb3cc700\" class=\"ne-p\"><strong><span class=\"ne-text\">6.2\u00a0TTL \u4e5f\u53ef\u901a\u8fc7 <\/span><\/strong><code class=\"ne-code\"><\/code><strong><span class=\"ne-text\">PUT<\/span><\/strong><strong><span class=\"ne-text\"> \u65b9\u6cd5\u8fdb\u884c\u53d6\u6d88\uff0c\u53ea\u8981\u8bbe\u7f6e\u7a7a\u503c <\/span><\/strong><code class=\"ne-code\"><\/code><strong><span class=\"ne-text\">ttl=<\/span><\/strong><strong><span class=\"ne-text\"> \u5c31\u884c\uff0c\u8fd9\u6837 key \u5c31\u4e0d\u4f1a\u8fc7\u671f\u88ab\u5220\u9664\u3002\u6bd4\u5982\uff1a<\/span><\/strong><\/p>\n<pre id=\"KKel5\" class=\"ne-codeblock\" data-language=\"bash\">http PUT http:\/\/127.0.0.1:2379\/v2\/keys\/foo value==bar ttl== prevExist==true<\/pre>\n<p id=\"71712c4204f62ba4d1a168a03c30efea\" class=\"ne-p\"><span class=\"ne-text\">\u6ce8\u610f\uff1a<\/span><strong><span class=\"ne-text\">\u9700\u8981\u8bbe\u7f6e value==bar\uff0c\u4e0d\u7136 key \u4f1a\u53d8\u6210\u7a7a\u503c\u3002<\/span><\/strong><\/p>\n<p id=\"2e6cbe4005222e9677fe845ef6416731\" class=\"ne-p\"><strong><span class=\"ne-text\">6.3\u00a0\u5982\u679c\u53ea\u662f\u60f3\u66f4\u65b0 TTL\uff0c\u53ef\u4ee5\u6dfb\u52a0\u4e0a <\/span><\/strong><code class=\"ne-code\"><\/code><strong><span class=\"ne-text\">refresh==true<\/span><\/strong><strong><span class=\"ne-text\"> \u53c2\u6570\uff1a<\/span><\/strong><\/p>\n<pre id=\"NctY5\" class=\"ne-codeblock\" data-language=\"bash\">http    PUT http:\/\/127.0.0.1:2379\/v2\/keys\/tempkey value==\"Gone with wind\" ttl==200\r\nhttp -v PUT http:\/\/127.0.0.1:2379\/v2\/keys\/tempkey refresh==true\r\n2. \r\n3. HTTP\/1.1 200 OK\r\n4. Content-Length: 305\r\n5. Content-Type: application\/json\r\n6. Date: Tue, 02 Aug 2016 06:05:12 GMT\r\n7. X-Etcd-Cluster-Id: cdf818194e3a8c32\r\n8. X-Etcd-Index: 20\r\n9. X-Raft-Index: 35849\r\n10. X-Raft-Term: 2\r\n11. \r\n12. {\r\n13. \"action\": \"set\",\r\n14. \"node\": {\r\n15. \"createdIndex\": 20,\r\n16. \"expiration\": \"2016-08-02T06:13:32.370495212Z\",\r\n17. \"key\": \"\/tempkey\",\r\n18. \"modifiedIndex\": 20,\r\n19. \"ttl\": 500,\r\n20. \"value\": \"hello, there\"\r\n21.     },\r\n22. \"prevNode\": {\r\n23. \"createdIndex\": 19,\r\n24. \"expiration\": \"2016-08-02T06:10:05.366042396Z\",\r\n25. \"key\": \"\/tempkey\",\r\n26. \"modifiedIndex\": 19,\r\n27. \"ttl\": 293,\r\n28. \"value\": \"hello, there\"\r\n29.     }\r\n30. }<\/pre>\n<h3 id=\"La1Qf\"><span class=\"ne-text\">7.\u76d1\u542c\u53d8\u5316<\/span><\/h3>\n<p id=\"95dc8db89e43dd3cfa5939a9c29db471\" class=\"ne-p\"><span class=\"ne-text\">etcd \u63d0\u4f9b\u4e86\u76d1\u542c\u7684\u673a\u5236\uff0c\u53ef\u4ee5\u8ba9\u5ba2\u6237\u7aef\u4f7f\u7528 long pulling \u65b9\u5f0f\u6765\u76d1\u542c\u67d0\u4e2a key\u3002\u5f53key\u53d1\u751f\u53d8\u5316\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u63a5\u6536\u5230\u901a\u77e5\u3002\u56e0\u4e3a etcd \u7ecf\u5e38\u88ab\u7528\u4f5c\u670d\u52a1\u53d1\u73b0\uff0c\u82e5\u96c6\u7fa4\u4e2d\u7684\u4fe1\u606f\u6709\u66f4\u65b0\uff0c\u9700\u8981\u53ca\u65f6\u88ab\u68c0\u6d4b\uff0c\u505a\u51fa\u5bf9\u5e94\u7684\u5904\u7406\u3002\u56e0\u6b64\uff0c\u9700\u8981\u6709\u76d1\u542c\u673a\u5236\uff0c\u6765\u544a\u8bc9\u5ba2\u6237\u7aef\u7279\u5b9a key \u7684\u53d8\u5316\u60c5\u51b5\u3002<\/span><\/p>\n<p id=\"44a7deb2556fffc9ca70eca018e26e2d\" class=\"ne-p\"><span class=\"ne-text\">\u76d1\u542c\u52a8\u4f5c\u53ea\u9700\u8981 <\/span><code class=\"ne-code\"><span class=\"ne-text\">GET<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5\uff0c\u6dfb\u52a0\u4e0a <\/span><code class=\"ne-code\"><span class=\"ne-text\">wait=true<\/span><\/code><span class=\"ne-text\"> \u53c2\u6570\u5c31\u884c\u3002\u4f7f\u7528 <\/span><code class=\"ne-code\"><span class=\"ne-text\">recursive=true<\/span><\/code><span class=\"ne-text\"> \u53c2\u6570\uff0c\u4e5f\u80fd\u76d1\u542c\u67d0\u4e2a\u76ee\u5f55\u3002<\/span><\/p>\n<pre id=\"qnBIn\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http http:\/\/127.0.0.1:2379\/v2\/keys\/foo wait==true\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:04:48 GMT\r\nTransfer-Encoding: chunked\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 27\r\nX-Raft-Index: 731\r\nX-Raft-Term: 7\r\n<\/pre>\n<p id=\"b468a341085e547649615039a02a2279\" class=\"ne-p\"><span class=\"ne-text\">\u8fd9\u4e2a\u65f6\u5019\uff0c\u5ba2\u6237\u7aef\u4f1a\u963b\u585e\u5728\u8fd9\u91cc\u3002\u5982\u679c\u6709\u53e6\u5916\u7684 terminal \u4fee\u6539 key \u7684\u503c\uff0c\u5219\u76d1\u542c\u7684\u5ba2\u6237\u7aef\u4f1a\u63a5\u6536\u5230\u6d88\u606f\uff0c\u5e76\u6253\u5370\u51fa\u66f4\u65b0\u7684\u503c\uff1a<\/span><\/p>\n<pre id=\"hRTpn\" class=\"ne-codeblock\" data-language=\"bash\">{\r\n    \"action\": \"set\", \r\n    \"node\": {\r\n        \"createdIndex\": 28, \r\n        \"key\": \"\/foo\", \r\n        \"modifiedIndex\": 28, \r\n        \"value\": \"I'm fuge\"\r\n    }, \r\n    \"prevNode\": {\r\n        \"createdIndex\": 26, \r\n        \"key\": \"\/foo\", \r\n        \"modifiedIndex\": 26, \r\n        \"value\": \"I'm changed\"\r\n    }\r\n}\r\n<\/pre>\n<p id=\"ba241d4366bb18153fd5bdd2c3bd2fb8\" class=\"ne-p\"><span class=\"ne-text\">\u9664\u4e86\u8fd9\u79cd\u6700\u7b80\u5355\u7684\u76d1\u542c\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u63d0\u4f9b\u57fa\u4e8e index \u7684\u76d1\u542c\u3002\u5982\u679c\u901a\u8fc7 <\/span><code class=\"ne-code\"><span class=\"ne-text\">waitIndex<\/span><\/code><span class=\"ne-text\"> \u6307\u5b9a\u4e86 index\uff0c\u90a3\u4e48\u4f1a\u8fd4\u56de\u4ece index \u5f00\u59cb\u51fa\u73b0\u7684\u7b2c\u4e00\u4e2a\u4e8b\u4ef6\uff0c\u8fd9\u5305\u542b\u4e86\u4e24\u79cd\u60c5\u51b5\uff1a<\/span><\/p>\n<ul class=\"ne-ul\">\n<li id=\"98741c80ab9ce573e0744418581da4f9\"><span class=\"ne-text\">\u7ed9\u51fa\u7684 index \u5c0f\u4e8e\u7b49\u4e8e\u5f53\u524d index \uff0c\u5373\u4e8b\u4ef6\u5df2\u7ecf\u53d1\u751f\uff0c\u90a3\u4e48\u76d1\u542c\u4f1a\u7acb\u5373\u8fd4\u56de\u8be5\u4e8b\u4ef6\u3002<\/span><\/li>\n<li id=\"95be7d4de9e06ada3ee109669eeb039d\"><span class=\"ne-text\">\u7ed9\u51fa\u7684 index \u5927\u4e8e\u5f53\u524d index\uff0c\u7b49\u5f85 index \u4e4b\u540e\u7684\u4e8b\u4ef6\u53d1\u751f\u5e76\u8fd4\u56de\u3002<\/span><\/li>\n<\/ul>\n<p id=\"1b66eb6014eea765e628aa2a73cfb96c\" class=\"ne-p\"><span class=\"ne-text\">\u76ee\u524d etcd \u53ea\u4f1a\u4fdd\u5b58\u6700\u8fd1 1000 \u4e2a\u4e8b\u4ef6\uff08\u6574\u4e2a\u96c6\u7fa4\u8303\u56f4\u5185\uff09\uff0c\u518d\u65e9\u4e4b\u524d\u7684\u4e8b\u4ef6\u4f1a\u88ab\u6e05\u7406\u3002\u5982\u679c\u76d1\u542c\u88ab\u6e05\u7406\u7684\u4e8b\u4ef6\uff0c\u5219\u4f1a\u62a5\u9519\u3002\u5982\u679c\u51fa\u73b0\u6f0f\u8fc7\u592a\u591a\u4e8b\u4ef6\uff08\u8d85\u8fc7 1000\uff09\u7684\u60c5\u51b5\uff0c\u9700\u8981\u91cd\u65b0\u83b7\u53d6\u5f53\u7136\u7684 index \u503c\uff08<\/span><code class=\"ne-code\"><span class=\"ne-text\">X-Etcd-Index<\/span><\/code><span class=\"ne-text\">\uff09\uff0c\u7136\u540e\u4ece <\/span><code class=\"ne-code\"><span class=\"ne-text\">X-Etcd-Index+1<\/span><\/code><span class=\"ne-text\"> \u5f00\u59cb\u76d1\u542c\u3002<\/span><\/p>\n<p id=\"482b2c4bbf91478b3fcce4264778be0e\" class=\"ne-p\"><span class=\"ne-text\">\u56e0\u4e3a\u5728\u76d1\u542c\u7684\u65f6\u5019\u51fa\u73b0\u4e8b\u4ef6\u5c31\u4f1a\u76f4\u63a5\u8fd4\u56de\uff0c\u6240\u4ee5\u9700\u8981\u5ba2\u6237\u7aef\u7f16\u5199\u5faa\u73af\u903b\u8f91\uff0c\u4fdd\u6301\u76d1\u542c\u72b6\u6001\u3002\u5728\u4e24\u6b21\u76d1\u542c\u7684\u95f4\u9694\u4e2d\u51fa\u73b0\u7684\u4e8b\u4ef6\uff0c\u5f88\u53ef\u80fd\u88ab\u6f0f\u8fc7\u3002\u6240\u4ee5\uff0c<\/span><span class=\"ne-text\">\u6700\u597d\u628a<\/span><strong><span class=\"ne-text\">\u4e8b\u4ef6\u5904\u7406\u903b\u8f91<\/span><\/strong><span class=\"ne-text\">\u505a\u6210<\/span><strong><span class=\"ne-text\">\u5f02\u6b65\u7684<\/span><\/strong><span class=\"ne-text\">\uff0c\u4e0d\u8981\u963b\u585e\u76d1\u542c\u903b\u8f91\u3002<\/span><\/p>\n<p id=\"19565c7073a89e418eea491fc9f99f2e\" class=\"ne-p\"><span class=\"ne-text\">\u6ce8\u610f\uff1a<\/span><strong><span class=\"ne-text\">\u76d1\u542c key \u65f6\u4f1a\u51fa\u73b0\u201c\u957f\u65f6\u95f4\u6ca1\u6709\u8fd4\u56de\uff0c\u5bfc\u81f4\u8fde\u63a5\u88ab close \u201d\u7684\u60c5\u51b5\uff0c\u5ba2\u6237\u7aef\u9700\u8981\u5904\u7406\u8fd9\u79cd\u9519\u8bef\uff0c\u5e76\u81ea\u52a8\u91cd\u8bd5\u3002<\/span><\/strong><\/p>\n<h3 id=\"s9CDd\"><span class=\"ne-text\">8.\u81ea\u52a8\u521b\u5efa\u6709\u5e8f\u7684 keys<\/span><\/h3>\n<p id=\"44b02696394f63b8132019a756c740fd\" class=\"ne-p\"><span class=\"ne-text\">\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981 key \u662f\u6709\u5e8f\u7684\uff0cetcd \u63d0\u4f9b\u4e86\u8fd9\u4e2a\u529f\u80fd\u3002<\/span><span class=\"ne-text\">\u5bf9\u67d0\u4e2a\u76ee\u5f55\u4f7f\u7528 <\/span><code class=\"ne-code\"><span class=\"ne-text\">POST<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5\uff0c\u80fd\u81ea\u52a8\u751f\u6210\u6709\u5e8f\u7684 key<\/span><span class=\"ne-text\">\uff0c\u8fd9\u79cd\u6a21\u5f0f\u53ef\u4ee5\u7528\u4e8e<\/span><span class=\"ne-text\">\u961f\u5217\u5904\u7406<\/span><span class=\"ne-text\">\u7b49\u573a\u666f\u3002<\/span><\/p>\n<pre id=\"i1OlZ\" class=\"ne-codeblock\" data-language=\"bash\">buntu@VM-0-13-ubuntu:~$ http POST http:\/\/127.0.0.1:2379\/v2\/keys\/queue value==job1\r\nHTTP\/1.1 201 Created\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 117\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:06:09 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 29\r\nX-Raft-Index: 734\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"create\", \r\n    \"node\": {\r\n        \"createdIndex\": 29, \r\n        \"key\": \"\/queue\/00000000000000000029\", \r\n        \"modifiedIndex\": 29, \r\n        \"value\": \"job1\"\r\n    }\r\n}\r\n<\/pre>\n<p id=\"cb595fcc54cb04fc8aef32f03bab31b1\" class=\"ne-p\"><span class=\"ne-text\">\u521b\u5efa\u7684 key \u4f1a\u4f7f\u7528 etcd index\uff0c\u53ea\u80fd\u4fdd\u8bc1\u9012\u589e\uff0c\u65e0\u6cd5\u4fdd\u8bc1\u662f\u8fde\u7eed\u7684\uff08\u56e0\u4e3a\u5728\u4e24\u6b21\u521b\u5efa\u4e4b\u95f4\uff0c\u53ef\u80fd\u4f1a\u6709\u5176\u4ed6\u4e8b\u4ef6\u53d1\u751f\uff09\u3002<\/span><span class=\"ne-text\">\u7528\u76f8\u540c\u7684\u547d\u4ee4\u521b\u5efa\u591a\u4e2a\u503c\uff0c\u5728\u83b7\u53d6\u503c\u7684\u65f6\u5019\uff0c\u4f7f\u7528 <\/span><code class=\"ne-code\"><span class=\"ne-text\">sorted=true<\/span><\/code><span class=\"ne-text\">\u53c2\u6570\uff0c\u5c31\u4f1a\u8fd4\u56de\u5df2\u7ecf\u6392\u5e8f\u7684\u503c<\/span><span class=\"ne-text\">\uff1a<\/span><\/p>\n<pre id=\"GuYtF\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http http:\/\/127.0.0.1:2379\/v2\/keys\/queue sorted==true\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 189\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:06:50 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 29\r\nX-Raft-Index: 734\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"get\", \r\n    \"node\": {\r\n        \"createdIndex\": 29, \r\n        \"dir\": true, \r\n        \"key\": \"\/queue\", \r\n        \"modifiedIndex\": 29, \r\n        \"nodes\": [\r\n            {\r\n                \"createdIndex\": 29, \r\n                \"key\": \"\/queue\/00000000000000000029\", \r\n                \"modifiedIndex\": 29, \r\n                \"value\": \"job1\"\r\n            }\r\n        ]\r\n    }\r\n}\r\n<\/pre>\n<h3 id=\"lI8ZP\"><span class=\"ne-text\">9.\u8bbe\u7f6e\u76ee\u5f55\u7684 TTL<\/span><\/h3>\n<p id=\"ddbf24c1ef16ded95d1affbd7a78b6f4\" class=\"ne-p\"><span class=\"ne-text\">\u548c key \u7c7b\u4f3c\uff0c\u76ee\u5f55\uff08dir\uff09\u4e5f\u53ef\u4ee5\u6709\u8fc7\u671f\u65f6\u95f4\u3002\u8bbe\u7f6e\u7684\u65b9\u6cd5\u4e5f\u4e00\u6837\uff0c\u53ea\u4e0d\u8fc7\u591a\u4e86 <\/span><code class=\"ne-code\"><span class=\"ne-text\">dir=true<\/span><\/code><span class=\"ne-text\"> \u53c2\u6570\u6765\u8bf4\u660e\u8fd9\u662f\u4e00\u4e2a\u76ee\u5f55\u3002<\/span><\/p>\n<pre id=\"Cwv8g\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http PUT http:\/\/127.0.0.1:2379\/v2\/keys\/dir dir==true ttl==5 prevExist==true\r\nHTTP\/1.1 404 Not Found\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 70\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:07:29 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 29\r\n\r\n{\r\n    \"cause\": \"\/dir\", \r\n    \"errorCode\": 100, \r\n    \"index\": 29, \r\n    \"message\": \"Key not found\"\r\n}\r\n<\/pre>\n<p id=\"b04f3d15e3fc7de055b674eb37261780\" class=\"ne-p\"><span class=\"ne-text\">\u76ee\u5f55\u5728\u8fc7\u671f\u7684\u65f6\u5019\uff0c\u4f1a\u88ab\u81ea\u52a8\u5220\u9664\uff0c\u5305\u62ec\u5b83\u91cc\u9762\u6240\u6709\u7684\u5b50\u76ee\u5f55\u548c key\u3002\u6240\u6709\u76d1\u542c\u8fd9\u4e2a\u76ee\u5f55\u4e2d\u5185\u5bb9\u7684\u5ba2\u6237\u7aef\uff0c\u90fd\u4f1a\u6536\u5230\u5bf9\u5e94\u7684\u4e8b\u4ef6\u3002<\/span><\/p>\n<h3 id=\"FDmIe\"><span class=\"ne-text\">10.\u6bd4\u8f83\u66f4\u65b0\u7684\u539f\u5b50\u64cd\u4f5c<\/span><\/h3>\n<p id=\"9bdacf27b2705e473992042f93e90939\" class=\"ne-p\"><span class=\"ne-text\">\u5728\u5206\u5e03\u5f0f\u73af\u5883\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u89e3\u51b3\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u7ade\u4e89\u95ee\u9898\uff0cetcd \u63d0\u4f9b\u4e86\u539f\u5b50\u64cd\u4f5c <\/span><code class=\"ne-code\"><span class=\"ne-text\">CompareAndSwap<\/span><\/code><span class=\"ne-text\">\uff08CAS\uff09\uff0c\u901a\u8fc7\u8fd9\u4e2a\u64cd\u4f5c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\u3002<\/span><\/p>\n<p id=\"207a77e6411fdc6d7c0bcecf56e26d22\" class=\"ne-p\"><span class=\"ne-text\">\u7b80\u5355\u6765\u8bf4\uff0c\u53ea\u6709\u5728\u5ba2\u6237\u7aef\u63d0\u4f9b\u7684\u6761\u4ef6\u6210\u7acb\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2a\u547d\u4ee4\u624d\u4f1a\u66f4\u65b0\u5bf9\u5e94\u7684\u503c\u3002\u76ee\u524d\u652f\u6301\u7684\u6761\u4ef6\u5305\u62ec\uff1a<\/span><\/p>\n<ul class=\"ne-ul\">\n<li id=\"fd2b998099af38f4e0e47cb9423cf4c6\"><code class=\"ne-code\"><span class=\"ne-text\">preValue<\/span><\/code><span class=\"ne-text\">\uff1a\u68c0\u67e5 key \u4e4b\u524d\u7684\u503c\u662f\u5426\u548c\u5ba2\u6237\u7aef\u63d0\u4f9b\u7684\u4e00\u81f4\u3002<\/span><\/li>\n<li id=\"7ed0c7607655403314b10ebf8e555a84\"><code class=\"ne-code\"><span class=\"ne-text\">prevIndex<\/span><\/code><span class=\"ne-text\">\uff1a\u68c0\u67e5 key \u4e4b\u524d\u7684 <\/span><code class=\"ne-code\"><span class=\"ne-text\">modifiedIndex<\/span><\/code><span class=\"ne-text\"> \u662f\u5426\u548c\u5ba2\u6237\u7aef\u63d0\u4f9b\u7684\u4e00\u81f4\u3002<\/span><\/li>\n<\/ul>\n<ul class=\"ne-ul\">\n<li id=\"294b81ca1a10427e6343df7d3292b1d4\"><code class=\"ne-code\"><span class=\"ne-text\">prevExist<\/span><\/code><span class=\"ne-text\">\uff1a\u68c0\u67e5 key \u662f\u5426\u5df2\u7ecf\u5b58\u5728\u3002\u5982\u679c\u5b58\u5728\u5c31\u6267\u884c\u66f4\u65b0\u64cd\u4f5c\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u6267\u884c create \u64cd\u4f5c\u3002<\/span><\/li>\n<\/ul>\n<p id=\"eb3db7803c78f7a30f25f22f12731258\" class=\"ne-p\"><span class=\"ne-text\">\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6bd4\u5982\u76ee\u524d <\/span><code class=\"ne-code\"><span class=\"ne-text\">\/foo<\/span><\/code><span class=\"ne-text\"> \u7684\u503c\u4e3a <\/span><code class=\"ne-code\"><span class=\"ne-text\">bar<\/span><\/code><span class=\"ne-text\">\uff0c\u8981\u628a\u5b83\u66f4\u65b0\u6210 <\/span><code class=\"ne-code\"><span class=\"ne-text\">changed<\/span><\/code><span class=\"ne-text\">\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/span><\/p>\n<pre id=\"MwRYn\" class=\"ne-codeblock\" data-language=\"plain\">ubuntu@VM-0-13-ubuntu:~$ http PUT http:\/\/127.0.0.1:2379\/v2\/keys\/foo prevValue==bar value==changed\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 182\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:09:44 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 31\r\nX-Raft-Index: 738\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"compareAndSwap\", \r\n    \"node\": {\r\n        \"createdIndex\": 30, \r\n        \"key\": \"\/foo\", \r\n        \"modifiedIndex\": 31, \r\n        \"value\": \"changed\"\r\n    }, \r\n    \"prevNode\": {\r\n        \"createdIndex\": 30, \r\n        \"key\": \"\/foo\", \r\n        \"modifiedIndex\": 30, \r\n        \"value\": \"bar\"\r\n    }\r\n}\r\n<\/pre>\n<p id=\"4058e1e1a2297db93c02171b3759cd4c\" class=\"ne-p\"><span class=\"ne-text\">\u5982\u679c\u63d0\u4f9b\u7684\u6761\u4ef6\u4e0d\u5bf9\uff0c\u4f1a\u62a5 <\/span><code class=\"ne-code\"><span class=\"ne-text\">412<\/span><\/code><span class=\"ne-text\"> \u9519\u8bef\uff1a<\/span><\/p>\n<pre id=\"l2cD3\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http PUT http:\/\/127.0.0.1:2379\/v2\/keys\/foo prevValue==bar value==changed\r\nHTTP\/1.1 412 Precondition Failed\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 84\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:08:40 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 29\r\n\r\n{\r\n    \"cause\": \"[bar != I'm fuge]\", \r\n    \"errorCode\": 101, \r\n    \"index\": 29, \r\n    \"message\": \"Compare failed\"\r\n}\r\n<\/pre>\n<p id=\"24292e49125fbf5def69eae50fb19fd2\" class=\"ne-p\"><span class=\"ne-text\">\u6ce8\u610f\uff1a<\/span><span class=\"ne-text\">\u5339\u914d\u6761\u4ef6\u662f <\/span><code class=\"ne-code\"><span class=\"ne-text\">prevIndex=0<\/span><\/code><span class=\"ne-text\"> \u7684\u8bdd\uff0c\u4e5f\u4f1a\u901a\u8fc7\u68c0\u67e5\u3002<\/span><\/p>\n<p id=\"b92c2c0c09575044e5f70b801b97b37a\" class=\"ne-p\"><span class=\"ne-text\">\u8fd9\u4e9b\u6761\u4ef6\u4e5f\u53ef\u4ee5\u7ec4\u5408\u8d77\u6765\u4f7f\u7528\uff0c\u53ea\u6709\u5f53\u90fd\u6ee1\u8db3\u7684\u65f6\u5019\uff0c\u624d\u4f1a\u6267\u884c\u5bf9\u5e94\u7684\u64cd\u4f5c\u3002<\/span><\/p>\n<h3 id=\"0aBsg\"><span class=\"ne-text\">11.\u6bd4\u8f83\u5220\u9664\u7684\u539f\u5b50\u64cd\u4f5c<\/span><\/h3>\n<p id=\"f1d3f960ec6a6741ae31f730fe19155a\" class=\"ne-p\"><span class=\"ne-text\">\u548c\u6761\u4ef6\u66f4\u65b0\u7c7b\u4f3c\uff0cetcd \u4e5f\u652f\u6301\u6761\u4ef6\u5220\u9664\u64cd\u4f5c\uff1a\u53ea\u6709\u5728\u5ba2\u6237\u7aef\u63d0\u4f9b\u7684\u6761\u4ef6\u6210\u7acb\u7684\u60c5\u51b5\u4e0b\uff0c\u624d\u4f1a\u6267\u884c\u5220\u9664\u64cd\u4f5c\u3002\u652f\u6301 <\/span><code class=\"ne-code\"><span class=\"ne-text\">prevValue<\/span><\/code><span class=\"ne-text\"> \u548c <\/span><code class=\"ne-code\"><span class=\"ne-text\">prevIndex<\/span><\/code><span class=\"ne-text\"> \u4e24\u79cd\u6761\u4ef6\u68c0\u67e5\uff0c\u6ca1\u6709 <\/span><code class=\"ne-code\"><span class=\"ne-text\">prevExist<\/span><\/code><span class=\"ne-text\">\uff0c\u56e0\u4e3a\u5220\u9664\u4e0d\u5b58\u5728\u7684\u503c\u672c\u8eab\u5c31\u4f1a\u62a5\u9519\u3002<\/span><\/p>\n<p id=\"cc7e42c8612e513808dd0b7f6695c2e6\" class=\"ne-p\"><span class=\"ne-text\">\u6211\u4eec\u6765\u5220\u9664\u4e0a\u9762\u4f8b\u5b50\u4e2d\u66f4\u65b0\u7684 <\/span><code class=\"ne-code\"><span class=\"ne-text\">\/foo<\/span><\/code><span class=\"ne-text\"> \uff0c\u5148\u770b\u4e00\u4e0b\u63d0\u4f9b\u7684\u6761\u4ef6\u4e0d\u5bf9\u7684\u60c5\u51b5\uff1a<\/span><\/p>\n<pre id=\"dRvrw\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http DELETE http:\/\/127.0.0.1:2379\/v2\/keys\/foo prevValue==bar\r\nHTTP\/1.1 412 Precondition Failed\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 83\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:10:20 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 31\r\n\r\n{\r\n    \"cause\": \"[bar != changed]\", \r\n    \"errorCode\": 101, \r\n    \"index\": 31, \r\n    \"message\": \"Compare failed\"\r\n}\r\n<\/pre>\n<p id=\"b19a923b5207fc4e5d8c9b3e902659d9\" class=\"ne-p\"><span class=\"ne-text\">\u5982\u679c\u63d0\u4f9b\u7684\u6761\u4ef6\u6210\u7acb\uff0c\u5bf9\u5e94\u7684 key \u5c31\u4f1a\u88ab\u5220\u9664\uff1a<\/span><\/p>\n<pre id=\"pH6vZ\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http DELETE http:\/\/127.0.0.1:2379\/v2\/keys\/foo prevValue==changed\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 170\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:10:40 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 32\r\nX-Raft-Index: 740\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"compareAndDelete\", \r\n    \"node\": {\r\n        \"createdIndex\": 30, \r\n        \"key\": \"\/foo\", \r\n        \"modifiedIndex\": 32\r\n    }, \r\n    \"prevNode\": {\r\n        \"createdIndex\": 30, \r\n        \"key\": \"\/foo\", \r\n        \"modifiedIndex\": 31, \r\n        \"value\": \"changed\"\r\n    }\r\n}<\/pre>\n<h3 id=\"YBmqG\"><span class=\"ne-text\">12.\u64cd\u4f5c\u76ee\u5f55<\/span><\/h3>\n<p id=\"afcb30d000a1f76c116aafc0236c6133\" class=\"ne-p\"><strong><span class=\"ne-text\">12.1\u00a0\u521b\u5efa\u64cd\u4f5c\u76ee\u5f55<\/span><\/strong><\/p>\n<p id=\"b29052e02aa18e25d3cd031ab6a12004\" class=\"ne-p\"><span class=\"ne-text\">\u5728\u521b\u5efa key \u7684\u65f6\u5019\uff0c\u5982\u679c\u5b83\u6240\u5728\u8def\u5f84\u7684\u76ee\u5f55\u4e0d\u5b58\u5728\uff0c\u4f1a\u81ea\u52a8\u88ab\u521b\u5efa\u3002\u6240\u4ee5\uff0c\u5728\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u5173\u5fc3\u76ee\u5f55\u7684\u521b\u5efa\u3002\u76ee\u5f55\u7684\u64cd\u4f5c\u548c key \u7684\u64cd\u4f5c\u57fa\u672c\u4e00\u81f4\uff0c\u552f\u4e00\u7684\u533a\u522b\u662f\uff1a\u9700\u8981\u52a0\u4e0a <\/span><code class=\"ne-code\"><span class=\"ne-text\">dir=true<\/span><\/code><span class=\"ne-text\"> \u53c2\u6570\uff0c\u6307\u660e\u64cd\u4f5c\u7684\u5bf9\u8c61\u662f\u76ee\u5f55\u3002<\/span><\/p>\n<p id=\"e0986d1853298ade023f2d6d47ddf83e\" class=\"ne-p\"><span class=\"ne-text\">\u6bd4\u5982\uff0c\u5982\u679c\u60f3\u8981\u663e\u793a\u5730\u521b\u5efa\u76ee\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528 <\/span><code class=\"ne-code\"><span class=\"ne-text\">PUT<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5\uff0c\u5e76\u8bbe\u7f6e <\/span><code class=\"ne-code\"><span class=\"ne-text\">dir=true<\/span><\/code><span class=\"ne-text\">\uff1a<\/span><\/p>\n<pre id=\"Urjx8\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http PUT http:\/\/127.0.0.1:2379\/v2\/keys\/anotherdir dir==true\r\nHTTP\/1.1 201 Created\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 94\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:11:21 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 33\r\nX-Raft-Index: 741\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"set\", \r\n    \"node\": {\r\n        \"createdIndex\": 33, \r\n        \"dir\": true, \r\n        \"key\": \"\/anotherdir\", \r\n        \"modifiedIndex\": 33\r\n    }\r\n}\r\n<\/pre>\n<p id=\"59d0bca737bc8ad534d46bca1988982d\" class=\"ne-p\"><span class=\"ne-text\">\u521b\u5efa\u76ee\u5f55\u7684\u64cd\u4f5c\u4e0d\u80fd\u91cd\u590d\u6267\u884c\uff0c\u5426\u5219\u4f1a\u62a5 <\/span><code class=\"ne-code\"><span class=\"ne-text\">HTTP 403<\/span><\/code><span class=\"ne-text\"> \u9519\u8bef\u3002<\/span><\/p>\n<p id=\"145230feb19183c955d1a0cb4154e3df\" class=\"ne-p\"><strong><span class=\"ne-text\">12.2\u00a0\u5217\u51fa\u5355\u4e2a\u8282\u70b9\u6216\u76ee\u5f55\u4e0b\u6240\u6709\u8282\u70b9\u7684\u4fe1\u606f<\/span><\/strong><\/p>\n<p id=\"9c49d35927e8bad02801f452907b0316\" class=\"ne-p\"><span class=\"ne-text\">\u5982\u679c <\/span><code class=\"ne-code\"><span class=\"ne-text\">GET<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5\u5bf9\u5e94\u7684 url \u662f\u76ee\u5f55\u7684\u8bdd\uff0cetcd \u4f1a\u5217\u51fa\u8be5\u76ee\u5f55\u6240\u6709\u8282\u70b9\u7684\u4fe1\u606f\uff08\u4e0d\u9700\u8981\u6307\u5b9a <\/span><code class=\"ne-code\"><span class=\"ne-text\">dir=true<\/span><\/code><span class=\"ne-text\">\uff09\u3002\u4f8b\u5982\uff0c\u8981\u5217\u51fa\u6839\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u8282\u70b9\uff1a<\/span><\/p>\n<pre id=\"mfKlP\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http http:\/\/127.0.0.1:2379\/v2\/keys\/\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 182\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:12:01 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 33\r\nX-Raft-Index: 741\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"get\", \r\n    \"node\": {\r\n        \"dir\": true, \r\n        \"nodes\": [\r\n            {\r\n                \"createdIndex\": 33, \r\n                \"dir\": true, \r\n                \"key\": \"\/anotherdir\", \r\n                \"modifiedIndex\": 33\r\n            }, \r\n            {\r\n                \"createdIndex\": 29, \r\n                \"dir\": true, \r\n                \"key\": \"\/queue\", \r\n                \"modifiedIndex\": 29\r\n            }\r\n        ]\r\n    }\r\n}\r\n<\/pre>\n<p id=\"70d4456a87b15ac9d99a955677b56311\" class=\"ne-p\"><strong><span class=\"ne-text\">12.3 \u9012\u5f52\u5217\u51fa\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u503c<\/span><\/strong><\/p>\n<p id=\"318b896258cf23bcc4d90b58413f6453\" class=\"ne-p\"><span class=\"ne-text\">\u5982\u679c\u8981\u9012\u5f52\u5217\u51fa\u6240\u6709\u7684\u503c\uff0c\u53ea\u9700\u6dfb\u52a0\u4e0a <\/span><code class=\"ne-code\"><span class=\"ne-text\">recursive=true<\/span><\/code><span class=\"ne-text\"> \u53c2\u6570\uff1a<\/span><\/p>\n<pre id=\"9LLYp\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http http:\/\/127.0.0.1:2379\/v2\/keys\/\\?recursive\\=true\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 483\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:13:40 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 36\r\nX-Raft-Index: 744\r\nX-Raft-Term: 7\r\n\r\n{\r\n    \"action\": \"get\", \r\n    \"node\": {\r\n        \"dir\": true, \r\n        \"nodes\": [\r\n            {\r\n                \"createdIndex\": 35, \r\n                \"key\": \"\/foo2\", \r\n                \"modifiedIndex\": 35, \r\n                \"value\": \"bar\"\r\n            }, \r\n            {\r\n                \"createdIndex\": 36, \r\n                \"key\": \"\/foo23\", \r\n                \"modifiedIndex\": 36, \r\n                \"value\": \"bar\"\r\n            }, \r\n            {\r\n                \"createdIndex\": 33, \r\n                \"dir\": true, \r\n                \"key\": \"\/anotherdir\", \r\n                \"modifiedIndex\": 33\r\n            }, \r\n            {\r\n                \"createdIndex\": 29, \r\n                \"dir\": true, \r\n                \"key\": \"\/queue\", \r\n                \"modifiedIndex\": 29, \r\n                \"nodes\": [\r\n                    {\r\n                        \"createdIndex\": 29, \r\n                        \"key\": \"\/queue\/00000000000000000029\", \r\n                        \"modifiedIndex\": 29, \r\n                        \"value\": \"job1\"\r\n                    }\r\n                ]\r\n            }, \r\n            {\r\n                \"createdIndex\": 34, \r\n                \"key\": \"\/foo\", \r\n                \"modifiedIndex\": 34, \r\n                \"value\": \"bar\"\r\n            }\r\n        ]\r\n    }\r\n}\r\n<\/pre>\n<p id=\"2a8136a8bb2e68218c9d228199bed51f\" class=\"ne-p\"><strong><span class=\"ne-text\">12.4 \u5220\u9664\u76ee\u5f55<\/span><\/strong><\/p>\n<p id=\"f9839d83a9160e516c1d1a67afbd0ace\" class=\"ne-p\"><span class=\"ne-text\">\u548c linux \u5220\u9664\u76ee\u5f55\u7684\u8bbe\u8ba1\u4e00\u6837\uff0c\u8981\u533a\u522b\u7a7a\u76ee\u5f55\u548c\u975e\u7a7a\u76ee\u5f55\u3002\u5220\u9664\u7a7a\u76ee\u5f55\u5f88\u7b80\u5355\uff0c\u4f7f\u7528 <\/span><code class=\"ne-code\"><span class=\"ne-text\">DELETE<\/span><\/code><span class=\"ne-text\"> \u65b9\u6cd5\uff0c\u5e76\u6dfb\u52a0\u4e0a <\/span><code class=\"ne-code\"><span class=\"ne-text\">dir=true<\/span><\/code><span class=\"ne-text\"> \u53c2\u6570\uff0c\u7c7b\u4f3c\u4e8e <\/span><code class=\"ne-code\"><span class=\"ne-text\">rmdir\u3002<\/span><\/code><span class=\"ne-text\">\u800c\u5bf9\u4e8e\u975e\u7a7a\u76ee\u5f55\uff0c\u9700\u8981\u6dfb\u52a0\u4e0a <\/span><code class=\"ne-code\"><span class=\"ne-text\">recursive=true<\/span><\/code><span class=\"ne-text\">\uff0c\u7c7b\u4f3c\u4e8e <\/span><code class=\"ne-code\"><span class=\"ne-text\">rm -rf<\/span><\/code><span class=\"ne-text\">\u3002<\/span><\/p>\n<pre id=\"dapJp\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http DELETE http:\/\/127.0.0.1:2379\/v2\/keys\/queue dir==true\r\nHTTP\/1.1 403 Forbidden\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 78\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:20:12 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 37\r\n\r\n{\r\n    \"cause\": \"\/queue\", \r\n    \"errorCode\": 108, \r\n    \"index\": 37, \r\n    \"message\": \"Directory not empty\"\r\n}<\/pre>\n<p id=\"1e2ee5ad91c0ab4c5e59b9c9e157d7ea\" class=\"ne-p\"><span class=\"ne-text\">\u76ee\u5f55\u4e0b\u6709key\u65f6\u63d0\u793a &#8220;Directory not empty&#8221;\uff0c\u53ef\u4ee5\u9012\u5f52\u5220\u9664<\/span><\/p>\n<pre id=\"zLg22\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http DELETE http:\/\/127.0.0.1:2379\/v2\/keys\/queue dir==true recursive==true\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 168\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:24:53 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\nX-Etcd-Index: 38\r\nX-Raft-Index: 749\r\nX-Raft-Term: 8\r\n\r\n{\r\n    \"action\": \"delete\", \r\n    \"node\": {\r\n        \"createdIndex\": 29, \r\n        \"dir\": true, \r\n        \"key\": \"\/queue\", \r\n        \"modifiedIndex\": 38\r\n    }, \r\n    \"prevNode\": {\r\n        \"createdIndex\": 29, \r\n        \"dir\": true, \r\n        \"key\": \"\/queue\", \r\n        \"modifiedIndex\": 29\r\n    }\r\n}\r\n<\/pre>\n<h3 id=\"O1Qxt\"><span class=\"ne-text\">13.\u6210\u5458\u7ba1\u7406<\/span><\/h3>\n<p id=\"fa55a5cce9e97e636898b13bb6bc2110\" class=\"ne-p\"><span class=\"ne-text\">etcd \u5728 <\/span><code class=\"ne-code\"><span class=\"ne-text\">\/v2\/members<\/span><\/code><span class=\"ne-text\"> \u4e0b\u4fdd\u5b58\u7740\u96c6\u7fa4\u4e2d\u5404\u4e2a\u6210\u5458\u7684\u4fe1\u606f\u3002<\/span><\/p>\n<p id=\"6b0c9d72d387edcb07aa55ffc4f2ffc8\" class=\"ne-p\"><strong><span class=\"ne-text\">13.1 \u5217\u8868\u67e5\u770b\u5404\u4e2a\u6210\u5458\u7684\u4fe1\u606f<\/span><\/strong><\/p>\n<pre id=\"1qQP3\" class=\"ne-codeblock\" data-language=\"bash\">ubuntu@VM-0-13-ubuntu:~$ http http:\/\/127.0.0.1:2379\/v2\/members\r\nHTTP\/1.1 200 OK\r\nAccess-Control-Allow-Headers: accept, content-type, authorization\r\nAccess-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: 131\r\nContent-Type: application\/json\r\nDate: Tue, 27 Oct 2020 07:25:38 GMT\r\nX-Etcd-Cluster-Id: cdf818194e3a8c32\r\n\r\n{\r\n    \"members\": [\r\n        {\r\n            \"clientURLs\": [\r\n                \"http:\/\/0.0.0.0:2379\"\r\n            ], \r\n            \"id\": \"8e9e05c52164694d\", \r\n            \"name\": \"default\", \r\n            \"peerURLs\": [\r\n                \"http:\/\/localhost:2380\"\r\n            ]\r\n        }\r\n    ]\r\n}\r\n<\/pre>\n<p id=\"3d087bbd07dbc3440f1ac598ca1dac6f\" class=\"ne-p\"><strong><span class=\"ne-text\">13.2 \u53ef\u4ee5\u901a\u8fc7 <\/span><\/strong><code class=\"ne-code\"><\/code><strong><span class=\"ne-text\">POST<\/span><\/strong><strong><span class=\"ne-text\"> \u65b9\u6cd5\u6dfb\u52a0\u6210\u5458<\/span><\/strong><\/p>\n<pre id=\"nxdy7\" class=\"ne-codeblock\" data-language=\"bash\">curl http:\/\/10.0.0.10:2379\/v2\/members -XPOST \\\r\n  H \"Content-Type: application\/json\" -d '{\"peerURLs\":[\"http:\/\/10.0.0.10:2380\"]}'<\/pre>\n<p id=\"2c1dc1d0dbfc2c391d3060f1ba70900b\" class=\"ne-p\"><strong><span class=\"ne-text\">13.3\u00a0\u53ef\u4ee5\u901a\u8fc7 <\/span><\/strong><code class=\"ne-code\"><\/code><strong><span class=\"ne-text\">DELETE<\/span><\/strong><strong><span class=\"ne-text\"> \u65b9\u6cd5\u5220\u9664\u6210\u5458<\/span><\/strong><\/p>\n<pre id=\"hmIC7\" class=\"ne-codeblock\" data-language=\"bash\">curl http:\/\/10.0.0.10:2379\/v2\/members\/272e204152 -XDELETE<\/pre>\n<p id=\"167b19224ef32d91c55c8a63297909e9\" class=\"ne-p\"><strong><span class=\"ne-text\">13.4\u00a0\u901a\u8fc7 PUT \u66f4\u65b0\u6210\u5458\u7684 peer url<\/span><\/strong><\/p>\n<pre id=\"EPThC\" class=\"ne-codeblock\" data-language=\"bash\">1. curl http:\/\/10.0.0.10:2379\/v2\/members\/272e204152 -XPUT \\\r\n2. -H \"Content-Type: application\/json\" -d '{\"peerURLs\":[\"http:\/\/10.0.0.10:2380\"]}'<\/pre>\n<h3 id=\"Zx0je\"><span class=\"ne-text\">14.\u67e5\u770b\u96c6\u7fa4\u6570\u636e\u4fe1\u606f<\/span><\/h3>\n<p id=\"8e8b30625ab8509e326c2e043cc6c138\" class=\"ne-p\"><span class=\"ne-text\">etcd \u4e2d\u8fd8\u4fdd\u5b58\u4e86\u96c6\u7fa4\u7684\u6570\u636e\u4fe1\u606f\uff0c\u5305\u62ec\u8282\u70b9\u4e4b\u95f4\u7684\u7f51\u7edc\u4fe1\u606f\u3001\u64cd\u4f5c\u7684\u7edf\u8ba1\u4fe1\u606f\u3002<\/span><\/p>\n<ul class=\"ne-ul\">\n<li id=\"92d3828826015594c0b7683f0a597cb5\"><code class=\"ne-code\"><span class=\"ne-text\">\/v2\/stats\/leader<\/span><\/code><span class=\"ne-text\">\u4f1a\u8fd4\u56de\u96c6\u7fa4\u4e2d leader \u7684\u4fe1\u606f\uff0c\u4ee5\u53ca followers \u7684\u57fa\u672c\u4fe1\u606f\u3002<\/span><\/li>\n<li id=\"ddb4212746c5d6c31dc1f55358f64056\"><code class=\"ne-code\"><span class=\"ne-text\">\/v2\/stats\/self<\/span><\/code><span class=\"ne-text\"> \u4f1a\u8fd4\u56de\u5f53\u524d\u8282\u70b9\u7684\u4fe1\u606f\u3002<\/span><\/li>\n<\/ul>\n<ul class=\"ne-ul\">\n<li id=\"560814f48a930a91aecdf2ab96c3217e\"><code class=\"ne-code\"><span class=\"ne-text\">\/v2\/state\/store<\/span><\/code><span class=\"ne-text\">\uff1a\u4f1a\u8fd4\u56de\u5404\u79cd\u547d\u4ee4\u7684\u7edf\u8ba1\u4fe1\u606f\u3002<\/span><\/li>\n<\/ul>\n<h3 id=\"Xgahs\"><span class=\"ne-text\">15.\u9690\u85cf\u7684\u8282\u70b9<\/span><\/h3>\n<p id=\"2a9e4abd5f4bc048adb3733fb3f44742\" class=\"ne-p\"><span class=\"ne-text\">etcd \u4e2d\u8282\u70b9\u4e5f\u53ef\u4ee5\u662f\u9ed8\u8ba4\u9690\u85cf\u7684\uff0c\u7c7b\u4f3c\u4e8e linux \u4e2d\u4ee5\u201c<\/span><code class=\"ne-code\"><span class=\"ne-text\">.<\/span><\/code><span class=\"ne-text\">\u201d\u5f00\u5934\u7684\u6587\u4ef6\u6216\u8005\u6587\u4ef6\u5939\uff0c<\/span><span class=\"ne-text\">\u4ee5 <\/span><code class=\"ne-code\"><span class=\"ne-text\">_<\/span><\/code><span class=\"ne-text\"> \u5f00\u5934\u7684\u8282\u70b9\u4e5f\u662f\u9ed8\u8ba4\u9690\u85cf\u7684\uff0c\u4e0d\u4f1a\u5728\u5217\u51fa\u76ee\u5f55\u7684\u65f6\u5019\u663e\u793a\u3002\u53ea\u6709\u77e5\u9053\u9690\u85cf\u8282\u70b9\u7684\u5b8c\u6574\u8def\u5f84\uff0c\u624d\u80fd\u591f\u8bbf\u95ee\u5b83\u7684\u4fe1\u606f\u3002<\/span><\/p>\n<h1 id=\"hg1hF\"><span class=\"ne-text\">8 c++\u5c01\u88c5libcurl\u5b9e\u73b0etcd\u6570\u636e\u64cd\u4f5c<\/span><\/h1>\n<h2 id=\"upDYe\"><span class=\"ne-text\">\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93<\/span><\/h2>\n<p id=\"bdd4e2f50b9f937a72000442e335416a\" class=\"ne-p\"><span class=\"ne-text\">\u5b89\u88c5jsoncpp<\/span><\/p>\n<p id=\"82bb205188c90b707440e099225d5bf6\" class=\"ne-p\"><span class=\"ne-text\">sudo apt-get install libjsoncpp-dev<\/span><\/p>\n<h2 id=\"aSi9s\"><span class=\"ne-text\">get\u5b9e\u73b0<\/span><\/h2>\n<p id=\"f449fe7ffd1c12bc2ed1187144e05c1f\" class=\"ne-p\"><span class=\"ne-text\">libcurl\u4e3ac\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e00\u5957HTTP RESTful API\u4f8b\u5982\u8981\u5b9e\u73b0\u4e0a\u9762\u7684\u83b7\u53d6\u4e00\u4e2a\u503c\u7684\u65b9\u6cd5\uff1a<\/span><\/p>\n<pre id=\"tg0gj\" class=\"ne-codeblock\" data-language=\"cpp\">#include &lt;curl\/curl.h&gt;\r\n#include &lt;jsoncpp\/json\/json.h&gt;\r\n#include &lt;iostream&gt;\r\n\r\nusing namespace std;\r\nusing namespace Json;\r\n\r\nsize_t process_data(void *buffer, size_t size, size_t nmemb, void *user_p)\r\n{\r\n\t\/* \u83b7\u53d6json\u7684value *\/\r\n\tValue root;\r\n\tValue node;\r\n\tReader reader;\r\n\tFastWriter writer;\r\n\tstring json = (char*)buffer;\r\n\r\n\tif(!reader.parse(json, root))\r\n\t{\r\n\t\tcout &lt;&lt; \"parse json error\" &lt;&lt; endl;\t\r\n\t\treturn 0;\r\n\t}\r\n\tstring nodeString = writer.write(root[\"node\"]);\r\n\tif(!reader.parse(nodeString, node))\r\n\t{\r\n\t\tcout &lt;&lt; \"parse json error\" &lt;&lt; endl;\t\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tcout &lt;&lt; node[\"value\"] &lt;&lt; endl;\r\n\r\n\treturn 0;\r\n}\r\n\r\nint main(int argc, char **argv)\r\n{\r\n\t\/\/\u521d\u59cb\u5316libcurl\r\n\tCURLcode return_code;\r\n\treturn_code = curl_global_init(CURL_GLOBAL_SSL);\r\n\tif (CURLE_OK != return_code)\r\n\t{\r\n\t\tcerr &lt;&lt; \"init libcurl failed.\" &lt;&lt; endl;\r\n\t\treturn -1;\r\n\t}\r\n\r\n\t\/\/ \u83b7\u53d6easy handle\r\n\tCURL *easy_handle = curl_easy_init();\r\n\tif (NULL == easy_handle)\r\n\t{\r\n\t\tcerr &lt;&lt; \"get a easy handle failed.\" &lt;&lt; endl;\r\n\t\tcurl_global_cleanup(); \r\n\r\n\t\treturn -1;\r\n\t}\r\n\r\n\tchar * buff_p = NULL;\r\n\r\n\t\/\/ \u8bbe\u7f6eeasy handle\u5c5e\u6027\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_URL, \"http:\/\/127.0.0.1\/v2\/keys\/message1\");\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_PORT, 2379);\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, &amp;process_data);\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buff_p);\r\n\r\n\t\/\/ \u6267\u884c\u6570\u636e\u8bf7\u6c42\r\n\tcurl_easy_perform(easy_handle);\t\r\n\r\n\t\/\/ \u91ca\u653e\u8d44\u6e90\r\n\r\n\tcurl_easy_cleanup(easy_handle);\r\n\tcurl_global_cleanup();\r\n\r\n\treturn 0;\r\n}<\/pre>\n<p id=\"b64f270cc290f686577bf284f2f252c0\" class=\"ne-p\"><span class=\"ne-text\">\u7531\u4e8eetcd\u8fd4\u56de\u7684\u6570\u636e\u90fd\u662f\u4ee5json\u7684\u5f62\u5f0f\uff0c\u6240\u4ee5\u4ee3\u7801\u4e2d\u8fd8\u589e\u52a0\u4e86\u4e00\u6bb5\u5bf9json\u7684\u5904\u7406\u3002\u00a0<\/span><\/p>\n<p id=\"1fe1e7fa4861df0c9dc0cf4a6898abbe\" class=\"ne-p\">\n<h2 id=\"KdThe\"><span class=\"ne-text\">set\u5b9e\u73b0<\/span><\/h2>\n<p id=\"ef0c3898db9efcf00a307406a8dd055c\" class=\"ne-p\"><span class=\"ne-text\">\u5b9e\u73b0\u8bbe\u7f6e\u4e00\u4e2akey\u7684\u529f\u80fd\uff1a<\/span><\/p>\n<pre id=\"emgeF\" class=\"ne-codeblock\" data-language=\"cpp\">\/\/ set.cpp\r\n\/\/ \u7f16\u8bd1\uff1ag++ -o set set.cpp -lcurl -ljsoncpp\r\n#include &lt;curl\/curl.h&gt;\r\n#include &lt;stdio.h&gt;\r\n#include &lt;string.h&gt;\r\n\r\nint etcd_set(char *key, char *value, char *token)\r\n{\r\n#define URL_MAX_LEN 50\r\n#define VALUE_LEN 1024\r\n\r\n         \/\/\u521d\u59cb\u5316libcurl\r\n\tCURLcode return_code;\r\n\tchar etcd_url[URL_MAX_LEN];\r\n    char etcd_value[VALUE_LEN]; \r\n\t\r\n        return_code = curl_global_init(CURL_GLOBAL_SSL);\r\n\tif (CURLE_OK != return_code)\r\n\t{\r\n\t\t\/\/cerr &lt;&lt; \"init libcurl failed.\" &lt;&lt; endl;\r\n\t\tprintf(\"init libcurl failed\\n\");\r\n\t\treturn -1;\r\n\t}\r\n\r\n\tsprintf(etcd_url, \"http:\/\/127.0.0.1:2379\/v2\/keys%s\", key);\r\n\tsprintf(etcd_value, \"value=%s\", value);\r\n\r\n\t\/\/ \u83b7\u53d6easy handle\r\n\tCURL *easy_handle = curl_easy_init();\r\n\tif (NULL == easy_handle)\r\n\t{\r\n\t\t\/\/cerr &lt;&lt; \"get a easy handle failed.\" &lt;&lt; endl;\r\n\t\tprintf(\"get a easy handle failed.\\n\");\r\n\t\tcurl_global_cleanup(); \r\n\t\treturn -1;\r\n\t}\r\n\r\n\t\/\/ \u8bbe\u7f6eeasy handle\u5c5e\u6027\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_URL, etcd_url); \r\n\tcurl_easy_setopt(easy_handle, CURLOPT_POST, 1);\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_POSTFIELDS, etcd_value);\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_CUSTOMREQUEST, \"PUT\");\r\n\r\n\t\/\/ \u6267\u884c\u6570\u636e\u8bf7\u6c42\r\n\tcurl_easy_perform(easy_handle); \r\n\r\n\t\/\/ \u91ca\u653e\u8d44\u6e90\r\n\tcurl_easy_cleanup(easy_handle);\r\n\tcurl_global_cleanup();\r\n\treturn 0;\r\n}\r\n\r\nint main(void)\r\n{\r\n\tetcd_set(\"\/message1\", \"darren\", NULL);\r\n\treturn 0;\r\n}<\/pre>\n<p id=\"3c469a6b82d1ec8f16a075054a2e460d\" class=\"ne-p\">\n<h2 id=\"1qXPc\"><span class=\"ne-text\">watch\u5b9e\u73b0<\/span><\/h2>\n<p id=\"3660d0dee5f9099a4415a2ffaed15d8b\" class=\"ne-p\"><span class=\"ne-text\">\u76d1\u63a7\u4e00\u4e2a\u503c\u7684\u53d8\u5316\u3002\u8fd9\u4e2a\u5728\u4e0a\u9762\u83b7\u53d6\u4e00\u4e2akey\u7684\u503c\u7684\u57fa\u7840\u4e0a\u6765\u5b9e\u73b0\uff0c\u53ea\u9700\u8981\u6539\u53d8\u5176url\uff0c\u5176\u5b83\u4e0d\u505a\u6539\u52a8\u5373\u53ef\u3002<\/span><\/p>\n<pre id=\"6drNd\" class=\"ne-codeblock\" data-language=\"cpp\">\/\/ watch.cpp\r\n\/\/ \u7f16\u8bd1\uff1ag++ -o watch watch.cpp -lcurl -ljsoncpp\r\n#include &lt;curl\/curl.h&gt;\r\n#include &lt;jsoncpp\/json\/json.h&gt;\r\n#include &lt;iostream&gt;\r\n\r\nusing namespace std;\r\nusing namespace Json;\r\n\r\nsize_t process_data(void *buffer, size_t size, size_t nmemb, void *user_p)\r\n{\r\n\t\/* \u83b7\u53d6json\u7684value *\/\r\n\tValue root;\r\n\tValue node;\r\n\tReader reader;\r\n\tFastWriter writer;\r\n\tstring json = (char*)buffer;\r\n\r\n\tif(!reader.parse(json, root))\r\n\t{\r\n\t\tcout &lt;&lt; \"parse json error\" &lt;&lt; endl;\t\r\n\t\treturn 0;\r\n\t}\r\n\tstring nodeString = writer.write(root[\"node\"]);\r\n\tif(!reader.parse(nodeString, node))\r\n\t{\r\n\t\tcout &lt;&lt; \"parse json error\" &lt;&lt; endl;\t\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tcout &lt;&lt; node[\"value\"] &lt;&lt; endl;\r\n\r\n\treturn 0;\r\n}\r\n\r\nint main(int argc, char **argv)\r\n{\r\n\t\/\/\u521d\u59cb\u5316libcurl\r\n\tCURLcode return_code;\r\n\treturn_code = curl_global_init(CURL_GLOBAL_SSL);\r\n\tif (CURLE_OK != return_code)\r\n\t{\r\n\t\tcerr &lt;&lt; \"init libcurl failed.\" &lt;&lt; endl;\r\n\t\treturn -1;\r\n\t}\r\n\r\n\t\/\/ \u83b7\u53d6easy handle\r\n\tCURL *easy_handle = curl_easy_init();\r\n\tif (NULL == easy_handle)\r\n\t{\r\n\t\tcerr &lt;&lt; \"get a easy handle failed.\" &lt;&lt; endl;\r\n\t\tcurl_global_cleanup(); \r\n\r\n\t\treturn -1;\r\n\t}\r\n\r\n\tchar * buff_p = NULL;\r\n\r\n\t\/\/ \u8bbe\u7f6eeasy handle\u5c5e\u6027\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_URL, \"http:\/\/127.0.0.1\/v2\/keys\/message1?wait=true\");\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_PORT, 2379);\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, &amp;process_data);\r\n\tcurl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buff_p);\r\n\r\n\t\/\/ \u6267\u884c\u6570\u636e\u8bf7\u6c42\r\n\tcurl_easy_perform(easy_handle);\t\r\n\r\n\t\/\/ \u91ca\u653e\u8d44\u6e90\r\n\r\n\tcurl_easy_cleanup(easy_handle);\r\n\tcurl_global_cleanup();\r\n\r\n\treturn 0;\r\n}<\/pre>\n<p id=\"f4e70712418458f2d9cdabf711b19df0\" class=\"ne-p\"><span class=\"ne-text\">\u4ee5\u4e0a\u662f\u6211\u5b9e\u73b0\u7684\u7b80\u5355\u7684etcd\u63a5\u53e3\uff0c\u8bfb\u8005\u53ef\u4ee5\u901a\u8fc7\u672c\u535a\u5ba2\u6216\u8005\u6839\u636elibcurl\u63d0\u4f9b\u7684http RESTful API\u6765\u5b9e\u73b0etcd\u652f\u6301\u7684\u66f4\u591a\u7684\u63a5\u53e3\u3002<\/span><\/p>\n<p id=\"18c35c29fc24b28821b3a23f1725f89b\" class=\"ne-p\"><span class=\"ne-text\">\u53e6\u5916\uff0c\u57fa\u4e8eetcd\u7684\u9ad8\u7ea7\u8bed\u8a00\u63a5\u53e3\u5728GitHub\u4e0a\u5df2\u6709\u76f8\u5f53\u591a\u7684\u5f00\u6e90\u5de5\u7a0b\uff0c\u8bfb\u8005\u611f\u5174\u8da3\u53ef\u4ee5\u5230\u8fd9\u91cc\u53bb\u4e0b\u8f7d\u67e5\u770b\u2014\u2014&gt;<\/span><a class=\"ne-link\" href=\"https:\/\/github.com\/coreos\/etcd\/blob\/master\/Documentation\/libraries-and-tools.md\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/coreos\/etcd\/blob\/master\/Documentation\/libraries-and-tools.md\"><span class=\"ne-text\">\u9ad8\u7ea7\u8bed\u8a00\u5c01\u88c5\u7684etcd<\/span><\/a><span class=\"ne-text\">\u63a5\u53e3\u3002<\/span><\/p>\n<h1 id=\"R09wK\"><span class=\"ne-text\">8 \u5728\u7cfb\u7edf\u4e2d\u7528etcd\u5b9e\u73b0\u670d\u52a1\u6ce8\u518c\u548c\u53d1\u73b0<\/span><\/h1>\n<p id=\"6f203c61225d8e942afeede8f2a1c020\" class=\"ne-p\"><span class=\"ne-text\">\u5e76\u5c06\u81ea\u5df1\u7684\u4fe1\u606f\u4ee5key,value\u5f62\u5f0f\uff08key:serviceId\uff0cvalue:ip\u5730\u5740\u3001\u7aef\u53e3\u7b49\u4fe1\u606f\uff09<\/span><\/p>\n<p id=\"5ebfb7245b80f277dd914fa83f07022c\" class=\"ne-p\"><span class=\"ne-text\">\u5728\u914d\u7f6e\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u4e5f\u5199\u4e0a\u5bf9\u5e94\u7684<\/span><\/p>\n<ul class=\"ne-ul\">\n<li id=\"3deb19209c8588a5850fba6756dac74a\"><span class=\"ne-text\">serverid<\/span><\/li>\n<li id=\"bf344a1afa52e8ac13024599ec59d87a\"><span class=\"ne-text\">ip<\/span><\/li>\n<\/ul>\n<ul class=\"ne-ul\">\n<li id=\"e7a7c6e6c617ee7c69ad311dc6e7bebb\"><span class=\"ne-text\">port<\/span><\/li>\n<\/ul>\n<p id=\"d552141d1a58bee1f9e29692478005cd\" class=\"ne-p\"><span class=\"ne-text\">\u5728\u5373\u65f6\u901a\u8baf\u9879\u76ee:\u6211\u4eec\u6682\u4e14\u8fd9\u4e48\u547d\u540dxxxx-xxxxx\uff0c\u524d\u9762xxxx\u4ee3\u8868\u670d\u52a1<\/span><\/p>\n<p id=\"512b0a75a2648324d971a0c57924de02\" class=\"ne-p\"><span class=\"ne-text\">0001 \u4ee3\u8868login_server<\/span><\/p>\n<p id=\"8cf73103c397bd5d8732620010e487fc\" class=\"ne-p\"><span class=\"ne-text\">0002 \u4ee3\u8868msg_server<\/span><\/p>\n<p id=\"2e2333dda87650fae10c4305f82eb98d\" class=\"ne-p\"><span class=\"ne-text\">0003 \u4ee3\u8868route_server<\/span><\/p>\n<p id=\"d711f761e783824fefdb1f198740125c\" class=\"ne-p\"><span class=\"ne-text\">0004 \u4ee3\u8868db_proxy_server<\/span><\/p>\n<p id=\"286ad8063e3c6872d16dfc9b105db38f\" class=\"ne-p\"><span class=\"ne-text\">0005 \u4ee3\u8868file_server<\/span><\/p>\n<p id=\"6ab29e5494b540c3d6a109481a9c5409\" class=\"ne-p\"><span class=\"ne-text\">0006 \u4ee3\u8868http_msg_server<\/span><\/p>\n<p id=\"90a2015c376995917252e5cdf56199aa\" class=\"ne-p\"><span class=\"ne-text\">0007 \u4ee3\u8868push_server<\/span><\/p>\n<p id=\"2048d967f48c3b5addfa4b0ae2ffa216\" class=\"ne-p\"><span class=\"ne-text\">0008 \u4ee3\u8868msfs<\/span><\/p>\n<p id=\"369677107fb60b096e027e3121f901c0\" class=\"ne-p\"><span class=\"ne-text\">\u540e\u9762xxxx\u56db\u4f4d\u4ee3\u8868\u5bf9\u5e94\u670d\u52a1\u673a\u5668\u7684\u5e8f\u53f7\u3002<\/span><\/p>\n<p id=\"96bdeedf901bcbcd9e5a960471a394bb\" class=\"ne-p\">\n<p id=\"b1110affe515e178919270422ef38523\" class=\"ne-p\"><span class=\"ne-text\">\u7cfb\u7edf\u4e2d\u5b9e\u73b0\u670d\u52a1\u6ce8\u518c\u4e0e\u53d1\u73b0\u6240\u9700\u7684\u57fa\u672c\u529f\u80fd\u6709\uff1a<\/span><\/p>\n<ul class=\"ne-ul\">\n<li id=\"b04de63251e1d12f470269999550316b\"><span class=\"ne-text\">\u670d\u52a1\u6ce8\u518c\uff1a\u540c\u4e00service\u7684\u6240\u6709\u8282\u70b9\u6ce8\u518c\u5230\u76f8\u540c\u76ee\u5f55\u4e0b\uff0c\u8282\u70b9\u542f\u52a8\u540e\u5c06\u81ea\u5df1\u7684\u4fe1\u606f\u6ce8\u518c\u5230\u6240\u5c5e\u670d\u52a1\u7684\u76ee\u5f55\u4e2d\u3002<\/span><\/li>\n<li id=\"b2dcb8a62b56b783ad2e3a4f8baff9be\"><span class=\"ne-text\">\u5065\u5eb7\u68c0\u67e5\uff1a\u670d\u52a1\u8282\u70b9\u5b9a\u65f6\u53d1\u9001\u5fc3\u8df3\uff0c\u6ce8\u518c\u5230\u670d\u52a1\u76ee\u5f55\u4e2d\u7684\u4fe1\u606f\u8bbe\u7f6e\u4e00\u4e2a\u8f83\u77ed\u7684TTL\uff0c\u8fd0\u884c\u6b63\u5e38\u7684\u670d\u52a1\u8282\u70b9\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u4f1a\u53bb\u66f4\u65b0\u4fe1\u606f\u7684TTL\u3002<\/span><\/li>\n<\/ul>\n<ul class=\"ne-ul\">\n<li id=\"d745f17187e7a83c372cb3914b7a0d8a\"><span class=\"ne-text\">\u670d\u52a1\u53d1\u73b0\uff1a\u901a\u8fc7\u540d\u79f0\u80fd\u67e5\u8be2\u5230\u670d\u52a1\u63d0\u4f9b\u5916\u90e8\u8bbf\u95ee\u7684 IP \u548c\u7aef\u53e3\u53f7\u3002\u6bd4\u5982\u7f51\u5173\u4ee3\u7406\u670d\u52a1\u65f6\u80fd\u591f\u53ca\u65f6\u7684\u53d1\u73b0\u670d\u52a1\u4e2d\u65b0\u589e\u8282\u70b9\u3001\u4e22\u5f03\u4e0d\u53ef\u7528\u7684\u670d\u52a1\u8282\u70b9\uff0c\u540c\u65f6\u5404\u4e2a\u670d\u52a1\u95f4\u4e5f\u80fd\u611f\u77e5\u5bf9\u65b9\u7684\u5b58\u5728\u3002<\/span><\/li>\n<\/ul>\n<p id=\"c0694a9f046449bef91f2d06f5b7af5d\" class=\"ne-p\"><span class=\"ne-text\">\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\uff0c\u5982\u4f55\u7ba1\u7406\u8282\u70b9\u95f4\u7684\u72b6\u6001\u4e00\u76f4\u662f\u4e00\u4e2a\u96be\u9898\uff0cetcd \u662f\u7531\u5f00\u53d1\u5e76\u7ef4\u62a4\u7684\uff0c\u5b83\u4f7f\u7528 Go \u8bed\u8a00\u7f16\u5199\uff0c\u5e76\u901a\u8fc7Raft \u4e00\u81f4\u6027\u7b97\u6cd5\u5904\u7406\u65e5\u5fd7\u590d\u5236\u4ee5\u4fdd\u8bc1\u5f3a\u4e00\u81f4\u6027\u3002etcd\u50cf\u662f\u4e13\u95e8\u4e3a\u96c6\u7fa4\u73af\u5883\u7684\u670d\u52a1\u53d1\u73b0\u548c\u6ce8\u518c\u800c\u8bbe\u8ba1\uff0c\u5b83\u63d0\u4f9b\u4e86\u6570\u636e TTL \u5931\u6548\u3001\u6570\u636e\u6539\u53d8\u76d1\u89c6\u3001\u591a\u503c\u3001\u76ee\u5f55\u76d1\u542c\u3001\u5206\u5e03\u5f0f\u9501\u539f\u5b50\u64cd\u4f5c\u7b49\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u7684\u8ddf\u8e2a\u5e76\u7ba1\u7406\u96c6\u7fa4\u8282\u70b9\u7684\u72b6\u6001\u3002<\/span><\/p>\n<p id=\"e1d37d16c262aaa61ba20f628c51771e\" class=\"ne-p\"><img decoding=\"async\" id=\"a8SaY\" class=\"ne-image\" src=\"https:\/\/cdn.nlark.com\/yuque\/0\/2020\/png\/708652\/1605171223382-d8b0cfaf-7aac-491a-a7a0-de0e666faafe.png\" width=\"569\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"index-module_reward_Uu00Q\">\n<div class=\"like-module_larkLike_m0Gno\"><\/div>\n<\/div>\n<\/article>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"WithToc-module_tocWrapper_1GHcw\">\n<div class=\"WithToc-module_toc_2rHJC\">\n<div class=\"larkui-synopsis-wrap undefined\" data-testid=\"larkui-synopsis\">\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 &nbsp; \u6ca1\u6709go\u73af\u5883\u7684\u5148<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[118],"class_list":["post-5392","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=5392"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5392\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=5392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=5392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=5392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}