{"id":102102,"date":"2026-09-08T07:52:00","date_gmt":"2026-09-07T23:52:00","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/102102.html"},"modified":"2026-09-08T07:52:00","modified_gmt":"2026-09-07T23:52:00","slug":"%e5%a4%9a%e5%8f%b0-linux-%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%80%8e%e4%b9%88%e7%bb%9f%e4%b8%80%e8%a3%85-docker%ef%bc%9f%e7%94%a8-ansible-playbook-%e5%9b%ba%e5%8c%96%e9%83%a8%e7%bd%b2%e6%b5%81%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/102102.html","title":{"rendered":"\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\n<ul>\n<li>\u6bcf\u65e5\u4e00\u53e5\u6b63\u80fd\u91cf<\/li>\n<li>\u524d\u8a00<\/li>\n<li>1.\u4e3a\u4ec0\u4e48\u4f7f\u7528ansible?<\/li>\n<li>2.\u5728\u4f60\u7684\u865a\u62df\u673a\u4e0a\u5b89\u88c5ansiable<\/li>\n<li>\n<ul>\n<li>2.1 \u4ec0\u4e48\u662fAnsible&#xff1f;<\/li>\n<li>2.2 Ansible\u7684\u6838\u5fc3\u4f5c\u7528<\/li>\n<li>2.3 \u5b89\u88c5ansiale<\/li>\n<\/ul>\n<\/li>\n<li>3.\u914d\u7f6eansiable\u6587\u4ef6\u641e\u5b9a\u5176\u4ed6\u4e3b\u673adocker\u90e8\u7f72<\/li>\n<li>\n<ul>\n<li>3.1 \u7f16\u5199hosts\u6587\u4ef6<\/li>\n<li>3.2 \u7f16\u5199\u5b89\u88c5docker\u8fd0\u884c\u811a\u672c<\/li>\n<li>3.3 \u6267\u884cPlaybook\u547d\u4ee4<\/li>\n<li>3.4 \u9a8c\u8bc1\u662f\u5426\u6210\u529f<\/li>\n<\/ul>\n<\/li>\n<li>4.\u5b89\u88c5cpolar\u5b9e\u73b0\u968f\u65f6\u968f\u5730\u5f00\u53d1<\/li>\n<li>5.\u914d\u7f6e\u516c\u7f51\u5730\u5740<\/li>\n<li>6.\u4fdd\u7559\u56fa\u5b9aTCP\u516c\u7f51\u5730\u5740<\/li>\n<li>\u603b\u7ed3<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235154-6a9f4e1a2858d.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>\u6bcf\u65e5\u4e00\u53e5\u6b63\u80fd\u91cf<\/h3>\n<p>\u843d\u65e5\u662f\u5929\u7a7a\u5f52\u6863\u7684\u53e5\u70b9&#xff0c; \u800c\u6211\u7684\u591c\u665a&#xff0c; \u6b63\u644a\u5f00\u4e00\u5f20\u672a\u88c1\u8fb9\u7684\u7f8a\u76ae\u7eb8\u3002<\/p>\n<h3>\u524d\u8a00<\/h3>\n<p>\u670d\u52a1\u5668\u6570\u91cf\u4e00\u591a&#xff0c;\u91cd\u590d\u5b89\u88c5\u548c\u91cd\u590d\u914d\u7f6e\u5f88\u5feb\u5c31\u4f1a\u53d8\u6210\u8fd0\u7ef4\u91cc\u7684\u56fa\u5b9a\u6210\u672c\u3002Docker \u5b89\u88c5\u3001\u8f6f\u4ef6\u6e90\u914d\u7f6e\u3001\u670d\u52a1\u542f\u52a8\u3001\u7528\u6237\u6743\u9650\u8fd9\u4e9b\u6b65\u9aa4\u5355\u72ec\u770b\u5e76\u4e0d\u590d\u6742&#xff0c;\u4f46\u5982\u679c\u9700\u8981\u5728\u591a\u53f0 Linux \u4e3b\u673a\u4e0a\u53cd\u590d\u6267\u884c&#xff0c;\u6700\u5bb9\u6613\u51fa\u73b0\u7684\u95ee\u9898\u4e0d\u662f\u201c\u4e0d\u4f1a\u88c5\u201d&#xff0c;\u800c\u662f\u6bcf\u53f0\u673a\u5668\u7684\u7ed3\u679c\u4e0d\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n<p>Ansible \u7684\u4ef7\u503c\u5c31\u5728\u8fd9\u91cc&#xff1a;\u628a\u539f\u672c\u9700\u8981\u9010\u53f0\u6267\u884c\u7684\u64cd\u4f5c\u6574\u7406\u6210\u53ef\u4ee5\u91cd\u590d\u8fd0\u884c\u7684 Playbook&#xff0c;\u518d\u901a\u8fc7\u4e3b\u673a\u6e05\u5355\u7edf\u4e00\u4e0b\u53d1\u3002\u8fd9\u6837\u505a\u7684\u91cd\u70b9\u4e0d\u662f\u7701\u6389\u51e0\u6761\u547d\u4ee4&#xff0c;\u800c\u662f\u628a\u90e8\u7f72\u6b65\u9aa4\u56fa\u5b9a\u4e0b\u6765&#xff0c;\u8ba9\u540c\u4e00\u5957 Docker \u73af\u5883\u80fd\u591f\u5728\u4e0d\u540c\u4e3b\u673a\u4e0a\u6309\u76f8\u540c\u89c4\u5219\u6267\u884c\u3002<\/p>\n<p>\u672c\u6587\u4f1a\u76f4\u63a5\u4ece Ansible \u7684\u5b89\u88c5\u548c\u57fa\u7840\u914d\u7f6e\u5f00\u59cb&#xff0c;\u968f\u540e\u7f16\u5199 hosts \u4e3b\u673a\u6e05\u5355\u4e0e deploy_docker.yml&#xff0c;\u5b8c\u6210 Docker \u6279\u91cf\u90e8\u7f72&#xff1b;\u672c\u5730\u5c40\u57df\u7f51\u6d41\u7a0b\u8dd1\u901a\u540e&#xff0c;\u518d\u901a\u8fc7 cpolar \u5efa\u7acb SSH \u516c\u7f51\u5165\u53e3&#xff0c;\u9a8c\u8bc1 Ansible \u5bf9\u5f02\u5730\u76ee\u6807\u4e3b\u673a\u7684\u8fdc\u7a0b\u6267\u884c&#xff0c;\u5e76\u7ee7\u7eed\u914d\u7f6e\u56fa\u5b9a TCP \u5730\u5740\u3002\u6574\u7bc7\u6309\u201c\u63a7\u5236\u7aef\u51c6\u5907 \u2192 Playbook \u90e8\u7f72 \u2192 \u8fdc\u7a0b\u8fde\u63a5 \u2192 \u56fa\u5b9a\u5165\u53e3\u201d\u7684\u987a\u5e8f\u5c55\u5f00\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235154-6a9f4e1a6fe24.png\" alt=\"image-20260806160737677\" \/><\/p>\n<h3>1.\u4e3a\u4ec0\u4e48\u4f7f\u7528ansible?<\/h3>\n<p>Ansible\u662f\u4e00\u6b3e\u5f00\u6e90\u3001\u65e0Agent\u67b6\u6784\u7684\u81ea\u52a8\u5316\u8fd0\u7ef4\u5de5\u5177&#xff0c;\u5b9a\u4f4d\u662f\u670d\u52a1\u5668\u6279\u91cf\u81ea\u52a8\u5316\u7ba1\u7406\u5de5\u5177&#xff0c;\u4e3b\u6253\u7b80\u5355\u6613\u7528\u3001\u65e0\u9700\u5b89\u88c5\u5ba2\u6237\u7aef\u3001Playbook\u5267\u672c\u7f16\u6392\u3002<\/p>\n<p>\u2728\u6838\u5fc3\u7279\u70b9<\/p>\n<li>\n<p>\u90e8\u7f72\u67b6\u6784\u4e0e\u4f53\u9a8c<\/p>\n<p>\u4f9d\u6258SSH\u534f\u8bae\u5b8c\u6210\u8fdc\u7a0b\u7ba1\u63a7&#xff0c;\u88ab\u7ba1\u7406\u670d\u52a1\u5668\u65e0\u9700\u5b89\u88c5\u4efb\u4f55\u4ee3\u7406\u5ba2\u6237\u7aef&#xff0c;\u53ea\u8981\u5f00\u542f SSH \u670d\u52a1\u5373\u53ef\u4f7f\u7528&#xff1b;YAML\u683c\u5f0fPlaybook\u5267\u672c\u8bed\u6cd5\u901a\u4fd7\u6613\u61c2&#xff0c;\u9605\u8bfb\u7f16\u5199\u95e8\u69db\u4f4e&#xff0c;\u4fbf\u4e8e\u56e2\u961f\u7ef4\u62a4\u3002<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u6807\u51c6\u5316\u53ef\u590d\u7528<\/p>\n<p>\u628a\u8f6f\u4ef6\u5b89\u88c5\u3001\u76ee\u5f55\u521b\u5efa\u3001\u4fee\u6539\u914d\u7f6e\u3001\u670d\u52a1\u542f\u505c\u7b49\u64cd\u4f5c\u7f16\u5199\u4e3aPlaybook\u5267\u672c&#xff0c;\u4e00\u6b21\u7f16\u5199&#xff0c;\u591a\u6b21\u6267\u884c&#xff1b;\u5355\u53f0\u8c03\u8bd5\u3001\u96c6\u7fa4\u6279\u91cf\u90e8\u7f72\u90fd\u53ef\u4ee5\u590d\u7528&#xff0c;\u4fdd\u8bc1\u591a\u53f0\u670d\u52a1\u5668\u914d\u7f6e\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e30\u5bcc\u5185\u7f6e\u6a21\u5757<\/p>\n<p>\u81ea\u5e26\u5927\u91cf\u6210\u719f\u8fd0\u7ef4\u6a21\u5757&#xff0c;\u8f6f\u4ef6\u5b89\u88c5\u3001\u6587\u4ef6\u540c\u6b65\u3001\u7528\u6237\u7ba1\u7406\u3001\u670d\u52a1\u7ba1\u7406\u90fd\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528&#xff0c;\u4e0d\u7528\u7f16\u5199\u590d\u6742shell\u811a\u672c\u903b\u8f91&#xff0c;\u51cf\u5c11shell\u811a\u672c\u7684\u6613\u9519\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>\u6267\u884c\u6a21\u5f0f<\/p>\n<p>\u652f\u6301\u5355\u673a\u6267\u884c\u3001\u591a\u53f0\u4e3b\u673a\u6279\u91cf\u6267\u884c&#xff1b;\u5177\u5907\u5e42\u7b49\u7279\u6027&#xff0c;\u91cd\u590d\u6267\u884cPlaybook\u4e0d\u4f1a\u91cd\u590d\u4fee\u6539\u5df2\u7ecf\u7b26\u5408\u9884\u671f\u7684\u73af\u5883&#xff0c;\u4e0d\u7528\u62c5\u5fc3\u91cd\u590d\u6267\u884c\u5e26\u6765\u7834\u574f\u3002<\/p>\n<\/li>\n<p>&#x1f534;\u9002\u7528\u573a\u666f<\/p>\n<ul>\n<li>\u670d\u52a1\u5668\u521d\u59cb\u5316\u3001\u6279\u91cf\u90e8\u7f72Docker\u7b49\u8fd0\u884c\u73af\u5883<\/li>\n<li>\u96c6\u7fa4\u591a\u8282\u70b9\u7edf\u4e00\u914d\u7f6e\u3001\u5206\u53d1\u914d\u7f6e\u6587\u4ef6<\/li>\n<li>\u8f6f\u4ef6\u6279\u91cf\u5b89\u88c5\u5347\u7ea7\u3001\u670d\u52a1\u7edf\u4e00\u542f\u505c\u7ba1\u7406<\/li>\n<li>\u8fd0\u7ef4\u73af\u5883\u6807\u51c6\u5316\u4ea4\u4ed8&#xff0c;\u51cf\u5c11\u4eba\u5de5\u6572\u547d\u4ee4\u5931\u8bef<\/li>\n<\/ul>\n<p>&#x1f4e6;\u6280\u672f\u6808<\/p>\n<p>\u57fa\u4e8ePython\u5f00\u53d1&#xff0c;\u8fdc\u7a0b\u901a\u4fe1\u4f9d\u9760SSH&#xff1b;\u6838\u5fc3\u7ec4\u4ef6&#xff1a;Inventory\u4e3b\u673a\u6e05\u5355\u3001Playbook\u5267\u672c\u3001\u5185\u7f6e\u6a21\u5757&#xff0c;\u63a8\u8350\u76f4\u63a5\u5728\u63a7\u5236\u8282\u70b9\u5b89\u88c5Ansible\u8fdb\u884c\u7ba1\u7406\u3002<\/p>\n<p>\u548cShell\u811a\u672c\u7b80\u5355\u5bf9\u6bd4<\/p>\n<ul>\n<li>Shell\u811a\u672c&#xff1a;\u6267\u884c\u539f\u59cb\u547d\u4ee4&#xff0c;\u903b\u8f91\u9700\u8981\u81ea\u5df1\u624b\u5199&#xff0c;\u7f3a\u5c11\u5e42\u7b49\u6027&#xff0c;\u591a\u673a\u5668\u6279\u91cf\u6267\u884c\u9700\u8981\u989d\u5916\u5904\u7406&#xff0c;\u914d\u7f6e\u4e00\u81f4\u6027\u9700\u8981\u4eba\u4e3a\u4fdd\u969c\u3002<\/li>\n<li>Ansible Playbook&#xff1a;YAML\u53ef\u8bfb\u6027\u5f3a&#xff0c;\u81ea\u5e26\u5927\u91cf\u6a21\u5757&#xff0c;\u5929\u7136\u652f\u6301\u5e42\u7b49&#xff1b;\u539f\u751f\u652f\u6301\u6279\u91cf\u4e3b\u673a&#xff1b;\u9700\u8981\u63a7\u5236\u8282\u70b9\u5b89\u88c5Ansible&#xff0c;\u88ab\u7ba1\u63a7\u7aef\u4ec5\u9700SSH\u3002<\/li>\n<\/ul>\n<h3>2.\u5728\u4f60\u7684\u865a\u62df\u673a\u4e0a\u5b89\u88c5ansiable<\/h3>\n<h4>2.1 \u4ec0\u4e48\u662fAnsible&#xff1f;<\/h4>\n<p>Ansible\u662f\u4e00\u4e2a\u5f00\u6e90\u7684 \u81ea\u52a8\u5316\u8fd0\u7ef4\u5de5\u5177&#xff0c;\u7531Red Hat\u8d5e\u52a9\u5f00\u53d1&#xff0c;\u7528\u4e8e\u5b9e\u73b0&#xff1a;<\/p>\n<ul>\n<li>\u914d\u7f6e\u7ba1\u7406&#xff08;Configuration Management&#xff09;<\/li>\n<li>\u5e94\u7528\u90e8\u7f72&#xff08;Application Deployment&#xff09;<\/li>\n<li>\u4efb\u52a1\u81ea\u52a8\u5316&#xff08;Task Automation&#xff09;<\/li>\n<li>IT\u7f16\u6392&#xff08;Orchestration&#xff09;<\/li>\n<\/ul>\n<p>\u5b83\u6700\u5927\u7684\u7279\u70b9\u662f&#xff1a;\u7b80\u5355\u3001\u65e0\u4ee3\u7406\u3001\u57fa\u4e8eSSH\u3001\u4f7f\u7528YAML\u8bed\u6cd5\u3002<\/p>\n<h4>2.2 Ansible\u7684\u6838\u5fc3\u4f5c\u7528<\/h4>\n<li>\u6279\u91cf\u6267\u884c\u547d\u4ee4<\/li>\n<p>\u65e0\u9700\u9010\u53f0\u767b\u5f55\u670d\u52a1\u5668&#xff0c;\u4e00\u6761\u547d\u4ee4\u53ef\u5728\u6210\u767e\u4e0a\u5343\u53f0\u673a\u5668\u4e0a\u540c\u65f6\u8fd0\u884c&#xff1a;<\/p>\n<li>\u7edf\u4e00\u914d\u7f6e\u7ba1\u7406<\/li>\n<p>\u786e\u4fdd\u6240\u6709\u670d\u52a1\u5668\u7684\u914d\u7f6e\u4e00\u81f4&#xff0c;\u6bd4\u5982&#xff1a;<\/p>\n<ul>\n<li>\u5b89\u88c5\u6307\u5b9a\u7248\u672c\u7684\u8f6f\u4ef6&#xff08;\u5982 Node Exporter\u3001Nginx&#xff09;<\/li>\n<li>\u540c\u6b65\u914d\u7f6e\u6587\u4ef6&#xff08;\u5982 \/etc\/hosts\u3001prometheus.yml&#xff09;<\/li>\n<li>\u521b\u5efa\u7528\u6237\u3001\u8bbe\u7f6e\u6743\u9650\u3001\u7ba1\u7406\u670d\u52a1\u72b6\u6001<\/li>\n<li>\u81ea\u52a8\u5316\u90e8\u7f72\u5e94\u7528<\/li>\n<\/ul>\n<p>\u901a\u8fc7 Playbook&#xff08;YAML \u6587\u4ef6&#xff09;\u5b9a\u4e49\u90e8\u7f72\u6d41\u7a0b&#xff0c;\u4e00\u952e\u5b8c\u6210\u590d\u6742\u5e94\u7528\u4e0a\u7ebf&#xff1a;<\/p>\n<li>\u5e42\u7b49\u6027&#xff08;Idempotency&#xff09;<\/li>\n<p>\u91cd\u590d\u6267\u884c\u540c\u4e00\u4e2a Playbook&#xff0c;\u7ed3\u679c\u59cb\u7ec8\u4e00\u81f4\u2014\u2014\u6ca1\u88c5\u7684\u4f1a\u88c5&#xff0c;\u5df2\u88c5\u7684\u4e0d\u4f1a\u91cd\u590d\u64cd\u4f5c&#xff0c;\u5b89\u5168\u53ef\u9760\u3002<\/p>\n<li>\u65e0\u9700\u5b89\u88c5\u5ba2\u6237\u7aef&#xff08;Agentless&#xff09;<\/li>\n<p>Ansible\u901a\u8fc7SSH \u4e0e\u76ee\u6807\u4e3b\u673a\u901a\u4fe1&#xff0c;\u53ea\u9700\u63a7\u5236\u673a\u5b89\u88c5Ansible&#xff0c;\u88ab\u63a7\u673a\u53ea\u8981\u6709Python \u548cSSH\u5373\u53ef\u3002<\/p>\n<li>\u652f\u6301\u4e91\u548c\u5bb9\u5668\u7f16\u6392<\/li>\n<p>\u53ef\u7ba1\u7406AWS\u3001Azure\u3001\u963f\u91cc\u4e91\u7b49\u4e91\u8d44\u6e90&#xff0c;\u4e5f\u80fd\u64cd\u4f5cDocker\u3001Kubernetes\u3002<\/p>\n<h4>2.3 \u5b89\u88c5ansiale<\/h4>\n<p>\u767b\u5f55\u5230 Ubuntu\u7cfb\u7edf&#xff0c;\u5e76\u5728APT\u547d\u4ee4\u4e0b\u8fd0\u884c\u4ee5\u5e94\u7528\u66f4\u65b0&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> upgrade <span class=\"token parameter variable\">-y<\/span><\/p>\n<p>\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Ansible&#xff1a;<\/p>\n<p><span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> <span class=\"token parameter variable\">-y<\/span> ansible<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235154-6a9f4e1ae9414.png\" alt=\"b22459cbd77b782b0540844e877693c0\" \/><\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u9a8c\u8bc1ansiable\u7248\u672c&#xff1a;<\/p>\n<p>ansible <span class=\"token parameter variable\">&#8211;version<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235155-6a9f4e1b179da.png\" alt=\"5728544c3e02fe61e823691627fe54e0\" \/><\/p>\n<p>\u6211\u4eec\u67e5\u770b\u4e00\u4e0b&#xff0c;\u6709\u6ca1\u6709\u542f\u52a8\u6587\u4ef6&#xff1a;<\/p>\n<p><span class=\"token function\">ls<\/span> \/etc\/ansible<\/p>\n<p>\u6211\u53d1\u73b0\u6211\u8fd9\u91cc\u6ca1\u6709&#xff0c;\u90a3\u6211\u4eec\u624b\u52a8\u914d\u4e00\u4e0b&#xff0c;\u521b\u5efaansiable\u6587\u4ef6&#xff1a;<\/p>\n<p><span class=\"token function\">mkdir<\/span> <span class=\"token parameter variable\">-p<\/span> \/etc\/ansible<\/p>\n<p>\u7f16\u5199hosts\u6587\u4ef6&#xff1a;<\/p>\n<p><span class=\"token function\">cat<\/span> <span class=\"token operator\">&gt;<\/span> \/etc\/ansible\/hosts <span class=\"token operator\">&lt;&lt;<\/span><span class=\"token string\">EOF<br \/>\n[local]<br \/>\nlocalhost ansible_connection&#061;local<br \/>\nEOF<\/span><\/p>\n<p>\u7f16\u5199ansiable.cfg\u6587\u4ef6&#xff1a;<\/p>\n<p><span class=\"token function\">cat<\/span> <span class=\"token operator\">&gt;<\/span> \/etc\/ansible\/ansible.cfg <span class=\"token operator\">&lt;&lt;<\/span><span class=\"token string\">EOF<br \/>\n[defaults]<br \/>\ninventory &#061; \/etc\/ansible\/hosts<br \/>\nhost_key_checking &#061; False<br \/>\nremote_user &#061; root<br \/>\nstdout_callback &#061; yaml<br \/>\nEOF<\/span><\/p>\n<p>\u9a8c\u8bc1\u662f\u5426\u6210\u529f&#xff1a;<\/p>\n<p>ansible localhost <span class=\"token parameter variable\">-m<\/span> <span class=\"token function\">ping<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235155-6a9f4e1b2cbd5.png\" alt=\"f1dff617f524f088860e1b8183ad3a93\" \/><\/p>\n<h3>3.\u914d\u7f6eansiable\u6587\u4ef6\u641e\u5b9a\u5176\u4ed6\u4e3b\u673adocker\u90e8\u7f72<\/h3>\n<h4>3.1 \u7f16\u5199hosts\u6587\u4ef6<\/h4>\n<p>\u786e\u4fdd\u4f60\u5728playbook\u6240\u5728\u76ee\u5f55&#xff08;\u5047\u8bbe\u662f \/etc\/ansible&#xff09;&#xff1a;<\/p>\n<p><span class=\"token builtin class-name\">cd<\/span> \/etc\/ansible<\/p>\n<p>\u63d0\u524d\u586b\u5199\u9700\u8981\u90e8\u7f72 Docker \u7684\u670d\u52a1\u5668 IP&#xff0c;\u652f\u6301\u591a\u53f0\u673a\u5668\u6279\u91cf\u90e8\u7f72&#xff08;\u5728hosts\u6587\u4ef6\u4e2d&#xff09;&#xff1a;<\/p>\n<ul>\n<li>[dbservers]<\/li>\n<li>\u65b9\u62ec\u53f7 [] \u5b9a\u4e49\u4e3b\u673a\u7ec4\u540d\u79f0&#xff0c;\u7ec4\u540d\u53eb dbservers&#xff0c;\u5b57\u9762\u542b\u4e49&#xff1a;\u6570\u636e\u5e93\u670d\u52a1\u5668\u7ec4\u3002<\/li>\n<\/ul>\n<p><span class=\"token punctuation\">[<\/span>dbservers<span class=\"token punctuation\">]<\/span><br \/>\n<span class=\"token number\">192.168<\/span>.42.146 <span class=\"token assign-left variable\">ansible_user<\/span><span class=\"token operator\">&#061;<\/span>root <span class=\"token assign-left variable\">ansible_port<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">22<\/span> <span class=\"token assign-left variable\">ansible_password<\/span><span class=\"token operator\">&#061;<\/span>*****<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235155-6a9f4e1b406dd.png\" alt=\"image-20260806152842140\" \/><\/p>\n<h4>3.2 \u7f16\u5199\u5b89\u88c5docker\u8fd0\u884c\u811a\u672c<\/h4>\n<p>\u7f16\u5199\u8fd0\u884c\u811a\u672cdeploy_docker.yml&#xff1a;<\/p>\n<ul>\n<li>playbook \u91cc\u5199 hosts: dbservers&#xff0c;\u4ee3\u8868&#xff1a;\u5bf9\u8fd9\u4e2a\u5206\u7ec4\u4e0b\u9762\u6240\u6709IP\u6267\u884c\u5267\u672c\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<p>&#8212;<br \/>\n&#8211; name: Ansible\u4e00\u952e\u90e8\u7f72Docker\u73af\u5883<br \/>\n  hosts: docker_group<br \/>\n  become: true<br \/>\n  tasks:<br \/>\n    &#8211; name: \u5b89\u88c5yum\u5de5\u5177\u4f9d\u8d56<br \/>\n      yum:<br \/>\n        name: yum-utils<br \/>\n        state: present<\/p>\n<p>    &#8211; name: \u6dfb\u52a0Docker yum\u8f6f\u4ef6\u6e90<br \/>\n      yum_repository:<br \/>\n        name: docker-ce<br \/>\n        description: Docker CE stable repo<br \/>\n        baseurl: https:\/\/download.docker.com\/linux\/centos\/$releasever\/$basearch\/stable<br \/>\n        gpgcheck: yes<br \/>\n        gpgkey: https:\/\/download.docker.com\/linux\/centos\/gpg<\/p>\n<p>    &#8211; name: \u5b89\u88c5Docker\u5168\u5957\u7ec4\u4ef6<br \/>\n      yum:<br \/>\n        name:<br \/>\n          &#8211; docker-ce<br \/>\n          &#8211; docker-ce-cli<br \/>\n          &#8211; containerd.io<br \/>\n        state: present<\/p>\n<p>    &#8211; name: \u542f\u52a8docker\u670d\u52a1\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f<br \/>\n      systemd:<br \/>\n        name: docker<br \/>\n        state: started<br \/>\n        enabled: yes<\/p>\n<p>    &#8211; name: \u5c06\u767b\u5f55\u7528\u6237\u52a0\u5165docker\u7ec4&#xff0c;\u514dsudo\u64cd\u4f5cdocker<br \/>\n      user:<br \/>\n        name: &#034;{{ ansible_user }}&#034;<br \/>\n        groups: docker<br \/>\n        append: true<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235155-6a9f4e1b8bb4f.png\" alt=\"image-20260806153100270\" \/><\/p>\n<h4>3.3 \u6267\u884cPlaybook\u547d\u4ee4<\/h4>\n<p>ansible-playbook -i hosts deploy_docker.yml<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235155-6a9f4e1bc9f15.png\" alt=\"image-20260806153044481\" \/><\/p>\n<h4>3.4 \u9a8c\u8bc1\u662f\u5426\u6210\u529f<\/h4>\n<p>\u5728\u88ab\u63a7\u673a\u5668\u6267\u884c&#xff1a;<\/p>\n<p><span class=\"token function\">docker<\/span> <span class=\"token parameter variable\">-v<\/span><br \/>\nsystemctl status <span class=\"token function\">docker<\/span><\/p>\n<p>\u770b\u5230\u7248\u672c\u53f7\u3001\u670d\u52a1\u72b6\u6001\u4e3aactive(running)\u5373\u4e3a\u90e8\u7f72\u5b8c\u6210\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235156-6a9f4e1c4d85c.png\" alt=\"image-20260806153509519\" \/><\/p>\n<p>\u5230\u8fd9\u91cc&#xff0c;Ansible \u5df2\u7ecf\u53ef\u4ee5\u6839\u636e hosts \u6e05\u5355\u6267\u884c Docker \u90e8\u7f72\u4efb\u52a1\u3002\u5148\u786e\u8ba4\u8fd9\u4e00\u5c42\u80fd\u591f\u6b63\u5e38\u5b8c\u6210&#xff0c;\u518d\u7ee7\u7eed\u5904\u7406\u8de8\u7f51\u7edc\u8fde\u63a5&#xff0c;\u4f1a\u66f4\u5bb9\u6613\u5224\u65ad\u540e\u7eed\u95ee\u9898\u5230\u5e95\u6765\u81ea Playbook\u3001\u672c\u5730 SSH&#xff0c;\u8fd8\u662f\u516c\u7f51\u8bbf\u95ee\u94fe\u8def\u3002<\/p>\n<h3>4.\u5b89\u88c5cpolar\u5b9e\u73b0\u968f\u65f6\u968f\u5730\u5f00\u53d1<\/h3>\n<p>\u524d\u9762\u7684 Ansible \u6d41\u7a0b\u9ed8\u8ba4\u5efa\u7acb\u5728\u63a7\u5236\u7aef\u80fd\u591f\u901a\u8fc7 SSH \u8fde\u63a5\u76ee\u6807\u4e3b\u673a\u7684\u57fa\u7840\u4e0a\u3002\u5982\u679c\u76ee\u6807\u4e3b\u673a\u4f4d\u4e8e\u6ca1\u6709\u516c\u7f51 IP \u7684\u5185\u7f51\u73af\u5883&#xff0c;\u5c40\u57df\u7f51\u4e4b\u5916\u5c31\u65e0\u6cd5\u76f4\u63a5\u7ee7\u7eed\u4f7f\u7528\u539f\u6765\u7684\u5185\u7f51\u5730\u5740\u3002<\/p>\n<p>\u8fd9\u91cc\u589e\u52a0 cpolar \u7684\u76ee\u7684&#xff0c;\u662f\u7ed9\u76ee\u6807\u4e3b\u673a\u7684 SSH \u670d\u52a1\u8865\u5145\u4e00\u4e2a\u516c\u7f51 TCP \u5165\u53e3\u3002Ansible \u672c\u8eab\u7684 Playbook \u548c\u4e3b\u673a\u6e05\u5355\u673a\u5236\u4e0d\u53d8&#xff0c;\u540e\u9762\u53ea\u9700\u8981\u628a hosts \u4e2d\u7684\u76ee\u6807\u5730\u5740\u548c\u7aef\u53e3\u6539\u6210 cpolar \u751f\u6210\u7684\u516c\u7f51 TCP \u5730\u5740\u3002<\/p>\n<p>\u4ee5\u4e0b\u7ee7\u7eed\u6309\u7167\u539f\u6709\u5b89\u88c5\u6b65\u9aa4\u914d\u7f6e cpolar&#xff1a;<\/p>\n<p>\u4f7f\u7528\u4e00\u952e\u811a\u672c\u5b89\u88c5\u547d\u4ee4&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">curl<\/span> https:\/\/get.cpolar.sh <span class=\"token operator\">|<\/span> <span class=\"token function\">sh<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235156-6a9f4e1c91fc0.png\" alt=\"image-20250725104019896\" \/><\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u6267\u884c\u4e0b\u65b9\u547d\u4ee4\u67e5\u770bcpolar\u670d\u52a1\u72b6\u6001&#xff1a;&#xff08;\u5982\u56fe\u6240\u793a\u5373\u4e3a\u6b63\u5e38\u542f\u52a8&#xff09;<\/p>\n<p><span class=\"token function\">sudo<\/span> systemctl status cpolar<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235156-6a9f4e1ca16fa.png\" alt=\"22e5adfaf290a17fc3384bb296055259\" \/><\/p>\n<p>cpolar\u5b89\u88c5\u548c\u6210\u529f\u542f\u52a8\u670d\u52a1\u540e&#xff0c;\u5728\u6d4f\u89c8\u5668\u4e0a\u8f93\u5165\u865a\u62df\u673a\u4e3b\u673aIP\u52a09200\u7aef\u53e3\u5373:\u3010http:\/\/ip:9200\u3011\u8bbf\u95eecpolar\u7ba1\u7406\u754c\u9762&#xff0c;\u4f7f\u7528cpolar\u5b98\u7f51\u6ce8\u518c\u7684\u8d26\u53f7\u767b\u5f55,\u767b\u5f55\u540e\u5373\u53ef\u770b\u5230cpolar web \u914d\u7f6e\u754c\u9762,\u63a5\u4e0b\u6765\u5728web \u754c\u9762\u914d\u7f6e\u5373\u53ef&#xff1a;<\/p>\n<p>\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee\u672c\u57309200\u7aef\u53e3&#xff0c;\u4f7f\u7528cpolar\u8d26\u6237\u5bc6\u7801\u767b\u5f55\u5373\u53ef,\u767b\u5f55\u540e\u5373\u53ef\u5bf9\u96a7\u9053\u8fdb\u884c\u7ba1\u7406\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235156-6a9f4e1cb9391.png\" alt=\"8a6698b1bf26d64ba3645827fbfb1c29\" \/><\/p>\n<h3>5.\u914d\u7f6e\u516c\u7f51\u5730\u5740<\/h3>\n<p>cpolar \u5b89\u88c5\u5e76\u542f\u52a8\u540e&#xff0c;\u63a5\u4e0b\u6765\u53ea\u5904\u7406 SSH \u8fd9\u4e00\u6761\u94fe\u8def&#xff1a;\u672c\u5730 22 \u7aef\u53e3\u4fdd\u6301\u4e0d\u53d8&#xff0c;\u901a\u8fc7 TCP \u96a7\u9053\u751f\u6210\u516c\u7f51\u5730\u5740&#xff0c;\u518d\u628a\u8fd9\u4e2a\u5730\u5740\u5199\u5165 Ansible \u7684 hosts \u6587\u4ef6\u3002\u8fd9\u6837\u53ef\u4ee5\u76f4\u63a5\u9a8c\u8bc1 Playbook \u662f\u5426\u80fd\u591f\u8de8\u7f51\u7edc\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<ul>\n<li>\u96a7\u9053\u540d\u79f0&#xff1a;\u53ef\u81ea\u5b9a\u4e49&#xff0c;\u672c\u4f8b\u4f7f\u7528\u4e86:ssh&#xff0c;\u6ce8\u610f\u4e0d\u8981\u4e0e\u5df2\u6709\u7684\u96a7\u9053\u540d\u79f0\u91cd\u590d<\/li>\n<li>\u534f\u8bae&#xff1a;tcp<\/li>\n<li>\u672c\u5730\u5730\u5740&#xff1a;22<\/li>\n<li>\u7aef\u53e3\u7c7b\u578b&#xff1a;\u968f\u673a\u4e34\u65f6TCP\u7aef\u53e3<\/li>\n<li>\u5730\u533a&#xff1a;China Top<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235157-6a9f4e1d0a110.png\" alt=\"image-20260806155646531\" \/><\/p>\n<p>\u521b\u5efa\u6210\u529f\u540e&#xff0c;\u6253\u5f00\u5de6\u4fa7\u5728\u7ebf\u96a7\u9053\u5217\u8868,\u53ef\u4ee5\u770b\u5230\u521a\u521a\u901a\u8fc7\u521b\u5efa\u96a7\u9053\u751f\u6210\u4e86\u516c\u7f51\u5730\u5740&#xff0c;\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u5728\u5176\u4ed6\u7535\u8111\u6216\u8005\u79fb\u52a8\u7aef\u8bbe\u5907&#xff08;\u5f02\u5730&#xff09;\u4e0a&#xff0c;\u4f7f\u7528\u4efb\u610f\u4e00\u4e2a\u5730\u5740\u5728\u7ec8\u7aef\u4e2d\u8bbf\u95ee\u5373\u53ef\u3002<\/p>\n<ul>\n<li>\n<p>tcp \u8868\u793a\u4f7f\u7528\u7684\u534f\u8bae\u7c7b\u578b<\/p>\n<\/li>\n<li>\n<p>2.tcp.cpolar.top\u662f Cpolar \u63d0\u4f9b\u7684\u57df\u540d<\/p>\n<\/li>\n<li>\n<p>15197\u662f\u968f\u673a\u5206\u914d\u7684\u516c\u7f51\u7aef\u53e3\u53f7<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235157-6a9f4e1d46d05.png\" alt=\"image-20260806155804171\" \/><\/p>\n<p>\u62ff\u5230\u516c\u7f51 TCP \u5730\u5740\u548c\u7aef\u53e3\u540e&#xff0c;\u53ef\u4ee5\u628a\u5b83\u4f5c\u4e3a Ansible \u7684\u76ee\u6807\u4e3b\u673a\u5730\u5740\u8fdb\u884c\u8fde\u63a5\u6d4b\u8bd5\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u4fee\u6539 hosts \u914d\u7f6e\u5e76\u5b9e\u9645\u6267\u884c\u4e00\u6b21 Playbook\u3002<\/p>\n<p>\u4fee\u6539hosts\u914d\u7f6e\u6587\u4ef6&#xff1a;<\/p>\n<p><span class=\"token punctuation\">[<\/span>dbservers<span class=\"token punctuation\">]<\/span><br \/>\n<span class=\"token number\">2<\/span>.tcp.cpolar.top <span class=\"token assign-left variable\">ansible_user<\/span><span class=\"token operator\">&#061;<\/span>root <span class=\"token assign-left variable\">ansible_port<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">15197<\/span> <span class=\"token assign-left variable\">ansible_password<\/span><span class=\"token operator\">&#061;<\/span>***<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235157-6a9f4e1d9c9e7.png\" alt=\"image-20260806160126792\" \/><\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6267\u884c\u914d\u7f6e\u6587\u4ef6&#xff1a;<\/p>\n<p>ansible-playbook <span class=\"token parameter variable\">-i<\/span> hosts deploy_docker.yml<\/p>\n<p>Playbook \u6267\u884c\u7ed3\u675f\u540e&#xff0c;\u518d\u5230\u76ee\u6807\u4e3b\u673a\u68c0\u67e5 Docker \u662f\u5426\u5df2\u7ecf\u6309\u9884\u671f\u5b89\u88c5&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235157-6a9f4e1da845c.png\" alt=\"image-20260806160319337\" \/><\/p>\n<p>\u5982\u679c\u76ee\u6807\u4e3b\u673a\u80fd\u591f\u770b\u5230\u5bf9\u5e94\u7684 Docker \u5b89\u88c5\u7ed3\u679c&#xff0c;\u8bf4\u660e\u8fd9\u6761\u516c\u7f51 SSH \u94fe\u8def\u5df2\u7ecf\u80fd\u591f\u88ab Ansible \u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n<h3>6.\u4fdd\u7559\u56fa\u5b9aTCP\u516c\u7f51\u5730\u5740<\/h3>\n<p>\u968f\u673a TCP \u5730\u5740\u9002\u5408\u5148\u505a\u8fde\u901a\u6027\u9a8c\u8bc1\u3002\u5982\u679c\u540e\u7eed\u8981\u957f\u671f\u628a\u8be5\u5730\u5740\u5199\u5165 Ansible \u4e3b\u673a\u6e05\u5355&#xff0c;\u53ef\u4ee5\u7ee7\u7eed\u6309\u7167\u4e0b\u9762\u7684\u539f\u6709\u6b65\u9aa4\u914d\u7f6e\u56fa\u5b9a TCP \u5730\u5740\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235157-6a9f4e1dea984.png\" alt=\"image-20251210160529622\" \/><\/p>\n<p>\u9009\u62e9\u533a\u57df\u548c\u63cf\u8ff0&#xff1a;\u6709\u4e00\u4e2a\u4e0b\u62c9\u83dc\u5355&#xff0c;\u5f53\u524d\u9009\u62e9\u7684\u662f\u201cChina VIP\u201d\u3002 \u53f3\u4fa7\u8f93\u5165\u6846&#xff0c;\u7528\u4e8e\u586b\u5199\u63cf\u8ff0\u4fe1\u606f\u3002 \u4fdd\u7559\u6309\u94ae&#xff1a;\u5728\u53f3\u4fa7\u6709\u4e00\u4e2a\u6a59\u8272\u7684\u201c\u4fdd\u7559\u201d\u6309\u94ae&#xff0c;\u70b9\u51fb\u8be5\u6309\u94ae\u53ef\u4ee5\u4fdd\u7559\u6240\u9009\u7684TCP\u5730\u5740\u3002 \u5217\u8868\u4e2d\u663e\u793a\u4e86\u4e00\u6761\u5df2\u4fdd\u7559\u7684TCP\u5730\u5740\u8bb0\u5f55\u3002<\/p>\n<ul>\n<li>\n<p>\u5730\u533a&#xff1a;\u663e\u793a\u4e3a\u201cChina VIP\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5730\u5740&#xff1a;\u663e\u793a\u4e3a\u201c15.tcp.cpolar.top:13633\u201d\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235158-6a9f4e1e38982.png\" alt=\"image-20251210160555284\" \/><\/p>\n<\/li>\n<\/ul>\n<p>\u767b\u5f55cpolar web UI\u7ba1\u7406\u754c\u9762&#xff0c;\u70b9\u51fb\u5de6\u4fa7\u4eea\u8868\u76d8\u7684\u96a7\u9053\u7ba1\u7406\u2014\u2014\u96a7\u9053\u5217\u8868&#xff0c;\u627e\u5230\u6240\u8981\u914d\u7f6e\u7684\u96a7\u9053ssh&#xff0c;\u70b9\u51fb\u53f3\u4fa7\u7684\u7f16\u8f91\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235158-6a9f4e1e58c57.png\" alt=\"image-20251210160639397\" \/><\/p>\n<p>\u4fee\u6539\u96a7\u9053\u4fe1\u606f&#xff0c;\u5c06\u4fdd\u7559\u6210\u529f\u7684TCP\u7aef\u53e3\u914d\u7f6e\u5230\u96a7\u9053\u4e2d\u3002<\/p>\n<ul>\n<li>\u7aef\u53e3\u7c7b\u578b&#xff1a;\u9009\u62e9\u56fa\u5b9aTCP\u7aef\u53e3<\/li>\n<li>\u9884\u7559\u7684TCP\u5730\u5740&#xff1a;\u586b\u5199\u4fdd\u7559\u6210\u529f\u7684TCP\u5730\u5740<\/li>\n<\/ul>\n<p>\u70b9\u51fb\u66f4\u65b0\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235158-6a9f4e1ec0428.png\" alt=\"image-20251210160618660\" \/><\/p>\n<p>\u521b\u5efa\u5b8c\u6210\u540e&#xff0c;\u6253\u5f00\u5728\u7ebf\u96a7\u9053\u5217\u8868&#xff0c;\u6b64\u65f6\u53ef\u4ee5\u770b\u5230\u968f\u673a\u7684\u516c\u7f51\u5730\u5740\u5df2\u7ecf\u53d1\u751f\u53d8\u5316&#xff0c;\u5730\u5740\u540d\u79f0\u4e5f\u53d8\u6210\u4e86\u4fdd\u7559\u548c\u56fa\u5b9a\u7684TCP\u5730\u5740\u3002<\/p>\n<p><img decoding=\"async\" src=\"2026-09-08lkcfzimox2y.png\" alt=\"image-20251210160652740\" \/><\/p>\n<p>\u66f4\u65b0\u5b8c\u6210\u540e&#xff0c;\u540e\u7eed\u4e3b\u673a\u6e05\u5355\u53ef\u4ee5\u7ee7\u7eed\u4f7f\u7528\u8fd9\u4e2a\u56fa\u5b9a TCP \u5730\u5740&#xff0c;\u907f\u514d\u968f\u673a\u5730\u5740\u53d8\u5316\u540e\u518d\u6b21\u4fee\u6539\u8fde\u63a5\u4fe1\u606f\u3002<\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u8fd9\u7bc7\u6559\u7a0b\u53ef\u4ee5\u62c6\u6210\u4e24\u5c42\u6765\u770b\u3002<\/p>\n<p>\u7b2c\u4e00\u5c42\u662f Ansible \u672c\u8eab&#xff1a;\u63a7\u5236\u7aef\u5b89\u88c5 Ansible&#xff0c;\u914d\u7f6e hosts \u4e3b\u673a\u6e05\u5355&#xff0c;\u518d\u901a\u8fc7 deploy_docker.yml \u628a Docker \u5b89\u88c5\u3001\u670d\u52a1\u542f\u52a8\u548c\u6743\u9650\u8bbe\u7f6e\u6574\u7406\u6210\u53ef\u91cd\u590d\u6267\u884c\u7684 Playbook\u3002\u8fd9\u6837\u540e\u7eed\u589e\u52a0\u76ee\u6807\u4e3b\u673a\u65f6&#xff0c;\u91cd\u70b9\u5c31\u4ece\u201c\u91cd\u65b0\u6572\u4e00\u904d\u547d\u4ee4\u201d\u53d8\u6210\u4e86\u201c\u628a\u4e3b\u673a\u52a0\u5165\u6e05\u5355\u5e76\u6267\u884c\u540c\u4e00\u5957\u5267\u672c\u201d\u3002<\/p>\n<p>\u7b2c\u4e8c\u5c42\u662f\u7f51\u7edc\u8fde\u63a5\u3002\u5982\u679c\u76ee\u6807\u4e3b\u673a\u53ea\u80fd\u901a\u8fc7\u5185\u7f51 SSH \u8bbf\u95ee&#xff0c;\u90a3\u4e48 Ansible \u4e5f\u53ea\u80fd\u5728\u7f51\u7edc\u53ef\u8fbe\u7684\u8303\u56f4\u5185\u5de5\u4f5c\u3002\u901a\u8fc7 cpolar \u628a\u672c\u5730 22 \u7aef\u53e3\u6620\u5c04\u6210\u516c\u7f51 TCP \u5730\u5740\u540e&#xff0c;\u53ea\u9700\u8981\u4fee\u6539 hosts \u4e2d\u7684\u76ee\u6807\u5730\u5740\u548c\u7aef\u53e3&#xff0c;\u5c31\u53ef\u4ee5\u7ee7\u7eed\u6cbf\u7528\u539f\u6765\u7684 Playbook&#xff1b;\u9700\u8981\u957f\u671f\u4f7f\u7528\u65f6&#xff0c;\u518d\u628a\u968f\u673a TCP \u5730\u5740\u8c03\u6574\u4e3a\u56fa\u5b9a TCP \u5730\u5740\u3002<\/p>\n<p>\u6574\u4e2a\u6d41\u7a0b\u91cc&#xff0c;Ansible \u8d1f\u8d23\u7684\u662f\u90e8\u7f72\u6b65\u9aa4\u6807\u51c6\u5316&#xff0c;cpolar \u5904\u7406\u7684\u662f\u76ee\u6807\u4e3b\u673a\u7684\u7f51\u7edc\u53ef\u8fbe\u6027\u3002\u628a\u8fd9\u4e24\u5c42\u5206\u5f00\u7406\u89e3&#xff0c;\u6bd4\u628a\u6240\u6709\u529f\u80fd\u90fd\u5f52\u5230\u201c\u4e00\u952e\u81ea\u52a8\u5316\u201d\u66f4\u5bb9\u6613\u6392\u67e5\u95ee\u9898&#xff0c;\u4e5f\u66f4\u9002\u5408\u540e\u7eed\u7ee7\u7eed\u6269\u5c55\u5230\u5176\u4ed6\u670d\u52a1\u5668\u548c\u5176\u4ed6 Playbook\u3002<\/p>\n<p>\u5982\u679c\u540e\u9762\u9700\u8981\u7ee7\u7eed\u6269\u5927\u4f7f\u7528\u8303\u56f4&#xff0c;\u4f18\u5148\u7ef4\u62a4\u597d\u4e3b\u673a\u6e05\u5355\u3001Playbook \u7248\u672c\u548c SSH \u8bbf\u95ee\u6743\u9650&#xff0c;\u6bd4\u4e0d\u65ad\u589e\u52a0\u4e34\u65f6\u547d\u4ee4\u66f4\u91cd\u8981\u3002\u81ea\u52a8\u5316\u771f\u6b63\u6709\u4ef7\u503c\u7684\u5730\u65b9&#xff0c;\u662f\u8ba9\u540c\u4e00\u5957\u90e8\u7f72\u89c4\u5219\u53ef\u4ee5\u88ab\u91cd\u590d\u6267\u884c\u548c\u68c0\u67e5\u3002<\/p>\n<hr \/>\n<p>\u8f6c\u8f7d\u81ea&#xff1a;https:\/\/blog.csdn.net\/u014727709\/article\/details\/164456185 \u6b22\u8fce &#x1f44d;\u70b9\u8d5e\u270d\u8bc4\u8bba\u2b50\u6536\u85cf&#xff0c;\u6b22\u8fce\u6307\u6b63<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u76ee\u5f55\u6bcf\u65e5\u4e00\u53e5\u6b63\u80fd\u91cf\u524d\u8a001.\u4e3a\u4ec0\u4e48\u4f7f\u7528ansible?2.\u5728\u4f60\u7684\u865a\u62df\u673a\u4e0a\u5b89\u88c5ansiable2.1 \u4ec0\u4e48\u662fAnsible&#xff1f;2.2 Ansible\u7684\u6838\u5fc3\u4f5c\u75282.3 \u5b89\u88c5ansiale3.\u914d\u7f6eansiable\u6587\u4ef6\u641e\u5b9a\u5176\u4ed6\u4e3b\u673adocker\u90e8\u7f723.1 \u7f16\u5199hosts\u6587\u4ef63.2 \u7f16\u5199\u5b89\u88c5docker\u8fd0\u884c\u811a\u672c3.3 \u6267\u884cPlaybook\u547d\u4ee43.4 \u9a8c\u8bc1\u662f\u5426\u6210\u529f4.\u5b89\u88c5cpolar\u5b9e\u73b0\u968f\u65f6\u968f\u5730\u5f00\u53d15.\u914d\u7f6e\u516c\u7f51\u5730\u57406.\u4fdd\u7559\u56fa\u5b9aTCP\u516c\u7f51\u5730\u5740\u603b\u7ed3\u6bcf\u65e5\u4e00\u53e5\u6b63\u80fd\u91cf \u843d\u65e5\u662f\u5929\u7a7a\u5f52\u6863\u7684<\/p>\n","protected":false},"author":2,"featured_media":102082,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1064,321,3151,1263,118],"topic":[],"class_list":["post-102102","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ansible","tag-cpolar","tag-docker-","tag-playbook","tag-118"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/102102.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u76ee\u5f55\u6bcf\u65e5\u4e00\u53e5\u6b63\u80fd\u91cf\u524d\u8a001.\u4e3a\u4ec0\u4e48\u4f7f\u7528ansible?2.\u5728\u4f60\u7684\u865a\u62df\u673a\u4e0a\u5b89\u88c5ansiable2.1 \u4ec0\u4e48\u662fAnsible&#xff1f;2.2 Ansible\u7684\u6838\u5fc3\u4f5c\u75282.3 \u5b89\u88c5ansiale3.\u914d\u7f6eansiable\u6587\u4ef6\u641e\u5b9a\u5176\u4ed6\u4e3b\u673adocker\u90e8\u7f723.1 \u7f16\u5199hosts\u6587\u4ef63.2 \u7f16\u5199\u5b89\u88c5docker\u8fd0\u884c\u811a\u672c3.3 \u6267\u884cPlaybook\u547d\u4ee43.4 \u9a8c\u8bc1\u662f\u5426\u6210\u529f4.\u5b89\u88c5cpolar\u5b9e\u73b0\u968f\u65f6\u968f\u5730\u5f00\u53d15.\u914d\u7f6e\u516c\u7f51\u5730\u57406.\u4fdd\u7559\u56fa\u5b9aTCP\u516c\u7f51\u5730\u5740\u603b\u7ed3\u6bcf\u65e5\u4e00\u53e5\u6b63\u80fd\u91cf \u843d\u65e5\u662f\u5929\u7a7a\u5f52\u6863\u7684\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/102102.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-07T23:52:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235154-6a9f4e1a2858d.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/102102.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/102102.html\",\"name\":\"\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-07T23:52:00+00:00\",\"dateModified\":\"2026-09-07T23:52:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/102102.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/102102.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/102102.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/102102.html","og_locale":"zh_CN","og_type":"article","og_title":"\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u76ee\u5f55\u6bcf\u65e5\u4e00\u53e5\u6b63\u80fd\u91cf\u524d\u8a001.\u4e3a\u4ec0\u4e48\u4f7f\u7528ansible?2.\u5728\u4f60\u7684\u865a\u62df\u673a\u4e0a\u5b89\u88c5ansiable2.1 \u4ec0\u4e48\u662fAnsible&#xff1f;2.2 Ansible\u7684\u6838\u5fc3\u4f5c\u75282.3 \u5b89\u88c5ansiale3.\u914d\u7f6eansiable\u6587\u4ef6\u641e\u5b9a\u5176\u4ed6\u4e3b\u673adocker\u90e8\u7f723.1 \u7f16\u5199hosts\u6587\u4ef63.2 \u7f16\u5199\u5b89\u88c5docker\u8fd0\u884c\u811a\u672c3.3 \u6267\u884cPlaybook\u547d\u4ee43.4 \u9a8c\u8bc1\u662f\u5426\u6210\u529f4.\u5b89\u88c5cpolar\u5b9e\u73b0\u968f\u65f6\u968f\u5730\u5f00\u53d15.\u914d\u7f6e\u516c\u7f51\u5730\u57406.\u4fdd\u7559\u56fa\u5b9aTCP\u516c\u7f51\u5730\u5740\u603b\u7ed3\u6bcf\u65e5\u4e00\u53e5\u6b63\u80fd\u91cf \u843d\u65e5\u662f\u5929\u7a7a\u5f52\u6863\u7684","og_url":"https:\/\/www.wsisp.com\/helps\/102102.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-07T23:52:00+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260907235154-6a9f4e1a2858d.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/102102.html","url":"https:\/\/www.wsisp.com\/helps\/102102.html","name":"\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-07T23:52:00+00:00","dateModified":"2026-09-07T23:52:00+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/102102.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/102102.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/102102.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u591a\u53f0 Linux \u670d\u52a1\u5668\u600e\u4e48\u7edf\u4e00\u88c5 Docker\uff1f\u7528 Ansible Playbook \u56fa\u5316\u90e8\u7f72\u6d41\u7a0b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/102102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=102102"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/102102\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/102082"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=102102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=102102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=102102"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=102102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}