{"id":3523,"date":"2021-03-27T21:25:17","date_gmt":"2021-03-27T13:25:17","guid":{"rendered":"http:\/\/blog.ywdevops.cn\/?p=3523"},"modified":"2021-03-27T21:25:33","modified_gmt":"2021-03-27T13:25:33","slug":"namespace","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2021\/03\/27\/namespace\/","title":{"rendered":"linux\u7cfb\u7edf\u4e4bnamespace"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>1\u3001\u4ec0\u4e48\u662fNamespace\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Linux Namespace\uff08\u547d\u540d\u7a7a\u95f4\uff09\u662f\u4e00\u79cd\u64cd\u4f5c\u7cfb\u7edf\u5c42\u7ea7\u7684\u8d44\u6e90\u9694\u79bb\u6280\u672f\uff0c\u80fd\u591f\u5c06 Linux \u7684\u5168\u5c40\u8d44\u6e90\uff0c\u5212\u5206\u4e3a namespace \u8303\u56f4\u5185\u7684\u8d44\u6e90\uff0c\u800c\u4e14\u4e0d\u540c namespace \u95f4\u7684\u8d44\u6e90\u5f7c\u6b64\u900f\u660e\uff0c\u4e0d\u540c namespace \u91cc\u7684\u8fdb\u7a0b\u65e0\u6cd5\u611f\u77e5\u5230\u5176\u5b83 namespace \u91cc\u9762\u7684\u8fdb\u7a0b\u548c\u8d44\u6e90\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Linux namespace \u5b9e\u73b0\u4e86 6 \u9879\u8d44\u6e90\u9694\u79bb\uff0c\u57fa\u672c\u4e0a\u6db5\u76d6\u4e86\u4e00\u4e2a\u5c0f\u578b\u64cd\u4f5c\u7cfb\u7edf\u7684\u8fd0\u884c\u8981\u7d20\uff0c\u5305\u62ec\u4e3b\u673a\u540d\u3001\u7528\u6237\u6743\u9650\u3001\u6587\u4ef6\u7cfb\u7edf\u3001\u7f51\u7edc\u3001\u8fdb\u7a0b\u53f7\u3001\u8fdb\u7a0b\u95f4\u901a\u4fe1\u3002Linux Namespace \u662f\u64cd\u4f5c\u7cfb\u7edf\u865a\u62df\u5316\u6280\u672f\uff08\u4f8b\u5982\uff1a \u5bb9\u5668\uff09\u7684\u5e95\u5c42\u5b9e\u73b0\u652f\u6491\u3002 <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"241\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/14-1.png\" alt=\"\" class=\"wp-image-3524\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/14-1.png 596w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/14-1-300x121.png 300w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9 6 \u9879\u8d44\u6e90\u9694\u79bb\u5206\u522b\u5bf9\u5e94 6 \u79cd\u7cfb\u7edf\u8c03\u7528\uff0c\u5c06\u8fd9\u4e9b\u7cfb\u7edf\u8c03\u7528\u4f20\u8f93\u4f20\u5165 clone \u51fd\u6570\u5c31\u53ef\u4ee5\u5efa\u7acb\u4e00\u4e2a\u5bb9\u5668\u4e86\u3002\u4e00\u4e2a\u5bb9\u5668\u8fdb\u7a0b\u8fd8\u53ef\u4ee5\u518d clone \u51fa\u4e00\u4e2a\u5bb9\u5668\u8fdb\u7a0b\uff0c\u5b8c\u6210\u5bb9\u5668\u7684\u5d4c\u5957\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u6587\u4ef6 \u6587\u4ef6 \/proc\/[pid]\/ns \u53ef\u4ee5\u67e5\u770b\u6307\u5b9a\u8fdb\u7a0b\u8fd0\u884c\u5728\u54ea\u4e9b namespace \u4e2d\uff1a <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"590\" height=\"219\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/15-1.png\" alt=\"\" class=\"wp-image-3525\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/15-1.png 590w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/03\/15-1-300x111.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u770b\u5230\uff0c\u6bcf\u9879 namespace \u90fd\u5177\u6709\u4e00\u4e2a\u552f\u4e00\u6807\u8bc6\uff0c\u5982\u679c\u4e24\u4e2a\u8fdb\u7a0b\u6307\u5411\u7684\u540c\u4e00\u4e2a namespace\uff0c\u5219\u8868\u793a\u5b83\u4eec\u540c\u5728\u8be5 namespace \u4e0b\u3002 <\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>2\u3001Linux Namespace \u7684\u7c7b\u578b<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> <strong>UTS namespace<\/strong>\u00a0\u63d0\u4f9b\u4e86 hostname \u548c domain \u7684\u9694\u79bb\uff0c\u8fd9\u6837\u6bcf\u4e2a\u5bb9\u5668\u5c31\u62e5\u6709\u72ec\u7acb\u7684\u4e3b\u673a\u540d\u548c\u57df\u540d\u4e86\uff0c\u5728\u7f51\u7edc\u4e0a\u5c31\u53ef\u4ee5\u88ab\u89c6\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u8282\u70b9\uff0c\u5728\u5bb9\u5668\u4e2d\u5bf9 hostname \u7684\u547d\u540d\u4e0d\u4f1a\u5bf9\u5bbf\u4e3b\u673a\u9020\u6210\u4efb\u4f55\u5f71\u54cd\u3002 <\/li><li> <strong>PID namespace<\/strong>\u00a0\u5b8c\u6210\u7684\u662f\u8fdb\u7a0b\u53f7\u7684\u9694\u79bb\uff0c\u4fdd\u8bc1\u4e86\u5bb9\u5668\u7684 init \u8fdb\u7a0b\u662f\u4ee5 1 \u53f7\u8fdb\u7a0b\u6765\u542f\u52a8\u7684\u3002 <\/li><li> <strong>IPC namespace<\/strong>\u00a0\u5b9e\u73b0\u4e86\u8fdb\u7a0b\u95f4\u901a\u4fe1\u7684\u9694\u79bb\uff0c\u5305\u62ec\u5e38\u89c1\u7684\u51e0\u79cd\u8fdb\u7a0b\u95f4\u901a\u4fe1\u673a\u5236\uff0c\u4f8b\u5982\uff1a\u4fe1\u53f7\u91cf\uff0c\u6d88\u606f\u961f\u5217\u548c\u5171\u4eab\u5185\u5b58\u3002\u6211\u4eec\u77e5\u9053\uff0c\u8981\u5b8c\u6210 IPC\uff0c\u9700\u8981\u7533\u8bf7\u4e00\u4e2a\u5168\u5c40\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u5373 IPC \u6807\u8bc6\u7b26\uff0c\u6240\u4ee5 IPC \u8d44\u6e90\u9694\u79bb\u4e3b\u8981\u5b8c\u6210\u7684\u5c31\u662f\u9694\u79bb IPC \u6807\u8bc6\u7b26\u3002 <\/li><li> <strong>Mount namespace<\/strong>\u00a0\u901a\u8fc7\u9694\u79bb\u6587\u4ef6\u7cfb\u7edf\u7684\u6302\u8f7d\u70b9\u6765\u8fbe\u5230\u5bf9\u6587\u4ef6\u7cfb\u7edf\u7684\u9694\u79bb\u3002\u4fdd\u8bc1\u4e86\u5bb9\u5668\u770b\u5230\u7684\u6587\u4ef6\u7cfb\u7edf\u7684\u89c6\u56fe\uff0c\u662f\u5bb9\u5668\u955c\u50cf\u63d0\u4f9b\u7684\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b83\u770b\u4e0d\u89c1\u5bbf\u4e3b\u673a\u4e0a\u7684\u5176\u5b83\u6587\u4ef6\uff0c\u9664\u4e86\u901a\u8fc7 -v \u53c2\u6570 bound \u7684\u90a3\u79cd\u6a21\u5f0f\uff0c\u662f\u53ef\u4ee5\u628a\u5bbf\u4e3b\u673a\u4e0a\u9762\u7684\u4e00\u4e9b\u76ee\u5f55\u548c\u6587\u4ef6\uff0c\u8ba9\u5b83\u5728\u5bb9\u5668\u91cc\u9762\u53ef\u89c1\u7684\uff1b <\/li><li><strong>Network namespace<\/strong>\u00a0\u5b9e\u73b0\u4e86\u64cd\u4f5c\u7cfb\u7edf\u5c42\u9762\u7684\u7f51\u7edc\u8d44\u6e90\u9694\u79bb\uff0c\u5305\u62ec\u7f51\u7edc\u8bbe\u5907\u63a5\u53e3\u3001IPv4 \u548c IPv6 \u534f\u8bae\u6808\uff0cIP \u8def\u7531\u8868\uff0c\u9632\u706b\u5899\uff0c\/proc\/net \u76ee\u5f55\uff0c\/sys\/class\/net \u76ee\u5f55\uff0cSockets \u5957\u63a5\u5b57\u7b49\u8d44\u6e90\u3002\u540c\u4e00\u4e2a\u7f51\u7edc\u8bbe\u5907\u53ea\u80fd\u4f4d\u4e8e\u4e00\u4e2a Network namespace \u4e2d\uff0c\u4e0d\u540c namespace \u4e2d\u7684\u7f51\u7edc\u8bbe\u5907\u53ef\u4ee5\u5229\u7528 veth pair \u8fdb\u884c\u6865\u63a5\u3002<\/li><li> <strong>User namespace<\/strong>\u00a0\u4e3b\u8981\u9694\u79bb\u4e86\u5b89\u5168\u76f8\u5173\u7684\u6807\u8bc6\u7b26\u548c\u5c5e\u6027\uff0c\u5305\u62ec User ID\u3001User Group ID\u3001root \u76ee\u5f55\u3001key \u4ee5\u53ca\u7279\u6b8a\u6743\u9650\u3002 <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u9645\u4e0a\uff0c\u8fd8\u6709\u7b2c 7 \u4e2a\u662f cgroup namespace\u3002Docker \u4e2d\u7528\u5230\u4e86\u524d\u516d\u79cd\uff0c\u7b2c 7 \u79cd cgroup namespace \u5728 Docker \u672c\u8eab\u5e76\u6ca1\u6709\u7528\u5230\uff0c\u4f46\u662f\u5728 runC \u5b9e\u73b0\u4e2d\u5b9e\u73b0\u4e86 cgroup namespace\u3002\u7528 cgroup namespace \u5e26\u6765\u7684\u4e00\u4e2a\u597d\u5904\u662f\u5bb9\u5668\u4e2d\u770b\u5230\u7684 cgroup \u89c6\u56fe\u662f\u4ee5\u6839\u7684\u5f62\u5f0f\u6765\u5448\u73b0\u7684\uff0c\u8fd9\u6837\u7684\u8bdd\u5c31\u548c\u5bbf\u4e3b\u673a\u4e0a\u9762\u8fdb\u7a0b\u770b\u5230\u7684 cgroup namespace \u7684\u4e00\u4e2a\u89c6\u56fe\u65b9\u5f0f\u662f\u76f8\u540c\u7684\uff0c\u53e6\u5916\u4e00\u4e2a\u597d\u5904\u662f\u8ba9\u5bb9\u5668\u5185\u90e8\u4f7f\u7528 cgroup \u4f1a\u53d8\u5f97\u66f4\u5b89\u5168\u3002 <\/p>\n\n\n\n<p class=\"has-background has-luminous-vivid-amber-background-color wp-block-paragraph\">cgroup namespace\u5728Linux \u5185\u68384.6\u4e4b\u540e\u652f\u6301<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u4ec0\u4e48\u662fNamespace\uff1f Linux Namespace\uff08\u547d\u540d\u7a7a\u95f4\uff09\u662f\u4e00\u79cd\u64cd\u4f5c\u7cfb\u7edf\u5c42\u7ea7\u7684\u8d44\u6e90\u9694\u79bb\u6280\u672f\uff0c\u80fd [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3526,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,22],"tags":[126],"class_list":["post-3523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-server","tag-namespace"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=3523"}],"version-history":[{"count":1,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3523\/revisions"}],"predecessor-version":[{"id":3527,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/3523\/revisions\/3527"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/3526"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=3523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=3523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=3523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}