{"id":540,"date":"2021-08-21T19:46:54","date_gmt":"2021-08-21T10:46:54","guid":{"rendered":"https:\/\/roroing.net\/?p=540"},"modified":"2021-09-05T17:24:31","modified_gmt":"2021-09-05T08:24:31","slug":"lxc%e7%94%a8%e3%81%ae%e9%96%a2%e9%80%a3%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88","status":"publish","type":"post","link":"https:\/\/roroing.net\/?p=540","title":{"rendered":"lxc\u7528\u306e\u95a2\u9023\u30b9\u30af\u30ea\u30d7\u30c8"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6700\u8fd1LXC\u3070\u304b\u308a\u89e6\u3063\u3066\u3044\u305f\u306e\u3067\u30db\u30b9\u30c8\u304b\u3089\u30b2\u30b9\u30c8OS\u3092\u8a2d\u5b9a\u3067\u304d\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u304b\u3044\u3066\u307f\u305f\u3002<br>\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3068SSH\u516c\u958b\u9375\u8a8d\u8a3c\u306e\u8a2d\u5b9a\u3002ssh\u306f\u5185\u5bb9\u8efd\u304f\u3044\u3058\u308c\u3070\u4ed6\u3067\u3082\u4f7f\u3044\u307e\u308f\u305b\u305d\u3046\u3002<br>OS\u306fcentos7.9\u3092\u60f3\u5b9a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#network config\nrm \/var\/lib\/lxc\/$1\/rootfs\/etc\/sysconfig\/network-scripts\/ifcfg-eth0\nlxc-attach -n $1 -- bash -c 'echo \"DEVICE=eth0\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"BOOTPROTO=none\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"ONBOOT=yes\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"NM_CONTROLLED=no\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"TYPE=Ethernet\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"IPADDR='$1'\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"NETMASK='$2'\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"GATEWAY='$3'\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"DNS1=8.8.8.8\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 -- bash -c 'echo \"DNS1=8.8.4.4\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'\nlxc-attach -n $1 systemctl restart network<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#ssh config\nlxc-attach -n $1 -- yum -y install openssh-server\nlxc-attach -n $1 -- ssh-keygen -N \"\" -f ~\/.ssh\/id_rsa\nlxc-attach -n $1 mv ~\/.ssh\/id_rsa.pub ~\/.ssh\/authorized_keys\nlxc-attach -n $1 chmod 600  ~\/.ssh\/authorized_keys\nlxc-attach -n $1 -- sed -i 's\/^PubkeyAuthentication.*$\/PubkeyAuthentication yes\/' \/etc\/ssh\/sshd_config\nlxc-attach -n $1 -- sed -i 's\/PasswordAuthentication yes\/PasswordAuthentication no\/' \/etc\/ssh\/sshd_config\nlxc-attach -n $1 systemctl restart sshd\nlxc-attach -n $1 cat ~\/.ssh\/id_rsa<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u500b\u4eba\u7684\u306b\u4e0b\u8a18\u884c\u306e\u5f15\u6570\u3092\u5c55\u958b\u3067\u304d\u306a\u3044\u3053\u3068\u306b\u82e6\u52b4\u3057\u305f\u3002<br><code> lxc-attach -n $1 -- bash -c 'echo \"IPADDR='$1'\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-eth0'<\/code>  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b7\u30f3\u30b0\u30eb\u30af\u30a9\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3063\u3066\u5f37\u5236\u7684\u306b\u3059\u3079\u3066\u6587\u5b57\u5217\u306b\u3059\u308b\u3082\u306e\u3060\u3068\u601d\u3063\u3066\u308b\u304b\u3089<br>echo\u4ee5\u964d\u306f\u5168\u3066\u6587\u5b57\u5217\u3057\u304b\u3067\u304d\u306a\u3044\u3002<br>\u3067\u3082\u3050\u3050\u3063\u305f\u3089\u3001\u3080\u3057\u308d$1\u306e\u5834\u6240\u3092\u30b7\u30f3\u30b0\u30eb\u30af\u30a9\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u3055\u3089\u306b\u56f2\u3063\u305f\u3089\u5909\u6570\u6271\u3044\u3068\u306a\u3063\u305f\u3002<br>\u306a\u305c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br>\u53c2\u8003<br>sed-i\u306b\u3064\u3044\u3066<br>https:\/\/www.usupi.org\/sysad\/197.html<br><br>lxc-attach\u306b\u3064\u3044\u3066<br>https:\/\/gihyo.jp\/admin\/serial\/01\/linux_containers\/0008?page=4<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1LXC\u3070\u304b\u308a\u89e6\u3063\u3066\u3044\u305f\u306e\u3067\u30db\u30b9\u30c8\u304b\u3089\u30b2\u30b9\u30c8OS\u3092\u8a2d\u5b9a\u3067\u304d\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u304b\u3044\u3066\u307f\u305f\u3002\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3068SSH\u516c\u958b\u9375\u8a8d\u8a3c\u306e\u8a2d\u5b9a\u3002ssh\u306f\u5185\u5bb9\u8efd\u304f\u3044\u3058\u308c\u3070\u4ed6\u3067\u3082\u4f7f\u3044\u307e\u308f\u305b\u305d\u3046\u3002OS\u306fcentos7.9\u3092\u60f3\u5b9a \u500b\u4eba\u7684\u306b\u4e0b\u8a18\u884c\u306e\u5f15 <a href=\"https:\/\/roroing.net\/?p=540\" class=\"more-link\">...<span class=\"screen-reader-text\"> \"lxc\u7528\u306e\u95a2\u9023\u30b9\u30af\u30ea\u30d7\u30c8\"<\/span> \u3092\u7d9a\u3051\u3066\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[11,14],"tags":[],"class_list":["post-540","post","type-post","status-publish","format-standard","category-lxc","category-14","h-entry","hentry","h-as-article"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/posts\/540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/roroing.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=540"}],"version-history":[{"count":2,"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/posts\/540\/revisions"}],"predecessor-version":[{"id":543,"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/posts\/540\/revisions\/543"}],"wp:attachment":[{"href":"https:\/\/roroing.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roroing.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roroing.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}