{"id":45,"date":"2021-01-13T08:53:23","date_gmt":"2021-01-13T00:53:23","guid":{"rendered":"http:\/\/mengstudy.com\/?p=45"},"modified":"2021-01-13T08:53:23","modified_gmt":"2021-01-13T00:53:23","slug":"%e5%ae%89%e8%a3%85vagrant","status":"publish","type":"post","link":"https:\/\/fugary.com\/?p=45","title":{"rendered":"\u5b89\u88c5Vagrant"},"content":{"rendered":"<blockquote><p>\n  vagrant\u662fHashiCorp\u7684\u865a\u62df\u673a\u7ba1\u7406\u8f6f\u4ef6\uff0c\u53ef\u4ee5\u7ba1\u7406virtualbox\uff0cVMware\uff0cdocker\u7b49\u955c\u50cf, \u5728vagrant\u4e2d\u7edf\u4e00\u88ab\u79f0\u4e4b\u4e3abox\u3002<br \/>\n  \u5bf9\u4e8e\u642d\u5efa\u548c\u914d\u7f6e\u96c6\u7fa4\u5f00\u53d1\u73af\u5883\u5f88\u65b9\u4fbf\n<\/p><\/blockquote>\n<h4>\u4e0b\u8f7dvagrant<\/h4>\n<blockquote><p>\n  \u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/www.vagrantup.com\/downloads.html<br \/>\n  \u6587\u6863\u5730\u5740\uff1a https:\/\/www.vagrantup.com\/docs\/<br \/>\n  \u6839\u636e\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u53ef\u4ee5\u9009\u62e9\u5bf9\u5e94\u7684\u7248\u672c\u4e0b\u8f7d\n<\/p><\/blockquote>\n<p>\u4e0b\u8f7d\u5b8c\u6210\u4e4b\u540e\u76f4\u63a5\u70b9\u51fb\u5b89\u88c5\u5373\u53ef\uff0c\u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\u68c0\u67e5\u7248\u672c\u4fe1\u606f<\/p>\n<pre><code class=\"language-shell line-numbers\">$ vagrant -v\nVagrant 2.2.7\n$ vagrant box list\nThere are no installed boxes! Use `vagrant box add` to add some.\n<\/code><\/pre>\n<h4>\u4e0b\u8f7d\u66f4\u65b0powershell<\/h4>\n<p>\u6267\u884c\u6dfb\u52a0centos\u547d\u4ee4\uff0c\u6211\u76ee\u524d\u4f7f\u7528\u7684\u662fWindows7\uff0c\u53ef\u80fd\u51fa\u73b0powershell\u7248\u672c\u4e0d\u591f\uff0c\u62a5\u4e00\u4e2a\u9519\u8bef<\/p>\n<pre><code class=\"language-shell line-numbers\">$ vagrant box add centos\/7\nVagrant failed to initialize at a very early stage:\nThe version of powershell currently installed on this host is less than\nthe required minimum version. Please upgrade the installed version of\npowershell to the minimum required version and run the command again.\n  Installed version: 2\n  Minimum required version: 3\n<\/code><\/pre>\n<p>\u67e5\u770bpowershell\u7248\u672c\u547d\u4ee4\uff1a$psversiontable<\/p>\n<pre><code class=\"language-powershell line-numbers\">&gt; $psversiontable\n\nName                           Value\n----                           -----\nCLRVersion                     2.0.50727.5420\nBuildVersion                   6.1.7601.17514\nPSVersion                      2.0\nWSManStackVersion              2.0\nPSCompatibleVersions           {1.0, 2.0}\nSerializationVersion           1.1.0.1\nPSRemotingProtocolVersion      2.1\n<\/code><\/pre>\n<p>\u4e0b\u8f7d\u5b89\u88c5\u65b0\u7248powershell\uff1a<\/p>\n<p>\u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/docs.microsoft.com\/en-us\/powershell\/scripting\/wmf\/setup\/install-configure?view=powershell-7<\/p>\n<p>\u6839\u636e\u3010\u5b89\u88c5\u8bf4\u660e\u3011\u4fe1\u606f\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u64cd\u4f5c\u7cfb\u7edf\u7248\u672c\u7684\u5b89\u88c5\u6587\u4ef6\uff0c\u5982Windows7 SP1 64\u4f4d\u5bf9\u5e94\u7684\u662f\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/go.microsoft.com\/fwlink\/?linkid=839523\">Win7AndW2K8R2-KB3191566-x64.ZIP<\/a><\/p>\n<p>\u6ce8\u610f\uff1a\u5982\u679c\u5b89\u88c5\u7684\u65f6\u5019\u957f\u65f6\u95f4\u5361\u4f4f\u4e0d\u52a8\uff0c\u53ef\u80fd\u9700\u8981\u4fee\u590d\u4e0b\u66f4\u65b0\u7a0b\u5e8f\uff1a<\/p>\n<p>\u53c2\u8003\u5730\u5740\uff1ahttps:\/\/docs.microsoft.com\/zh-cn\/windows\/deployment\/update\/windows-update-resources<\/p>\n<p>\u5b89\u88c5\u540e\uff1a<\/p>\n<pre><code class=\"language-powershell line-numbers\">&gt; $psversiontable\n\nName                           Value\n----                           -----\nPSVersion                      5.1.14409.1005\nPSEdition                      Desktop\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}\nBuildVersion                   10.0.14409.1005\nCLRVersion                     4.0.30319.42000\nWSManStackVersion              3.0\nPSRemotingProtocolVersion      2.3\nSerializationVersion           1.1.0.1\n<\/code><\/pre>\n<h4>Vagrant\u57fa\u672c\u4f7f\u7528<\/h4>\n<p>Vagrant\u63d0\u4f9b\u5f88\u591a\u5df2\u7ecf\u6253\u5305\u597d\u7684box\u4ed3\u5e93\uff0c\u4ed3\u5e93\u641c\u7d22\u5730\u5740\uff1ahttps:\/\/app.vagrantup.com\/boxes\/search<br \/>\n\u627e\u5230\u81ea\u5df1\u9700\u8981\u7684box\uff0c\u6267\u884c\u547d\u4ee4\u4e0b\u8f7d\u5230\u672c\u5730\uff0c\u6839\u636ebox\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u6709\u51e0\u79cd\u683c\u5f0f\u53ef\u4ee5\u9009\u62e9\uff0cVMware\u6216\u8005virtualbox\u7b49<\/p>\n<pre><code class=\"language-shell line-numbers\">$ vagrant box add centos\/7\n==&gt; box: Loading metadata for box 'centos\/7'\n    box: URL: https:\/\/vagrantcloud.com\/centos\/7\nThis box can work with multiple providers! The providers that it\ncan work with are listed below. Please review the list and choose\nthe provider you will be working with.\n\n1) hyperv\n2) libvirt\n3) virtualbox\n4) vmware_desktop\n\nEnter your choice: 3\n==&gt; box: Adding box 'centos\/7' (v1905.1) for provider: virtualbox\n    box: Downloading: https:\/\/vagrantcloud.com\/centos\/boxes\/7\/versions\/1905.1\/providers\/virtualbox.box\n    box: Download redirected to host: cloud.centos.org\n<\/code><\/pre>\n<p>\u4e0b\u8f7d\u901f\u5ea6\u6bd4\u8f83\u6162\uff0c\u53ef\u4ee5\u628a\u5730\u5740\u590d\u5236\u4e0b\u6765\uff0c\u7136\u540e\u4f7f\u7528\u4e0b\u8f7d\u5de5\u5177\u4e0b\u8f7d<br \/>\n\u624b\u52a8\u4e0b\u8f7d\u540e\u6dfb\u52a0<\/p>\n<pre><code class=\"language-shell line-numbers\">$ vagrant box add centos\/7 .\/DownloadBoxes\/centos7.box\n==&gt; box: Box file was not detected as metadata. Adding it directly...\n==&gt; box: Adding box 'centos\/7' (v0) for provider:\n    box: Unpacking necessary files from: file:\/\/E:\/vagrant\/DownloadBoxes\/centos7.box\n    box:\n==&gt; box: Successfully added box 'centos\/7' (v0) for 'virtualbox'!\n<\/code><\/pre>\n<p>\u521d\u59cb\u5316\u865a\u62df\u673a\uff0c\u542f\u52a8\u865a\u62df\u673a<\/p>\n<pre><code class=\"language-shell line-numbers\">vagrant init centos\/7\nvagrant up\n<\/code><\/pre>\n<p>\u5982\u679c\u6ca1\u6709\u5b89\u88c5virtualbox\u7b49provider\uff0c\u542f\u52a8\u4f1a\u63d0\u793a<\/p>\n<pre><code>No usable default provider could be found for your system.\n<\/code><\/pre>\n<p>\u5b89\u88c5virtualbox<\/p>\n<p>\u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/www.virtualbox.org\/wiki\/Downloads<\/p>\n<p>\u5b89\u88c5\u597dvirtualbox\u4e4b\u540e\uff0c\u518d\u6b21\u8fd0\u884c<\/p>\n<pre><code>vagrant up\nvagrant ssh\n<\/code><\/pre>\n<p>\u767b\u5f55\u7cfb\u7edf\uff0c\u53ef\u4ee5\u6267\u884c\u5176\u4ed6\u64cd\u4f5c\u4e86<\/p>\n<p>\u5982\u679c\u76f4\u63a5\u4f7f\u7528virtualbox\u767b\u5f55\uff0c\u9ed8\u8ba4\u8d26\u6237\uff1avagrant\/vagrant<\/p>\n<h4>Vagrantfile\u914d\u7f6e<\/h4>\n<p>Vagrant\u6700\u4e3b\u8981\u7684\u914d\u7f6e\u6587\u4ef6\u5c31\u662fVagrantfile\uff0c\u914d\u7f6e\u865a\u62df\u673a\u76f8\u5173\u7684\u5c5e\u6027\uff0c\u7f51\u7edc\uff0c\u4ee5\u53ca\u811a\u672c\u6267\u884c\u7b49\u64cd\u4f5c\u3002<\/p>\n<p>Vagrant\u7684\u914d\u7f6e\u8bed\u6cd5\u662fRuby\u7684\uff0c\u6bcf\u4e2a\u9879\u76ee\u90fd\u9700\u8981\u6709\u4e00\u4e2aVagrantfile\uff0c\u5728\u6267\u884cvagrant init\u7684\u76ee\u5f55\u4e0b\u53ef\u4ee5\u627e\u5230\u8be5\u6587\u4ef6\uff0c\u53ef\u4ee5\u590d\u5236\u6b64\u6587\u4ef6\u76f4\u63a5\u521d\u59cb\u5316vagrant\u9879\u76ee\u3002<\/p>\n<pre><code class=\"language-ruby line-numbers\">Vagrant.configure(\"2\") do |config|\n# box\u6e90\n  config.vm.box = \"centos\/7\"\n# \u914d\u7f6e\u4e3b\u673a\u540d\n  config.vm.hostname = \"test.centos.local\"\n# \u914d\u7f6e\u6587\u4ef6\u5939\u540c\u6b65\n# config.vm.synced_folder \"..\/data\", \"\/vagrant_data\"\n# \u7aef\u53e3\u6620\u5c04\n# config.vm.network \"forwarded_port\", guest: 80, host: 8080\n# \u914d\u7f6e\u79c1\u6709\u7f51\u7edc,\u5982\u679c\u662fprivate_network\uff0c\u865a\u62df\u673a\u7f51\u7edc\u548c\u4e3b\u673a\u7f51\u7edc\u9694\u79bb, \u5916\u90e8\u4e0d\u80fdping\u901a\u865a\u62df\u673a\n# config.vm.network \"private_network\", ip: \"192.168.1.11\"\n# \u6865\u63a5\u6a21\u5f0f\uff0c\u4e3b\u673a\u4e4b\u5916\u53ef\u4ee5\u8bbf\u95ee\u5230\n  config.vm.network \"public_network\", ip: \"192.168.31.101\"\n  config.vm.provider \"virtualbox\" do |vb|\n  # vb.gui = true\n  # \u914d\u7f6e\u865a\u62df\u673a\u540d\u5b57\uff0c\u4e0d\u914d\u7f6e\u7684\u8bdd\uff0c\u81ea\u52a8\u4f1a\u4ea7\u751f\u865a\u62df\u673a\u540d\u5b57\uff0c\u914d\u7f6e\u865a\u62df\u673a\u5185\u5b58\u5927\u5c0f\n    vb.name = \"test-vm1\"\n    vb.memory = \"1024\"\n  end\n# \u914d\u7f6e\u521d\u59cb\u5316\u9700\u8981\u6267\u884c\u7684\u811a\u672c\uff0c\u6bd4\u5982\u66f4\u65b0\u8f6f\u4ef6\u5305\uff0c\u5b89\u88c5\u5e38\u7528\u8f6f\u4ef6\u7b49\n  config.vm.provision \"shell\", inline: &lt;&lt;-SHELL\n    yum update\n    yum install -y gcc\n    yum install -y net-tools.x86_64\n  SHELL\nend\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>vagrant\u662fHashiCorp\u7684\u865a\u62df\u673a\u7ba1\u7406\u8f6f\u4ef6\uff0c\u53ef\u4ee5\u7ba1\u7406virtualbox\uff0cVMware\uff0cdocker\u7b49 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[9,8],"_links":{"self":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/45"}],"collection":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45"}],"version-history":[{"count":0,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions"}],"wp:attachment":[{"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}