{"id":1219,"date":"2024-07-13T10:05:08","date_gmt":"2024-07-13T02:05:08","guid":{"rendered":"http:\/\/118.178.124.79\/wordpress\/?p=1219"},"modified":"2025-04-28T11:32:06","modified_gmt":"2025-04-28T03:32:06","slug":"docker%e9%83%a8%e7%bd%b2etcd%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/minglelu.cn\/index.php\/2024\/07\/13\/1219\/","title":{"rendered":"docker\u90e8\u7f72etcd\u96c6\u7fa4"},"content":{"rendered":"\n<pre class=\"wp-block-code alignwide\"><code>\u5728CentOS 7\u7cfb\u7edf\u4e0a\u4f7f\u7528Docker\u642d\u5efaetcd\u96c6\u7fa4\uff0c\u5e76\u914d\u7f6e\u91cd\u542f\u7b56\u7565\u4e3aalways\uff08\u59cb\u7ec8\u91cd\u542f\uff09\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u8be6\u7ec6\u6d41\u7a0b\u8fdb\u884c\u64cd\u4f5c\u3002\n\n\u6b65\u9aa4 1: \u51c6\u5907\u5de5\u4f5c\n\u786e\u4fddCentOS 7\u7cfb\u7edf\u5df2\u7ecf\u5b89\u88c5\u4e86Docker\u548cDocker Compose\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u5b89\u88c5\uff1a\n\n\u5b89\u88c5Docker\uff1a\n\nbash\n\u590d\u5236\u4ee3\u7801\nsudo yum install -y docker\nsudo systemctl start docker\nsudo systemctl enable docker\n\u5b89\u88c5Docker Compose\uff1a\n\nbash\n\u590d\u5236\u4ee3\u7801\nsudo curl -L \"https:\/\/github.com\/docker\/compose\/releases\/download\/&lt;VERSION>\/docker-compose-$(uname -s)-$(uname -m)\" -o \/usr\/local\/bin\/docker-compose\nsudo chmod +x \/usr\/local\/bin\/docker-compose\n\uff08\u66ff\u6362&lt;VERSION>\u4e3a\u4f60\u8981\u5b89\u88c5\u7684Docker Compose\u7248\u672c\uff0c\u53ef\u4ee5\u5728 Docker Compose Releases \u627e\u5230\u6700\u65b0\u7684\u7248\u672c\u53f7\u3002\uff09\n\n\u6b65\u9aa4 2: \u7f16\u5199Docker Compose\u6587\u4ef6\n\u521b\u5efa\u4e00\u4e2aDocker Compose\u6587\u4ef6\uff08\u4f8b\u5982docker-compose.yml\uff09\uff0c\u7528\u4e8e\u5b9a\u4e49etcd\u96c6\u7fa4\u7684\u670d\u52a1\uff0c\u5e76\u914d\u7f6e\u91cd\u542f\u7b56\u7565\u3002\n\nyaml\n\u590d\u5236\u4ee3\u7801\nversion: '3'\n\nservices:\n  etcd1:\n    image: quay.io\/coreos\/etcd:v3.5.0\n    restart: always\n    command: >\n      etcd --name etcd1\n           --advertise-client-urls http:\/\/etcd1:2379\n           --listen-client-urls http:\/\/0.0.0.0:2379\n           --initial-advertise-peer-urls http:\/\/etcd1:2380\n           --listen-peer-urls http:\/\/0.0.0.0:2380\n           --initial-cluster-token etcd-cluster-1\n           --initial-cluster etcd1=http:\/\/etcd1:2380,etcd2=http:\/\/etcd2:2380,etcd3=http:\/\/etcd3:2380\n           --initial-cluster-state new\n    ports:\n      - \"2379:2379\"\n      - \"2380:2380\"\n\n  etcd2:\n    image: quay.io\/coreos\/etcd:v3.5.0\n    restart: always\n    command: >\n      etcd --name etcd2\n           --advertise-client-urls http:\/\/etcd2:2379\n           --listen-client-urls http:\/\/0.0.0.0:2379\n           --initial-advertise-peer-urls http:\/\/etcd2:2380\n           --listen-peer-urls http:\/\/0.0.0.0:2380\n           --initial-cluster-token etcd-cluster-1\n           --initial-cluster etcd1=http:\/\/etcd1:2380,etcd2=http:\/\/etcd2:2380,etcd3=http:\/\/etcd3:2380\n           --initial-cluster-state new\n    ports:\n      - \"22379:2379\"\n      - \"22380:2380\"\n\n  etcd3:\n    image: quay.io\/coreos\/etcd:v3.5.0\n    restart: always\n    command: >\n      etcd --name etcd3\n           --advertise-client-urls http:\/\/etcd3:2379\n           --listen-client-urls http:\/\/0.0.0.0:2379\n           --initial-advertise-peer-urls http:\/\/etcd3:2380\n           --listen-peer-urls http:\/\/0.0.0.0:2380\n           --initial-cluster-token etcd-cluster-1\n           --initial-cluster etcd1=http:\/\/etcd1:2380,etcd2=http:\/\/etcd2:2380,etcd3=http:\/\/etcd3:2380\n           --initial-cluster-state new\n    ports:\n      - \"32379:2379\"\n      - \"32380:2380\"\n\u6b65\u9aa4 3: \u542f\u52a8etcd\u96c6\u7fa4\n\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8etcd\u96c6\u7fa4\uff0c\u5e76\u786e\u4fdd\u6307\u5b9a\u4e86Docker Compose\u6587\u4ef6\u8def\u5f84\uff08\u5047\u8bbe\u6587\u4ef6\u540d\u4e3adocker-compose.yml\uff09\uff1a\n\nbash\n\u590d\u5236\u4ee3\u7801\ndocker-compose -f docker-compose.yml up -d\n\u6b65\u9aa4 4: \u9a8c\u8bc1etcd\u96c6\u7fa4\n\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1etcd\u96c6\u7fa4\u662f\u5426\u6b63\u5e38\u8fd0\u884c\uff1a\n\nbash\n\u590d\u5236\u4ee3\u7801\ndocker-compose -f docker-compose.yml ps\n\u8f93\u51fa\u5e94\u8be5\u663e\u793a\u4e09\u4e2a\u670d\u52a1 (etcd1, etcd2, etcd3) \u6b63\u5728\u8fd0\u884c\uff0c\u5e76\u4e14\u5728\u4efb\u4f55\u670d\u52a1\u56e0\u6545\u969c\u6216\u91cd\u542f\u540e\uff0cDocker\u5c06\u81ea\u52a8\u91cd\u65b0\u542f\u52a8\u5b83\u4eec\u3002\n\n\u6b65\u9aa4 5: \u4f7f\u7528etcd\u96c6\u7fa4\n\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7etcd\u7684\u5ba2\u6237\u7aef\u5de5\u5177\u6765\u8bbf\u95ee\u548c\u7ba1\u7406etcd\u96c6\u7fa4\u3002\u4f8b\u5982\uff0c\u4f7f\u7528etcdctl\u5de5\u5177\uff1a\n\nbash\n\u590d\u5236\u4ee3\u7801\ndocker run --rm -it --network=host --entrypoint=etcdctl quay.io\/coreos\/etcd:v3.5.0 --endpoints=http:\/\/localhost:2379 member list\n\u8fd9\u5c06\u5217\u51fa\u96c6\u7fa4\u4e2d\u7684\u6210\u5458\u3002<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-1219","post","type-post","status-publish","format-standard","hentry","category-cloud-computing"],"_links":{"self":[{"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/posts\/1219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1219"}],"version-history":[{"count":3,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/posts\/1219\/revisions"}],"predecessor-version":[{"id":1222,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/posts\/1219\/revisions\/1222"}],"wp:attachment":[{"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/minglelu.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}