{"id":18289,"date":"2024-11-18T13:08:13","date_gmt":"2024-11-18T05:08:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18289\/"},"modified":"2024-11-18T13:08:13","modified_gmt":"2024-11-18T05:08:13","slug":"docker%e6%80%8e%e4%b9%88%e5%a4%8d%e5%88%b6redis","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18289\/","title":{"rendered":"docker\u600e\u4e48\u590d\u5236redis"},"content":{"rendered":"<blockquote><p>\n  \u5728 docker \u4e2d\u590d\u5236 redis \u9700\u8981\u8bbe\u7f6e\u4e3b\u4ece\u590d\u5236\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a1. \u521b\u5efa\u4e3b redis \u5bb9\u5668\uff1b2. \u542f\u52a8\u526f\u672c\u5bb9\u5668\u5e76\u8fde\u63a5\u5230\u4e3b\u5bb9\u5668\uff1b3. \u9a8c\u8bc1\u590d\u5236\uff1b4. \u6267\u884c\u6545\u969c\u8f6c\u79fb\uff08\u5982\u679c\u9700\u8981\uff09\uff1b5. \u6269\u5c55\u526f\u672c\uff08\u53ef\u9009\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/05\/2024060508421859859.jpg\" class=\"aligncenter\" title=\"docker\u600e\u4e48\u590d\u5236redis\u63d2\u56fe\" alt=\"docker\u600e\u4e48\u590d\u5236redis\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Docker \u4e2d\u590d\u5236 Redis<\/strong><\/p>\n<p>\u5728 Docker \u4e2d\u590d\u5236 Redis \u6d89\u53ca\u521b\u5efa\u4e3b\u4ece\u590d\u5236\u8bbe\u7f6e\u3002\u4ee5\u4e0b\u6b65\u9aa4\u5c06\u6307\u5bfc\u4f60\u5b8c\u6210\u6b64\u8fc7\u7a0b\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u4e3b Redis \u5bb9\u5668<\/strong><\/p>\n<pre>docker run -d --name redis-master redis:latest<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u542f\u52a8\u526f\u672c\u5bb9\u5668\u5e76\u8fde\u63a5\u5230\u4e3b\u5bb9\u5668<\/strong><\/p>\n<pre>docker run --rm -it --link redis-master:redis redis:latest \n  redis-cli --slaveof redis-master 6379<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u9a8c\u8bc1\u590d\u5236<\/strong><\/p>\n<pre>docker exec redis-master redis-cli info replication<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u5c06\u5728\u4e3b\u5bb9\u5668\u4e2d\u8f93\u51fa\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<pre>connected_slaves:1\nslave0:ip=172.17.0.2,port=6379,state=online,offset=14467,lag=0<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u6545\u969c\u8f6c\u79fb<\/strong><\/p>\n<p>\u5982\u679c\u4e3b\u5bb9\u5668\u53d1\u751f\u6545\u969c\uff0c\u5c06\u81ea\u52a8\u89e6\u53d1\u6545\u969c\u8f6c\u79fb\uff0c\u5e76\u9009\u62e9\u4e00\u4e2a\u526f\u672c\u4f5c\u4e3a\u65b0\u4e3b\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u624b\u52a8\u89e6\u53d1\u6545\u969c\u8f6c\u79fb\uff1a<\/p>\n<pre>docker exec redis-master redis-cli SLAVEOF NO ONE<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u6269\u5c55\u526f\u672c<\/strong><\/p>\n<p>\u8981\u6269\u5c55\u526f\u672c\u6570\u91cf\uff0c\u8bf7\u91cd\u590d\u6b65\u9aa4 2\u3002\u6bcf\u4e2a\u526f\u672c\u5c06\u81ea\u52a8\u8fde\u63a5\u5230\u4e3b\u5bb9\u5668\u3002<\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 &#8211;net=host \u53c2\u6570\u5141\u8bb8\u5bb9\u5668\u76f4\u63a5\u4f7f\u7528\u4e3b\u673a\u7684\u7f51\u7edc\u5806\u6808\uff0c\u4ece\u800c\u7b80\u5316\u5bb9\u5668\u4e4b\u95f4\u7684\u901a\u4fe1\u3002<\/li>\n<li>\u4e3a\u5bb9\u5668\u5206\u914d\u6301\u4e45\u6027\u5b58\u50a8\uff0c\u4ee5\u4fdd\u7559\u6570\u636e\uff0c\u5373\u4f7f\u5bb9\u5668\u91cd\u65b0\u542f\u52a8\u6216\u53d1\u751f\u6545\u969c\u3002<\/li>\n<li>\u76d1\u63a7\u590d\u5236\u8bbe\u7f6e\uff0c\u786e\u4fdd\u6240\u6709\u526f\u672c\u90fd\u6b63\u5e38\u8fd0\u884c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u590d\u5236\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 docker \u4e2d\u590d\u5236 redis \u9700\u8981\u8bbe\u7f6e\u4e3b\u4ece\u590d\u5236\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a1. \u521b\u5efa\u4e3b redis \u5bb9\u5668\uff1b2. \u542f\u52a8\u526f\u672c\u5bb9\u5668\u5e76\u8fde\u63a5\u5230\u4e3b\u5bb9\u5668\uff1b3. \u9a8c\u8bc1\u590d\u5236\uff1b4. \u6267\u884c\u6545\u969c\u8f6c\u79fb\uff08\u5982\u679c\u9700\u8981\uff09\uff1b5. \u6269\u5c55\u526f\u672c\uff08\u53ef\u9009\uff09\u3002 \u5982\u4f55\u5728 Docker \u4e2d\u590d\u5236 Redis \u5728 Docker \u4e2d\u590d\u5236 Redis \u6d89\u53ca\u521b\u5efa\u4e3b\u4ece\u590d\u5236\u8bbe\u7f6e\u3002\u4ee5\u4e0b\u6b65\u9aa4\u5c06\u6307\u5bfc\u4f60\u5b8c\u6210\u6b64\u8fc7\u7a0b\uff1a 1. \u521b\u5efa\u4e3b Redis \u5bb9\u5668 docker run -d &#8211;name redis-master redis:latest \u767b\u5f55\u540e\u590d\u5236 2. \u542f\u52a8\u526f\u672c\u5bb9\u5668\u5e76\u8fde\u63a5\u5230\u4e3b\u5bb9\u5668 docker run &#8211;rm -it &#8211;link redis-master:redis redis:latest redis-cli &#8211;slaveof redis-master 6379 \u767b\u5f55\u540e\u590d\u5236 3. \u9a8c\u8bc1\u590d\u5236 docker exec redis-master redis-cli info replication \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18289","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18289"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18289\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}