{"id":727,"date":"2021-11-23T07:43:00","date_gmt":"2021-11-23T07:43:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=727"},"modified":"2021-11-23T07:43:00","modified_gmt":"2021-11-23T07:43:00","slug":"727","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/11\/23\/727\/","title":{"rendered":"Proxmox VE \u4e4b LXC \u5bb9\u5668"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/11\/1198094551.png\" alt=\"containers.png\" title=\"containers.png\"><\/p>\n<h2>1\uff0e    LXC\u7b80\u8ff0<\/h2>\n<p>Linux container\u662f\u4e00\u79cd\u8d44\u6e90\u9694\u79bb\u673a\u5236\u800c\u975e\u865a\u62df\u5316\u6280\u672f\u3002VMM\uff08VMM Virtual Machine<br \/>Monitor\uff09\u6216\u8005\u53ebHypervisor\u662f\u6807\u51c6\u7684\u865a\u62df\u5316\u6280\u672f\uff0c\u8fd9\u79cd\u6280\u672f\u901a\u8fc7\u865a\u62df\u5c42\uff08\u4e5f\u5c31\u662fVMM\u6216\u53ebHypervisor\uff09\uff0c\u4e3b\u8981\u4f5c\u7528\u4e00\u662f\u8ba9\u591a\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u548c\u5e94\u7528\u5171\u4eab\u786c\u4ef6\u8d44\u6e90\uff0c<br \/>\u5176\u4e8c\u662f\u628a\u4e0a\u5c42\u865a\u62df\u673a\u7684\u6307\u4ee4\u8f6c\u6362\u6210\u5e95\u5c42Host\u64cd\u4f5c\u7cfb\u7edf\u6240\u8ba4\u8bc6\u7684\u6307\u4ee4\uff0c\u8fd9\u5c31\u610f\u5473\u7740\u5728Linux\u4e0a\u53ef\u4ee5\u8dd1windows\u7cfb\u7edf\uff0ccontainer\u6280\u672f\u4ecb\u4e8echroot\u548cVM\u4e4b\u95f4\uff0c\u5176\u201c\u865a\u62df\u673a\u201d\u548c\u4e3b\u673a\u64cd\u4f5c\u7cfb\u7edf\u76f8\u540c\u6216\u5f88\u7c7b\u4f3c\uff0c\u5373Linux\u4e0b\u5747\u662fLinux\u67b6\u6784\u7684\uff0c\u6ca1\u6709\u5b89\u88c5windows\u865a\u62df\u673a\u7684\u3002cgroup\u5c31\u662f\u4e00\u4e2a\u8d44\u6e90\u9650\u5236\u5668\uff0c\u6ca1\u6709\u63d0\u4f9b\u9694\u79bb\u529f\u80fd\uff0c\u771f\u6b63\u7684\u9694\u79bb\u529f\u80fd\u5185\u6838\u4f7f\u7528namespace\u5b9e\u73b0\u7684\uff0c\u8fd9\u5c31\u610f\u5473\u7740cgroup\u8d44\u6e90\u9650\u5236\u7684\u6a21\u5757\u95f4\u5f71\u54cd\u6bd4container\u8981\u5927\u5f88\u591a\u3002<\/p>\n<p><strong>\u5b98\u65b9\u7ed9\u51fa\u7684LXC\u672a\u6765\u7684\u76ee\u6807\u662f\uff1a<\/strong><\/p>\n<p>The goal of LXC is to create an environment as close as possible as a standard<br \/>Linux installation but without the need for a separate kernel.<\/p>\n<h3>1.1  LXC\u4e0edocker\u7684\u5173\u7cfb<\/h3>\n<p>LXC\u5c06Linux\u8fdb\u7a0b\u6c99\u76d2\u5316\uff0c\u4f7f\u5f97\u8fdb\u7a0b\u4e4b\u95f4\u76f8\u4e92\u9694\u79bb\uff0c\u5e76\u4e14\u80fd\u591f\u63a7\u5236\u5404\u8fdb\u7a0b\u7684\u8d44\u6e90\u5206\u914d\u3002lxc<br \/>\u7528\u5bb9\u5668\u7684\u65b9\u5f0f\u4eff\u771f\u4e86\u4e00\u4e2a\u7c7b\u4f3c\u865a\u62df\u673a\u7684\u64cd\u4f5c\u4f53\u9a8c\uff0c\u5e76\u907f\u514d\u4e86\u865a\u62df\u673a\u989d\u5916\u7684\u7cfb\u7edf\u8d1f\u8f7d\u3002lxc\u5229\u7528cgroup\u548cnamespace\u5728linux\u5e94\u7528\u5c42\u521b\u5efa\u4e86\u4e00\u4e2a\u201c\u865a\u62df\u673a\u201d\uff08\u9694\u79bb\u7684\u88f8\u9732\u6587\u4ef6\u7cfb\u7edf\uff09\uff0c\u65e0\u6cd5\u6709\u6548\u652f\u6301\u8de8\u4e3b\u673a\u4e4b\u95f4\u7684\u5bb9\u5668\u8fc1\u79fb\u3001\u7ba1\u7406\u590d\u6742\uff08lxd\u89e3\u51b3\u4e86\u8fd9\u4e9b\u95ee\u9898\uff09\u3002lxc\u548cdocker\u4e0d\u540c\u5730\u65b9\u5728\u4e8elxc\u5305\u542b\u5b8c\u6574\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u662f\u4e00\u4e2a\u7cfb\u7edf\u5bb9\u5668\u3002<\/p>\n<p>Docker\u7684\u5e95\u5c42\u4f7f\u7528\u4e86LXC\u6765\u5b9e\u73b0\u7684\uff0c\u4f46docker\u5bf9lxc\u5c01\u88c5\uff0c\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u64cd\u4f5c\u6027\u548c\u79fb\u690d\u6027\u3002Docker\u5bb9\u5668\u5c06\u5e94\u7528\u548c\u5176\u4f9d\u8d56\u73af\u5883\u5168\u90e8\u6253\u5305\u5230\u4e00\u4e2a\u5355\u4e00\u5bf9\u8c61\u4e2d\uff0c\u5728\u4e0d\u5305\u542b\u5b8c\u6574\u7684\u64cd\u4f5c\u7cfb\u7edf\u7684\u60c5\u51b5\u4e0b\u5c31\u80fd\u8fd0\u884c\u666e\u901a\u5e94\u7528\uff0c\u66f4\u52a0\u8f7b\u91cf\u7ea7\uff0c\u53ef\u79fb\u690d\u6027\u66f4\u597d\u3002\u6240\u4ee5\u5b83\u6210\u4e3a\u4e86PaaS\uff08\u6bd4\u5982Kubernates\uff09\u5e73\u53f0\u7684\u57fa\u77f3\u3002<\/p>\n<p>\u9664\u4e86lxc\u5e95\u5c42\u57fa\u7840\u4e4b\u5916\uff0cDocker\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5177\u6709\u4ee5\u4e0b\u5f3a\u5927\u529f\u80fd\u7684\u9ad8\u7ea7\u5de5\u5177\uff1a<\/p>\n<p><strong>\u8de8\u673a\u5668\u7684\u4fbf\u643a\u5f0f\u90e8\u7f72\u3002<\/strong><br \/>Docker\u5b9a\u4e49\u4e86\u4e00\u79cd\u5c06\u5e94\u7528\u7a0b\u5e8f\u53ca\u5176\u6240\u6709\u4f9d\u8d56\u7ed1\u5b9a\u5230\u4e00\u4e2a\u5355\u72ec\u5bf9\u8c61\u4e2d\u7684\u683c\u5f0f\uff0c\u8be5\u5bf9\u8c61\u53ef\u4ee5\u88ab\u4f20\u8f93\u5230\u4efb\u4f55\u542f\u7528docker\u7684\u673a\u5668\u4e0a\uff0c\u5e76\u5728\u90a3\u91cc\u6267\u884c\uff0c\u4fdd\u8bc1\u66b4\u9732\u7ed9\u5e94\u7528\u7a0b\u5e8f\u7684\u6267\u884c\u73af\u5883\u662f\u76f8\u540c\u7684\u3002<br \/>Lxc\u5b9e\u73b0\u4e86\u6d41\u7a0b\u6c99\u76d2\uff0c\u8fd9\u662f\u4fbf\u643a\u5f0f\u90e8\u7f72\u7684\u91cd\u8981\u5148\u51b3\u6761\u4ef6\uff0c\u4f46\u5355\u9760\u8fd9\u4e00\u70b9\u5bf9\u4e8e\u4fbf\u643a\u5f0f\u90e8\u7f72\u6765\u8bf4\u662f\u4e0d\u591f\u7684\u3002\u5982\u679c\u60a8\u5411\u6211\u53d1\u9001\u4e86\u4e00\u4e2a\u5b89\u88c5\u5728\u81ea\u5b9a\u4e49lxc\u914d\u7f6e\u4e2d\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u526f\u672c\uff0c\u90a3\u4e48\u5b83\u51e0\u4e4e\u80af\u5b9a\u4e0d\u4f1a\u50cf\u6211\u4eec\u7684\u673a\u5668\u90a3\u6837\u5728\u60a8\u7684\u673a\u5668\u4e0a\u8fd0\u884c\uff0c\u56e0\u4e3a\u5b83\u4e0e\u60a8\u8ba1\u7b97\u673a\u7684\u7279\u5b9a\u914d\u7f6e\u6709\u5173\uff1a\u7f51\u7edc\uff0c\u5b58\u50a8\uff0c\u65e5\u5fd7\u8bb0\u5f55\uff0c\u53d1\u884c\u7248\uff0c\u7b49\u7b49\u3002Docker\u4e3a\u8fd9\u4e9b\u7279\u5b9a\u4e8e\u673a\u5668\u7684\u8bbe\u7f6e\u5b9a\u4e49\u4e86\u4e00\u4e2a\u62bd\u8c61\uff0c\u4ee5\u4fbf\u5b8c\u5168\u76f8\u540c\u7684docker\u5bb9\u5668\u53ef\u4ee5\u5728\u8bb8\u591a\u4e0d\u540c\u7684\u673a\u5668\u4e0a\u8fd0\u884c\uff0c\u5373\u4f7f\u4e0d\u540c\u4e3b\u673a\u5177\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u914d\u7f6e\u3002<\/p>\n<p><strong>\u4ee5\u5e94\u7528\u4e3a\u4e2d\u5fc3\u3002<\/strong><br \/>Docker\u9488\u5bf9\u5e94\u7528\u7a0b\u5e8f\u7684\u90e8\u7f72\u8fdb\u884c\u4e86\u4f18\u5316\uff0c\u800c\u4e0d\u662f\u673a\u5668\u3002\u8fd9\u53cd\u6620\u5728\u5176API\uff0c\u7528\u6237\u754c\u9762\uff0c\u8bbe\u8ba1\u7406\u5ff5\u548c\u6587\u6863\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0clxc\u52a9\u624b\u811a\u672c\u5c06\u5bb9\u5668\u4f5c\u4e3a\u8f7b\u91cf\u7ea7\u7684\u673a\u5668 -<br \/>\u57fa\u672c\u4e0a\u662f\u542f\u52a8\u901f\u5ea6\u66f4\u5feb\uff0c\u5185\u5b58\u66f4\u5c11\u7684\u670d\u52a1\u5668\u3002\u6211\u4eec\u8ba4\u4e3a\u5bb9\u5668\u4e0d\u6b62\u4e8e\u6b64\u3002<\/p>\n<p><strong>\u81ea\u52a8\u6784\u5efa\u3002<\/strong><br \/>Docker\u5305\u542b\u4e00\u4e2a\u5de5\u5177\uff0c\u4f9b\u5f00\u53d1\u4eba\u5458\u81ea\u52a8\u4ece\u6e90\u4ee3\u7801\u4e2d\u7ec4\u88c5\u4e00\u4e2a\u5bb9\u5668\uff0c\u5b8c\u5168\u63a7\u5236\u5e94\u7528\u7a0b\u5e8f\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u6784\u5efa\u5de5\u5177\uff0c\u6253\u5305\u7b49\u3002\u4ed6\u4eec\u53ef\u4ee5\u81ea\u7531\u4f7f\u7528make\uff0cmaven\uff0cchef\uff0cpuppet\uff0csalt\uff0cdebian\u5305\uff0crpms\uff0csource<br \/>tarballs\uff0c\u6216\u4e0a\u8ff0\u7684\u4efb\u4f55\u7ec4\u5408\uff0c\u800c\u4e0d\u7ba1\u673a\u5668\u7684\u914d\u7f6e\u5982\u4f55\u3002<\/p>\n<p><strong>\u7248\u672c\u8ffd\u6eaf\u3002<\/strong><br \/>Docker\u5305\u62ec\u7528\u4e8e\u8ddf\u8e2a\u5bb9\u5668\u7684\u8fde\u7eed\u7248\u672c\uff0c\u68c0\u67e5\u7248\u672c\u4e4b\u95f4\u7684\u5dee\u5f02\uff0c\u63d0\u4ea4\u65b0\u7248\u672c\uff0c\u56de\u6eda\u7b49\u7c7b\u4f3cgit\u7684\u529f\u80fd\u3002\u5386\u53f2\u8bb0\u5f55\u8fd8\u5305\u62ec\u5982\u4f55\u7ec4\u88c5\u4e00\u4e2a\u5bb9\u5668\u4ee5\u53ca\u7531\u8c01\u6765\u5b8c\u6210\uff0c\u56e0\u6b64\u60a8\u53ef\u4ee5\u4ece\u751f\u4ea7\u670d\u52a1\u5668\u4e00\u8def\u56de\u5230\u4e0a\u6e38\u5f00\u53d1\u5546\u3002<br \/>Docker\u4e5f\u5b9e\u73b0\u589e\u91cf\u4e0a\u4f20\u548c\u4e0b\u8f7d\uff0c\u7c7b\u4f3c\u4e8e\u201cgit pull\u201d\uff0c\u6240\u4ee5\u65b0\u7248\u672c\u7684\u5bb9\u5668\u53ea\u80fd\u901a\u8fc7\u53d1\u9001\u5dee\u5f02\u6765\u4f20\u8f93\u3002<\/p>\n<p><strong>\u7ec4\u4ef6\u91cd\u7528\u3002<\/strong><br \/>\u4efb\u4f55\u5bb9\u5668\u90fd\u53ef\u4ee5\u7528\u4f5c\u201c\u57fa\u7840\u56fe\u50cf\u201d\u6765\u521b\u5efa\u66f4\u4e13\u4e1a\u7684\u7ec4\u4ef6\u3002\u8fd9\u53ef\u4ee5\u624b\u52a8\u5b8c\u6210\u6216\u4f5c\u4e3a\u81ea\u52a8\u6784\u5efa\u7684\u4e00\u90e8\u5206\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u51c6\u5907\u7406\u60f3\u7684python\u73af\u5883\uff0c\u5e76\u5c06\u5176\u7528\u4f5c10\u4e2a\u4e0d\u540c\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u7840\u3002\u60a8\u7406\u60f3\u7684postgresql\u8bbe\u7f6e\u53ef\u4ee5\u91cd\u65b0\u7528\u4e8e\u60a8\u6240\u6709\u7684\u672a\u6765\u9879\u76ee\u3002<\/p>\n<p><strong>\u5171\u4eab\u3002<\/strong><br \/>Docker\u53ef\u4ee5\u8bbf\u95ee\u4e00\u4e2a\u516c\u5171\u6ce8\u518c\u8868\uff08<a href=\"http:\/\/index.docker.io\">http:\/\/index.docker.io<\/a>\uff09\uff0c\u6210\u5343\u4e0a\u4e07\u7684\u7528\u6237\u4e0a\u4f20\u4e86\u6709\u7528\u7684\u5bb9\u5668\uff1a\u4eceredis\uff0ccouchdb\uff0cpostgres\u5230irc\u4fdd\u9669\u7bb1\u5230rails\u5e94\u7528\u670d\u52a1\u5668\uff0c\u4ee5\u4fbf\u4e3a\u5404\u79cd\u53d1\u884c\u7248\u672c\u521b\u5efa\u57fa\u7840\u6620\u50cf\u3002\u767b\u8bb0\u5904\u8fd8\u5305\u62ec\u7531\u7801\u5934\u5de5\u4f5c\u7ec4\u7ef4\u62a4\u7684\u6709\u7528\u5bb9\u5668\u7684\u5b98\u65b9\u201c\u6807\u51c6\u5e93\u201d\u3002\u6ce8\u518c\u8868\u672c\u8eab\u662f\u5f00\u6e90\u7684\uff0c\u6240\u4ee5\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u90e8\u7f72\u4ed6\u4eec\u81ea\u5df1\u7684\u6ce8\u518c\u8868\u6765\u5b58\u50a8\u548c\u4f20\u8f93\u79c1\u6709\u5bb9\u5668\uff0c\u4f8b\u5982\u7528\u4e8e\u5185\u90e8\u670d\u52a1\u5668\u90e8\u7f72\u3002<\/p>\n<p><strong>\u5de5\u5177\u751f\u6001\u7cfb\u7edf\u3002<\/strong> Docker\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7528\u4e8e\u81ea\u52a8\u5316\u548c\u81ea\u5b9a\u4e49\u5bb9\u5668\u7684\u521b\u5efa\u548c\u90e8\u7f72\u7684API\u3002\u6709\u5927\u91cf\u7684\u5de5\u5177\u4e0edocker\u96c6\u6210\u6765\u6269\u5c55\u5176\u529f\u80fd\u3002<br \/>\uff08Dokku\uff0cDeis\uff0cFlynn\uff09\uff0c\u591a\u8282\u70b9\u7f16\u6392\uff08maestro\uff0csalt\uff0cmesos\uff0copenstack nova\uff09\uff0c\u7ba1\u7406\u4eea\u8868\u677f\uff08docker-<br \/>ui\uff0cOpenStack<br \/>Horizo??n\uff0c\u9020\u8239\u5382\uff09\uff0c\u914d\u7f6e\u7ba1\u7406\uff08\u53a8\u5e08\uff0cpuppet\uff09\uff0c\u6301\u7eed\u96c6\u6210\uff08jenkins\uff0cstrider\uff0ctravis\uff09\u7b49\u3002Docker\u6b63\u5728\u8fc5\u901f\u5c06\u81ea\u5df1\u5b9a\u4f4d\u4e3a\u57fa\u4e8e\u5bb9\u5668\u7684\u5de5\u5177\u7684\u6807\u51c6\u3002<\/p>\n<h2>2\uff0e \u5e38\u7528\u547d\u4ee4<\/h2>\n<h3>2.1 \u5e38\u7528\u64cd\u4f5c\u547d\u4ee4<\/h3>\n<p>LXC\u53ef\u4ee5\u521b\u5efa\u4e24\u79cd\u4e0d\u540c\u7684\u5bb9\u5668\uff1a<\/p>\n<ul>\n<li>\u00b7 \u7279\u6743\u6a21\u5f0f\uff0d\uff0d\u4ee5root\u8eab\u4efd\u8fd0\u884c\u5404\u79cdlxc\u547d\u4ee4\uff0c\u521b\u5efa\u7279\u6743\u5bb9\u5668\uff1b<\/li>\n<li>\u00b7 \u666e\u901a\u6a21\u5f0f\uff0d\uff0d\u4ee5\u666e\u901a\u7528\u6237\u8eab\u4efd\u8fd0\u884c\u5404\u79cdlxc\u547d\u4ee4\uff0c\u521b\u5efa\u975e\u7279\u6743\u5bb9\u5668<\/li>\n<\/ul>\n<p>\u666e\u901a\u5bb9\u5668\u53c8\u5f88\u591a\u9650\u5236(\u6bd4\u5982\u65e0\u6cd5\u521b\u5efa\u8bbe\u5907\u8282\u70b9)\uff0c\u4e0d\u8fc7\u4e5f\u66f4\u5b89\u5168(\u4e0d\u4f1a\u5371\u5bb3\u5230\u4e3b\u673a)\uff0c\u56e0\u4e3a\u8fd9\u79cd\u5bb9\u5668\u7684root\u7528\u6237\uff0c\u5176\u5b9e\u6620\u5c04\u5230\u4e3b\u673a\u4e0a\u7684\u4e00\u4e2a\u666e\u901a\u7528\u6237\u3002<\/p>\n<p><strong>1. lxc-checkconfig<\/strong> \uff1a\u68c0\u67e5\u7cfb\u7edf\u73af\u5883\u662f\u5426\u6ee1\u8db3\u5bb9\u5668\u4f7f\u7528\u8981\u6c42\u3002<\/p>\n<p><strong>2. lxc-create<\/strong> \uff1a\u521b\u5efalxc\u5bb9\u5668\uff1b<\/p>\n<p>lxc-create -n NAME -t TEMPLATE_NAME<\/p>\n<p><strong>3. lxc-start<\/strong> \uff1a\u542f\u52a8\u5bb9\u5668\uff1b<\/p>\n<p>lxc-start -n foo [-f config] \/bin\/bash<\/p>\n<p>lxc-start -n NAME -d<\/p>\n<p>-d\u5b88\u62a4\u8fdb\u7a0b\u65b9\u5f0f\u542f\u52a8\u5bb9\u5668\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u547d\u4ee4\uff0clxc-start\u5c06\u8fd0\u884c\/sbin\/init\u3002<\/p>\n<p>lxc-create\u521b\u5efa\u7684\u5bb9\u5668\uff0c\u5728\u505c\u6b62\u8fd0\u884c\u540e\u9700\u8981\u4f7f\u7528lxc-destroy\u9500\u6bc1\u3002<\/p>\n<p><strong>4. lxc-execute<\/strong> \uff1a\u6267\u884c\u547d\u4ee4<\/p>\n<p>lxc-execute -n foo [-f config] \/bin\/bash<\/p>\n<p>lxc-execute\u901a\u8fc7\u4e2d\u95f4\u8fdb\u7a0blxc-init\u4f7f\u547d\u4ee4\u5728\u5bb9\u5668\u4e2d\u8fd0\u884c\u3002<\/p>\n<p>\u5982\u679c\u5bb9\u5668\u4e0d\u5b58\u5728\uff0clxc-execute\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\uff0c\u505c\u6b62\u8fd0\u884c\u540e\u4f1a\u88ab\u81ea\u52a8\u9500\u6bc1\u3002<\/p>\n<p>lxc-execute\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u914d\u7f6e\u4f18\u5148\u7ea7\u5982\u4e0b\uff1a<\/p>\n<p>\u5982\u679c\u6267\u884c-f\u9009\u9879\uff0c\u90a3\u4e48\u4e4b\u524d\u521b\u5efa\u5bb9\u5668\u7684\u914d\u7f6e\u6587\u4ef6\u4e0d\u4f1a\u88ab\u4f7f\u7528\u3002\u5982\u679c\u6307\u5b9a-s\u9009\u9879\uff0c\u5219\u5728\u547d\u4ee4\u884c\u4e2d\u914d\u7f6e\u7684\u952e\u503c\u5bf9\u4f1a\u8986\u76d6\u914d\u7f6e\u6587\u4ef6\uff08\u65e0\u8bba\u4e4b\u524d\u7684\u8fd8\u662f-f\u6307\u5b9a\u7684\uff09\u7684\u76f8\u540c\u914d\u7f6e\u3002<\/p>\n<p><strong>5. lxc-stop<\/strong> \uff1a\u505c\u6b62\u5bb9\u5668\uff1b\uff08\u505c\u6b62\u547d\u4ee4\u5f88\u6162\uff09<\/p>\n<p>lxc-stop -n NAME -d<\/p>\n<p><strong>6. lxc-destory<\/strong> \uff1a\u5220\u9664\u5904\u4e8e\u505c\u673a\u72b6\u6001\u7684\u5bb9\u5668\uff1b<\/p>\n<p>lxc-destroy -n NAME<\/p>\n<p><strong>7. lxc-info<\/strong> \uff1a\u67e5\u770b\u5bb9\u5668\u76f8\u5173\u7684\u4fe1\u606f\uff1b<\/p>\n<p>lxc-info -n NAME<\/p>\n<p><strong>8. lxc-ls<\/strong> \uff1a\u5217\u51fa\u5bb9\u5668<\/p>\n<p>lxc-ls --fancy \u5217\u51fa\u8be6\u7ec6\u4fe1\u606f<\/p>\n<p><strong>9. lxc-monitor<\/strong> \uff1a\u76d1\u63a7\u5bb9\u5668<\/p>\n<p>lxc-monitor -n <code>foo|bar<\/code><\/p>\n<p>lxc-monitor -n <code>.*<\/code>   ;\u76d1\u63a7\u6240\u6709\u5bb9\u5668<\/p>\n<p>\u5f53\u4e00\u4e2a\u5bb9\u5668\u7684\u72b6\u6001\u53d8\u5316\u65f6\uff0clxc-monitor\u4f1a\u5728\u5c4f\u5e55\u4e0a\u6253\u5370\u51fa\u5bb9\u5668\u7684\u72b6\u6001\u3002<\/p>\n<p><strong>10. lxc-wait<\/strong> \uff1a\u76d1\u542c\u5bb9\u5668\u7279\u5b9a\u72b6\u6001\u540e\u9000\u51fa<\/p>\n<p>lxc-wait -n foo -s STOPPED &<\/p>\n<p><strong>11. lxc-cgroup<\/strong> \uff1a\u8bbe\u7f6e\u6216\u83b7\u53d6\u4e0ecgroup\u76f8\u5173\u7684\u53c2\u6570\uff08control group subsystem\uff09<\/p>\n<p>lxc-cgroup -n foo cpuset.cpus<\/p>\n<p>lxc-cgroup -n foo cpu.shares 512<\/p>\n<p><strong>11. lxc-snapshot<\/strong> \uff1a\u521b\u5efa\u548c\u6062\u590d\u5feb<br \/>\n\u7167\uff1b<\/p>\n<h3>2.2 \u8fdb\u5165\u5bb9\u5668<\/h3>\n<p><strong>\u8fdb\u5165\u5bb9\u5668\u7684\u65b9\u5f0f\u6709\u4e09\u79cd\uff1alxc-attach\u3001lxc-console\u3001\u548cSSH.<\/strong><\/p>\n<p><strong>1. lxc-attach<\/strong><\/p>\n<p>lxc-attach -n Name<\/p>\n<p>lxc-attach -n Name -- command<\/p>\n<p>\u63d0\u5347\u7279\u6743\uff0c\u5e76\u6307\u5b9a\u540d\u5b57\u7a7a\u95f4\uff0c\u5728\u6d4b\u8bd5\u4e3b\u673a\u4e0a\u8f6f\u4ef6\u65f6\u5f88\u6709\u7528\uff1a<\/p>\n<p>lxc-attach -n ubuntu1 -e -s 'NETWORK|UTSNAME'<\/p>\n<p><strong>2. lxc-console<\/strong><\/p>\n<p>lxc-console -n Name \u767b\u5f55\u5bb9\u5668\uff0c\u9700\u8981\u7528\u6237\u540d\u548c\u5bc6\u7801<\/p>\n<p><strong>3. ssh<\/strong><\/p>\n<p>ssh \u7528\u6237\u540d@IP<\/p>\n<h3>2.3 \u514b\u9686\u5bb9\u5668<\/h3>\n<p><code>\u514b\u9686<\/code>\u8981\u4e48\u662f\u5176\u4ed6\u5bb9\u5668\u7684\u4e00\u4efd\u62f7\u8d1d\uff0c\u8981\u4e48\u662f\u5176\u4ed6\u5bb9\u5668\u7684\u4e00\u4efd\u5feb\u7167\u3002<\/p>\n<p><strong>\u62f7\u8d1d\uff1a<\/strong> \u5b8c\u6574\u7684\u590d\u5236\u539f\u6765\u7684\u5bb9\u5668\uff0c\u6240\u5360\u7684\u7a7a\u95f4\u548c\u539f\u6765\u7684\u5bb9\u5668\u4e00\u6837\u5927<\/p>\n<p><strong>\u5feb\u7167\uff1a<\/strong> \u5229\u7528\u540e\u53f0\u6587\u4ef6\u7cfb\u7edf\u7684\u5feb\u7167\u529f\u80fd\uff0c\u521b\u5efa\u4e00\u4e2a\u5f88\u5c0f\u7684\u65b0\u5bb9\u5668\uff0c\u5728\u53d1\u751f\u5199\u64cd\u4f5c\u65f6\u624d\u8fdb\u884c\u590d\u5236<\/p>\n<p>\u8981\u60f3\u4f7f\u5feb\u7167\u62e5\u6709\u8fd9\u4e2a\u5199\u65f6\u590d\u5236\u7684\u7279\u6027\uff0c\u9700\u8981\u4e00\u4e2a\u7279\u6b8a\u5b58\u50a8\u7cfb\u7edf\uff0c\u652f\u6301\u5feb\u7167\u7684\u5b58\u50a8\u65b9\u5f0f\u6709\uff1aaufs\uff0cbtrfs\uff0cLVM\uff0coverlayfs\uff0czfs\u7b49\uff0c\u6bcf\u79cd\u5b58\u50a8\u65b9\u5f0f\u5404\u6709\u81ea\u5df1\u7279\u70b9\u3002<\/p>\n<p>lxc-clone\u7528\u4e8e\u521b\u5efa\u62f7\u8d1d\u548c\u5feb\u7167\uff0c\u5728\u521b\u5efa\u4e4b\u524d\u9700\u8981\u505c\u6b62\u5bb9\u5668\uff1a<\/p>\n<p>sudo lxc-stop -n Name<\/p>\n<p>sudo lxc-copy -n Name -N clone_Name    ;\u62f7\u8d1d<\/p>\n<p>sudo lxc-copy -s -n Name -N snapshot_Name   \uff1b\u5feb\u7167<\/p>\n<p>sudo lxc-snapshot -n Name { -r snapshot_Name -N nawName\uff1b\u521b\u5efa\u5feb\u7167\u6216\u6062\u590d<\/p>\n<p>\u521b\u5efa\u7684\u5feb\u7167\u4f4d\u4e8e\/var\/lib\/lxc\/\u5bb9\u5668\u540d\u76ee\u5f55\u4e0b\uff0c\u5feb\u7167\u540d\u5b57\u4e3asnap0\uff0csnap1\u2026<\/p>\n<h2>3. \u5b89\u88c5<\/h2>\n<p><strong>1\uff0e \u5b89\u88c5lxc \u548clxc \u81ea\u5e26\u7684\u6a21\u677f\u5305<\/strong><\/p>\n<p>sudo add-apt-repository ppa:ubuntu-lxc\/lxc-stable<\/p>\n<p>sudo apt-get update<\/p>\n<p>sudo apt install lxc lxc-templates  <\/p>\n<p><strong>2\uff0e \u6dfb\u52a0\u7f51\u6865<\/strong><\/p>\n<p><strong>lxc\u4e0d\u4f1a\u5904\u7406\u5bb9\u5668\u7f51\u7edc\uff0c\u9700\u8981\u914d\u7f6e\u7f51\u7edc\uff08\u5728Ubuntu\u4e0b\u901a\u8fc7apt\u5b89\u88c5\u7684\u8bdd\uff0c\u7f51\u6865\u5df2\u7ecf\u914d\u7f6e\u597d\uff09\u3002<\/strong><\/p>\n<p>sudo apt install bridge-utils -y<\/p>\n<p>brctl addbr virbr0  #\u6dfb\u52a0\u7f51\u6865<\/p>\n<p>brctl addif virbr0 ens33 ; # \u5c06\u7f51\u6865\u5173\u8054\u5230ens33\u8fd9\u4e2a\u7f51\u5361 \\r<\/p>\n<p>ip addr del dev ens33 192.168.253.128\/24 ; #\u628a\u7f51\u5361\u4e0a\u7684ip\u5220\u4e86 \\r<\/p>\n<p>ifconfig  virbr0 192.168.253.128\/24 up  #\u7ed9\u7f51\u6865\u914d\u7f6eip \\r<\/p>\n<p>route add default gw 192.168.253.2 #\u8bbe\u7f6e\u9ed8\u8ba4\u7f51\u5173<\/p>\n<h2>4.  LXC\u6a21\u677f<\/h2>\n<p>\u6240\u8c13\u7684\u6a21\u677f\u5c31\u662f\u4e00\u4e2a\u539f\u578b\uff0c\u4f9d\u636e\u8be5\u539f\u578b\u53ef\u4ee5\u521b\u5efa\u4e00\u7cfb\u5217\u7c7b\u4f3c\u7684LXC\u865a\u62df\u673a\uff0c\u5982\u679c\u4f7f\u7528lxc\u81ea\u5e26\u7684\u6a21\u677f\uff0c\u90a3\u4e48\u8be5\u539f\u578b\u53ea\u63d0\u4f9b\u6700\u57fa\u672c\u7684\u914d\u7f6e\uff0c\u5982\u679c\u60f3\u4f7f\u7528vim\uff0cgcc\uff0cmysql\u9700\u8981\u81ea\u5df1\u5236\u4f5c\u3002\u8fd9\u91cc\u6240\u8bf4\u7684\u6a21\u677f\u5236\u4f5c\uff0c\u53ea\u662f\u4e00\u4e2a\u6bd4\u8f83\u7b80\u5355\u7684\u6700\u57fa\u7840\u7684\u5236\u4f5c\uff0c\u6709\u70b9\u7c7b\u4f3c\u5d4c\u5165\u5f0f\u7cfb\u7edf\u7684\u6700\u5c0f\u7cfb\u7edf\u7684\u6982\u5ff5\uff0c\u53ea\u4fdd\u7559\u6700\u6700\u57fa\u672c\u7684\u5e94\u7528\uff0c\u5728\u8fd9\u57fa\u7840\u4e4b\u4e0a\uff0c\u6dfb\u52a0\u76f8\u5e94\u7684\u5e94\u7528\u3002<\/p>\n<p>\u6a21\u677f\u5c31\u662f\u521b\u5efa\u5bb9\u5668\u7684\u811a\u672c\uff0c\u5305\u542b\u5bb9\u5668\u4e2d\u5404\u79cd\u6e90\uff08\u6216\u7ec4\u4ef6\uff09\u5730\u5740\u53ca\u4e0b\u8f7d\u548c\u4e00\u6b65\u6b65\u5236\u4f5c\u5bb9\u5668\u7684\u65b9\u6cd5\uff0c\u672c\u8d28\u5c31\u662fshell\u811a\u672c\u3002<\/p>\n<p>\u521b\u5efaubuntu\u5bb9\u5668\u540e\uff0c\u5bb9\u5668\u6587\u4ef6\u7cfb\u7edf\u76ee\u5f55\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/11\/2827665707.png\" alt=\"lxc.png\" title=\"lxc.png\"><\/p>\n<p>\u521b\u5efaUbuntu\u7684lxc\u5bb9\u5668\u65e5\u5fd7\uff0c\u751f\u6210\u65f6\u95f4\u8d85\u8fc730min\uff08\u4e3b\u8981\u662f\u6e90\u4e0b\u8f7d\u65f6\u95f4\u957f\uff09\u3002<\/p>\n<p>\u53c2\u8003\uff1a<br \/>1\uff0e <a href=\"https:\/\/linuxcontainers.org\/\">https:\/\/linuxcontainers.org\/<\/a> \u5b98\u7f51<br \/>2\uff0e <a href=\"https:\/\/www.cnblogs.com\/along21\/p\/9184293.html\">Docker\u7cfb\u521702\u2014LXC---Docker\u7684\u201c\u524d\u8eab\u201d<\/a><br \/>3\uff0e <a href=\"https:\/\/blog.csdn.net\/L835311324\/article\/details\/84488470\">LXC\u7b80\u5355\u4ecb\u7ecd\u4e0e\u4f7f\u7528<\/a><br \/>4\uff0e <a href=\"https:\/\/blog.csdn.net\/shichaog\/article\/details\/38037903\">LXC\u4e4b\u4e09--\u521b\u5efa\u6a21\u677f<\/a><br \/>5\uff0e <a href=\"https:\/\/www.cnblogs.com\/xidongyu\/p\/8059781.html\">\u6700\u4f73\u865a\u62df\u5bb9\u5668LXC<\/a><br \/>6\uff0e <a href=\"https:\/\/www.cnblogs.com\/HacTF\/p\/8082196.html\">docker\u5230\u5e95\u6bd4LXC\u591a\u4e86\u4e9b\u4ec0\u4e48<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\uff0e LXC\u7b80\u8ff0 Linux container\u662f\u4e00\u79cd\u8d44\u6e90\u9694\u79bb\u673a\u5236\u800c\u975e\u865a\u62df\u5316\u6280\u672f\u3002VMM\uff08VMM V [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[60],"class_list":["post-727","post","type-post","status-publish","format-standard","hentry","category-vps","tag-pve"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=727"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/727\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}