{"id":2424,"date":"2021-01-03T14:46:04","date_gmt":"2021-01-03T06:46:04","guid":{"rendered":"http:\/\/39.97.231.10\/?p=2424"},"modified":"2021-01-03T14:46:04","modified_gmt":"2021-01-03T06:46:04","slug":"linux-namespace%e5%91%bd%e5%90%8d%e7%a9%ba%e9%97%b4","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=2424","title":{"rendered":"Linux namespace\u547d\u540d\u7a7a\u95f4"},"content":{"rendered":"<div>\nnamespace\u63d0\u4f9b\u4e00\u79cd\u9694\u79bb\u673a\u5236\uff0c\u8ba9\u4e0d\u540c\u7684namespace\u4e0b\u7684\u8fdb\u7a0b\u770b\u5230\u7684\u5168\u5c40\u8d44\u6e90\u4e0d\u540c\uff0c\u6bcf\u4e00\u4e2anamespace\u6709\u4e00\u4e2a\u81ea\u5df1\u72ec\u7acb\u7684\u5168\u5c40\u8d44\u6e90\u5b9e\u4f8b\u3002<br \/>\nnamespace\u7684\u4e00\u4e2a\u7528\u9014\u662f\u5b9e\u73b0\u5bb9\u5668\u3002<\/p>\n<div class=\\\"image-package\\\">\n<div class=\\\"image-container\\\">\n<div class=\\\"image-container-fill\\\"><\/div>\n<div class=\\\"image-view\\\" data-width=\\\"1506\\\" data-height=\\\"590\\\"><img class=\\\"\\\" src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15604519-f5138275818db919.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/1200\/format\/webp\\\" width=\\\"768\\\" height=\\\"301\\\" data-original-src=\\\"\/\/upload-images.jianshu.io\/upload_images\/15604519-f5138275818db919.png\\\" data-original-width=\\\"1506\\\" data-original-height=\\\"590\\\" data-original-format=\\\"image\/png\\\" data-original-filesize=\\\"137714\\\" data-image-index=\\\"0\\\" \/><\/div>\n<\/div>\n<div class=\\\"image-caption\\\"><\/div>\n<\/div>\n<h2>Linux\u7cfb\u7edf\u4e0b\u7684namespace\u7c7b\u578b<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u540d\u79f0<\/th>\n<th>API\u4e2d\u4f7f\u7528\u7684\u6807\u8bc6<\/th>\n<th>\u624b\u518c<\/th>\n<th>\u9694\u79bb\u7684\u8d44\u6e90<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Cgroup<\/td>\n<td>CLONE_NEWCGROUP<\/td>\n<td>cgroup_namespaces(7)<\/td>\n<td>Cgroup root directory<\/td>\n<\/tr>\n<tr>\n<td>IPC<\/td>\n<td>CLONE_NEWIPC<\/td>\n<td>ipc_namespaces(7)<\/td>\n<td>System V IPC, POSIX message queues<\/td>\n<\/tr>\n<tr>\n<td>Network<\/td>\n<td>CLONE_NEWNET<\/td>\n<td>network_namespaces(7)<\/td>\n<td>Network devices,stacks,ports,etc.<\/td>\n<\/tr>\n<tr>\n<td>Mount<\/td>\n<td>CLONE_NEWNS<\/td>\n<td>mount_namespaces(7)<\/td>\n<td>Mount points<\/td>\n<\/tr>\n<tr>\n<td>PID<\/td>\n<td>CLONE_NEWPID<\/td>\n<td>pid_namespaces(7)<\/td>\n<td>Process IDs<\/td>\n<\/tr>\n<tr>\n<td>Time<\/td>\n<td>CLONE_NEWTIME<\/td>\n<td>time_namespaces(7)<\/td>\n<td>Boot and monotonic clocks<\/td>\n<\/tr>\n<tr>\n<td>User<\/td>\n<td>CLONE_NEWUSER<\/td>\n<td>user_namespaces(7)<\/td>\n<td>User and group IDs<\/td>\n<\/tr>\n<tr>\n<td>UTS<\/td>\n<td>CLONE_NEWUTS<\/td>\n<td>uts_namespaces(7)<\/td>\n<td>Hostname and NIS domain name<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>namespace\u76f8\u5173\u7cfb\u7edf\u8c03\u7528<\/h2>\n<p><strong>clone<\/strong> \u521b\u5efa\u65b0\u8fdb\u7a0b\uff0cflags\u53c2\u6570\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u65b0\u7684namespace<br \/>\n<strong>setns<\/strong> \u8ba9\u8fdb\u7a0b\u52a0\u5165\u5b58\u5728\u7684namespace<br \/>\n<strong>unshare<\/strong> \u5c06\u8c03\u7528\u8fdb\u7a0b\u79fb\u52a8\u5230\u65b0\u7684namespace\u4e2d<br \/>\n<strong>ioctl_ns<\/strong> \u67e5\u770bnamespace\u7684\u4fe1\u606f<\/p>\n<h2>\u8fdb\u7a0bnamespace\u76ee\u5f55<\/h2>\n<p>\/proc\/[pid]\/ns\/cgroup \u8fdb\u7a0bcgroup\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<br \/>\n\/proc\/[pid]\/ns\/ipc \u8fdb\u7a0bIPC\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<br \/>\n\/proc\/[pid]\/ns\/mnt \u8fdb\u7a0bmount\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<br \/>\n\/proc\/[pid]\/ns\/net \u8fdb\u7a0b\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<br \/>\n\/proc\/[pid]\/ns\/pid \u8fdb\u7a0bPID\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<br \/>\n\/proc\/[pid]\/ns\/pid_for_children \u8be5\u8fdb\u7a0b\u7684\u5b50\u8fdb\u7a0b\u7684PID\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<br \/>\n\/proc\/[pid]\/ns\/time \u8fdb\u7a0btime\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<br \/>\n\/proc\/[pid]\/ns\/user \u8fdb\u7a0buser\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<br \/>\n\/proc\/[pid]\/ns\/uts \u8fdb\u7a0bUTS\u547d\u540d\u7a7a\u95f4\u53e5\u67c4<\/p>\n<h2>namespace limit<\/h2>\n<p>\/proc\/sys\/user\u76ee\u5f55<br \/>\nmax_cgroup_namespaces<br \/>\nmax_inotify_instances<br \/>\nmax_inotify_watches<br \/>\nmax_ipc_namespaces<br \/>\nmax_mnt_namespaces<br \/>\nmax_net_namespaces<br \/>\nmax_pid_namespaces<br \/>\nmax_user_namespaces<br \/>\nmax_uts_namespaces<\/p>\n<h2>namespace\u751f\u547d\u5468\u671f<\/h2>\n<p>namespace\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u8fdb\u7a0b\u7ed3\u675f\u6216\u79bb\u5f00namespace\uff0c\u8be5namespace\u751f\u547d\u5468\u671f\u7ed3\u675f<\/p>\n<div class=\\\"image-package\\\"><\/div>\n<h2>\u76f8\u5173\u547d\u4ee4<\/h2>\n<p>lsns \u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u7cfb\u7edf\u4e0b\u6240\u6709\u7684namespace<br \/>\n\/proc\/[pid]\/ns \u4f2a\u6587\u4ef6\u7cfb\u7edf\u4e0b\u8bb0\u5f55\u4e86\u8fdb\u7a0b\u7684\u6240\u6709namespace\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>namespace\u63d0\u4f9b\u4e00\u79cd\u9694\u79bb\u673a\u5236\uff0c\u8ba9\u4e0d\u540c\u7684namespace\u4e0b\u7684\u8fdb\u7a0b\u770b\u5230\u7684\u5168\u5c40\u8d44\u6e90\u4e0d\u540c\uff0c\u6bcf\u4e00\u4e2anamespa &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=2424\"> <span class=\"screen-reader-text\">Linux namespace\u547d\u540d\u7a7a\u95f4<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[102,124],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"namespace\u63d0\u4f9b\u4e00\u79cd\u9694\u79bb\u673a\u5236\uff0c\u8ba9\u4e0d\u540c\u7684namespace\u4e0b\u7684\u8fdb\u7a0b\u770b\u5230\u7684\u5168\u5c40\u8d44\u6e90\u4e0d\u540c\uff0c\u6bcf\u4e00\u4e2anamespa&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/2424"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2424"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/2424\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2424"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}