{"id":516,"date":"2021-09-29T14:22:00","date_gmt":"2021-09-29T14:22:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=516"},"modified":"2021-09-29T14:22:00","modified_gmt":"2021-09-29T14:22:00","slug":"516","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/09\/29\/516\/","title":{"rendered":"\u8d85\u7b80\u5355 Vagrant \u642d\u5efa\u672c\u5730\u865a\u62df\u5316\u73af\u5883"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/09\/2003054082.png\" alt=\"logo.png\" title=\"logo.png\"><\/p>\n<p>Vagrant\u662f\u4e00\u6b3e\u7528\u4e8e\u6784\u5efa\u53ca\u914d\u7f6e\u865a\u62df\u5f00\u53d1\u73af\u5883\u7684\u8f6f\u4ef6\uff0c\u57fa\u4e8eRuby,\u4e3b\u8981\u4ee5\u547d\u4ee4\u884c\u7684\u65b9\u5f0f\u8fd0\u884c\u3002<br \/>Vagrant\u4f5c\u4e3a\u6700\u5916\u5c42\u7684\u865a\u62df\u8f6f\u4ef6\uff0c\u76ee\u7684\u662f\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u5bb9\u6613\u5730\u4e0eProviders\u4e92\u52a8\u3002Vagrantfile\u8bb0\u5f55Providers\u548cProvisioners\u7684\u76f8\u5173\u4fe1\u606f\u3002<br \/>Providers\u4f5c\u4e3a\u670d\u52a1\uff0c\u5e2e\u52a9vagrant\u4f7f\u7528Boxes\u5efa\u7acb\u548c\u521b\u5efa\u865a\u62df\u73af\u5883\u3002Vagrant\u63d0\u4f9b\u7684\u5185\u5d4c\u7684Provider\u6709 VirtualBox\u3001Hyper-V\u3001Docker\u3001VMware\uff0c\u800cAWS\u4ee5\u63d2\u4ef6\u5f62\u5f0f\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n<h2>1.\u5b89\u88c5 <code>VirtualBox<\/code> \u548c \u5b89\u88c5 <code>Vagrant<\/code>\uff0c\u8bbf\u95ee\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u7a0b\u5e8f\u5b89\u88c5<\/h2>\n<ul>\n<li><code>VirtualBox<\/code> \u5b98\u65b9\u7f51\u5740: <a href=\"https:\/\/www.virtualbox.org\/\">https:\/\/www.virtualbox.org\/<\/a><\/li>\n<li><code>Vagrant<\/code> \u5b98\u65b9\u7f51\u5740: <a href=\"https:\/\/www.vagrantup.com\/\">https:\/\/www.vagrantup.com\/<\/a><\/li>\n<\/ul>\n<h2>2.\u4e0b\u8f7dVagrant Boxes\u57fa\u672c\u7cfb\u7edf\u955c\u50cf- \u8bbf\u95ee <code>Discover Vagrant Boxes<\/code><\/h2>\n<ul>\n<li>\n<p><a href=\"https:\/\/app.vagrantup.com\/boxes\/search\">https:\/\/app.vagrantup.com\/boxes\/search<\/a><\/p>\n<h3>\u627e\u5230\u9002\u7528 <code>virtualbox<\/code> \u865a\u62df\u673a\u7684 <code>Debian 11<\/code> \u955c\u50cf<\/h3>\n<\/li>\n<li><a href=\"https:\/\/app.vagrantup.com\/debian\/boxes\/bullseye64\">https:\/\/app.vagrantup.com\/debian\/boxes\/bullseye64<\/a><\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/09\/4034635824.png\" alt=\"d11.PNG\" title=\"d11.PNG\"><\/p>\n<h3>\u90e8\u7f72 debian\/bullseye64 Vagrant box \u4e24\u884c\u547d\u4ee4\u5c31\u80fd\u81ea\u52a8\u90e8\u7f72\u5b8c\u6210\u4e86<\/h3>\n<pre><code>vagrant init debian\/bullseye64\nvagrant up<\/code><\/pre>\n<ul>\n<li>\n<p>\u5b9e\u9645\u60c5\u51b5\u4f60\u61c2\u7684\uff0c\u6240\u4ee5\u6211\u5148\u5728\u56fd\u5916vps\u673a\u5668\uff0c\u5148\u4e0b\u8f7d\u4fdd\u5b58\u955c\u50cf <code>debian11.box<\/code> , \u4e0b\u8f7d\u79bb\u7ebf\u955c\u50cf\u7684<\/p>\n<pre><code>wget -O debian11.box  \\r\nhttps:\/\/app.vagrantup.com\/debian\/boxes\/bullseye64\/versions\/11.20210829.1\/providers\/virtualbox.box<\/code><\/pre>\n<h3>\u56fd\u5185\u4e2d\u79d1\u5927\u955c\u50cf: Centos\u548cUbuntu\u7cfb\u7edf\u7684 Vagrant box \u4e0b\u8f7d\u5730\u5740\uff0c\u9002\u5408\u56fd\u5185\u7f51\u7edc\u90e8\u7f72<\/h3>\n<\/li>\n<li><a href=\"https:\/\/mirrors.ustc.edu.cn\/centos-cloud\/centos\/8\/vagrant\/x86_64\/images\/\">https:\/\/mirrors.ustc.edu.cn\/centos-cloud\/centos\/8\/vagrant\/x86_64\/images\/<\/a><\/li>\n<li><a href=\"https:\/\/mirrors.ustc.edu.cn\/ubuntu-cloud-images\/vagrant\/trusty\/\">https:\/\/mirrors.ustc.edu.cn\/ubuntu-cloud-images\/vagrant\/trusty\/<\/a><\/li>\n<\/ul>\n<h2>3.\u4f7f\u7528 <code>vagrant box add<\/code> \u5efa\u7acb\u672c\u5730\u955c\u50cf<\/h2>\n<pre><code>vagrant box add debian D:vagrantdebian11.box\n# \u57fa\u7840\u955c\u50cf\u4fdd\u5b58\u786c\u76d8\u4f4d\u7f6e  C:Usersvip.vagrant.d\boxesdebian\u0000virtualbox<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/09\/2296911009.png\" alt=\"vagrant.PNG\" title=\"vagrant.PNG\"><\/p>\n<pre><code>PS C:VPCvagrant&gt; vagrant box add --help\nUsage: vagrant box add [options] &lt;name, url, or path&gt;\n\nPS C:VPCvagrant&gt; vagrant box add debian D:vagrantdebian11.box\n==&gt; box: Box file was not detected as metadata. Adding it directly...\n==&gt; box: Adding box 'debian' (v0) for provider:\n    box: Unpacking necessary files from: file:\/\/\/D:\/vagrant\/debian11.box\n    box:\n==&gt; box: Successfully added box 'debian' (v0) for 'virtualbox'!<\/code><\/pre>\n<h3><code>vagrant box list<\/code> \u67e5\u770b\u955c\u50cf<\/h3>\n<pre><code>PS C:VPCvagrant&gt; vagrant box list\ndebian (virtualbox, 0)<\/code><\/pre>\n<h2>4.\u4f7f\u7528 <code>vagrant up<\/code> \u5efa\u7acb\u865a\u62df\u673a\u548c\u542f\u52a8\u865a\u62df\u673a<\/h2>\n<ul>\n<li>\u5148\u5efa\u7acb\u4e00\u4e2a\u76ee\u5f55 <code>C:VPCvagrant<\/code>\uff0c\u5728\u8fd9\u4e2a\u76ee\u5f55 <code>init<\/code><\/li>\n<li>\n<p>\u8fd9\u4e2a\u76ee\u5f55\u5230\u65f6\u4f1a\u81ea\u52a8\u6302\u8f7d\u5230\u865a\u62df\u673a\u4e2d\uff0c\u547d\u4ee4\u884c\u8fdb\u5165\u8fd9\u4e2a\u76ee\u5f55<\/p>\n<pre><code>vagrant init debian\nvagrant up\n# \u865a\u62df\u673a\u78c1\u76d8\u4fdd\u5b58\u786c\u76d8\u4f4d\u7f6e  C:UsersvipVirtualBox VMsvagrant_default_1632921757898_12141<\/code><\/pre>\n<h3>\u8fd0\u884c <code>vagrant up<\/code> \u524d\u5148\u7f16\u8f91 <code>Vagrantfile<\/code>\uff0c\u5f00\u542f <code>config.vm.network <\/code>public_network\"\"<\/h3>\n<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u516c\u5171\u7f51\u7edc\uff0c\u5b83\u901a\u5e38\u4e0e\u6865\u63a5\u7f51\u7edc\u76f8\u5339\u914d\u3002<\/li>\n<li>\n<p>\u6865\u63a5\u7f51\u7edc\u4f7f\u673a\u5668\u663e\u793a\u4e3a\u7f51\u7edc\u4e0a\u7684\u53e6\u4e00\u4e2a\u7269\u7406\u8bbe\u5907\u3002<\/p>\n<pre><code># Create a public network, which generally matched to bridged network.\n# Bridged networks make the machine appear as another physical device on\n# your network.\nconfig.vm.network \"public_network\"<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/09\/1617084598.png\" alt=\"vagrant1.PNG\" title=\"vagrant1.PNG\"><\/p>\n<pre><code>PS C:VPCvagrant&gt; vagrant init debian\nA \"Vagrantfile\" has been placed in this directory. You are now\nready to \"vagrant up\" your first virtual environment! Please read\nthe comments in the Vagrantfile as well as documentation on\n\"vagrantup.com\" for more information on using Vagrant.\n\nvagrant.exe up <\/code><\/pre>\n<h3><code>vagrant status<\/code> \u67e5\u770b\u865a\u62df\u673a\u8fd0\u884c\u72b6\u6001; <code>vagrant halt<\/code> \u505c\u6b62; <code>vagrant up<\/code> \u91cd\u542f<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/09\/3355485654.png\" alt=\"vagrant2.PNG\" title=\"vagrant2.PNG\"><\/p>\n<pre><code>PS C:VPCvagrant&gt; vagrant status\nCurrent machine states:\n\ndefault                   running (virtualbox)\n\nThe VM is running. To stop this VM, you can run \"vagrant halt\" to\nshut it down forcefully, or you can run \"vagrant suspend\" to simply\nsuspend the virtual machine. In either case, to restart it again,\nsimply run \"vagrant up\".\nPS C:VPCvagrant&gt; vagrant halt\n==&gt; default: Attempting graceful shutdown of VM...<\/code><\/pre>\n<h3><code>vagrant ssh<\/code> \u767b\u9646\u865a\u62df\u673a\uff0c<code>ip addr<\/code> \u67e5\u770bIP\u5730\u5740<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/09\/2913229980.png\" alt=\"vagrant3.PNG\" title=\"vagrant3.PNG\"><\/p>\n<pre><code>vagrant ssh\nip addr\nsudo -i # \u5207\u6362\u5230root<\/code><\/pre>\n<h3>5.\u6dfb\u52a0\u8bc1\u4e66\u65b9\u4fbf\u4f7f\u7528 <code>Xshell<\/code> \u767b\u9646<\/h3>\n<pre><code>root@bullseye:~# df -h\nFilesystem      Size  Used Avail Use% Mounted on\n\n\/dev\/sda1        20G  856M   18G   5% \/\nvagrant         112G   64G   48G  58% \/vagrant\n\n# Windows\u7cfb\u7edf\u4e2d vagrant \u76ee\u5f55 \u6302\u8f7d\u5728\u865a\u62df\u673a \/vagrant\n\nmkdir -p \/root\/.ssh\ncp \/vagrant\/authorized_keys  \/root\/.ssh\/authorized_keys\n<\/code><\/pre>\n<h2>6. <code>vagrant reload<\/code> \u91cd\u8f7d\u865a\u673a \u548c  <code>vagrant destroy<\/code> \u5220\u9664\u865a\u673a<\/h2>\n<\/li>\n<li>\u91cd\u8f7d\u865a\u673a: \u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u4f1a\u91cd\u542f\u865a\u673a\uff0c\u5e76\u4e14\u91cd\u65b0\u52a0\u8f7d <code>Vagrantfile<\/code> \u4e2d\u7684\u914d\u7f6e\u4fe1\u606f<\/li>\n<li>\u5220\u9664\u865a\u673a: \u6700\u540e\uff0c\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u53ef\u4ee5\u5f7b\u5e95\u5220\u9664\u865a\u673a\uff0c\u5305\u62ec\u6574\u4e2a\u865a\u673a\u6587\u4ef6<\/li>\n<li>PS. \u6267\u884c <code>vagrant<\/code> \u547d\u4ee4, \u8981\u5728 \u5305\u542b <code>Vagrantfile<\/code> \u7684\u76ee\u5f55\u6267\u884c<\/li>\n<\/ul>\n<h2>7. \u56fd\u5185Linux\u7cfb\u7edf\u66f4\u6362\u4e2d\u79d1\u5927\u8f6f\u4ef6\u6e90<\/h2>\n<pre><code>sed -i 's\/deb.debian.org\/mirrors.ustc.edu.cn\/g'  \/etc\/apt\/sources.list\nsed -i 's\/deb.debian.org\/mirrors.ustc.edu.cn\/g'  \/etc\/apt\/sources.list.d\/unstable.list\napt update<\/code><\/pre>\n<h3>\u76f8\u5173\u6587\u7ae0: \u8d85\u8be6\u7ec6\u7684 Vagrant \u4e0a\u624b\u6307\u5357<\/h3>\n<ul>\n<li><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/259833884\">https:\/\/zhuanlan.zhihu.com\/p\/259833884<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Vagrant\u662f\u4e00\u6b3e\u7528\u4e8e\u6784\u5efa\u53ca\u914d\u7f6e\u865a\u62df\u5f00\u53d1\u73af\u5883\u7684\u8f6f\u4ef6\uff0c\u57fa\u4e8eRuby,\u4e3b\u8981\u4ee5\u547d\u4ee4\u884c\u7684\u65b9\u5f0f\u8fd0\u884c\u3002Vagr [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,6],"tags":[52,17],"class_list":["post-516","post","type-post","status-publish","format-standard","hentry","category-linux","category-vps","tag-inux","tag-vps"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/516","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=516"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}