{"id":1037,"date":"2014-10-27T16:04:45","date_gmt":"2014-10-27T08:04:45","guid":{"rendered":"http:\/\/hesiwei.cn\/?p=1037"},"modified":"2014-10-27T16:04:45","modified_gmt":"2014-10-27T08:04:45","slug":"%e4%bd%bf%e7%94%a8-vagrant-%e6%90%ad%e5%bb%ba%e8%b7%a8%e5%b9%b3%e5%8f%b0%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"http:\/\/hesiwei.cn\/?p=1037","title":{"rendered":"\u4f7f\u7528 Vagrant \u642d\u5efa\u8de8\u5e73\u53f0\u5f00\u53d1\u73af\u5883"},"content":{"rendered":"<p><a rel=\"nofollow noopener noreferrer\" href=\"http:\/\/vagrantup.com\/\" target=\"_blank\">Vagrant<\/a>&nbsp;\u662f\u4e00\u6b3e\u7528\u6765\u6784\u5efa\u865a\u62df\u5f00\u53d1\u73af\u5883\u7684\u5de5\u5177\uff0c\u975e\u5e38\u9002\u5408 php\/python\/ruby\/java \u8fd9\u7c7b\u8bed\u8a00\u5f00\u53d1 web \u5e94\u7528\u3002\u53ef\u4ee5\u901a\u8fc7 Vagrant \u5c01\u88c5\u4e00\u4e2a Linux \u7684\u5f00\u53d1\u73af\u5883\uff0c\u5206\u53d1\u7ed9\u56e2\u961f\u6210\u5458\uff0c\u6210\u5458\u53ef\u4ee5\u5728\u81ea\u5df1\u7684\u684c\u9762\u7cfb\u7edf\uff08Mac\/Windows\/Linux\uff09\u4e0a\u5f00\u53d1\u7a0b\u5e8f\uff0c\u4ee3\u7801\u5374\u80fd\u7edf\u4e00\u5728\u5c01\u88c5\u597d\u7684\u73af\u5883\u91cc\u8fd0\u884c\u3002<\/p>\n<p>\u5b89\u88c5\u6b65\u9aa41. \u5b89\u88c5 VirtualBox<\/p>\n<p>\u865a\u62df\u673a\u8fd8\u662f\u5f97\u4f9d\u9760 VirtualBox \u6765\u642d\u5efa\uff0c\u514d\u8d39\u5c0f\u5de7\u3002<br \/>\u4e0b\u8f7d\u5730\u5740\uff1a<a rel=\"nofollow noopener noreferrer\" href=\"https:\/\/www.virtualbox.org\/wiki\/Downloads\" target=\"_blank\">https:\/\/www.virtualbox.org\/wiki\/Downloads<\/a><\/p>\n<p>2. \u5b89\u88c5 Vagrant<\/p>\n<p>\u4e0b\u8f7d\u5730\u5740\uff1a<a rel=\"nofollow noopener noreferrer\" href=\"http:\/\/downloads.vagrantup.com\/\" target=\"_blank\">http:\/\/downloads.vagrantup.com\/<\/a>&nbsp;\u6839\u636e\u63d0\u793a\u4e00\u6b65\u6b65\u5b89\u88c5\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u8fd8\u5f97\u4e0b\u8f7d\u5b98\u65b9\u5c01\u88c5\u597d\u7684\u57fa\u7840\u955c\u50cf\uff1a<br \/>Ubuntu precise 32 VirtualBox&nbsp;<a rel=\"nofollow noopener noreferrer\" href=\"http:\/\/files.vagrantup.com\/precise32.box\" target=\"_blank\">http:\/\/files.vagrantup.com\/precise32.box<\/a><br \/>Ubuntu precise 64 VirtualBox&nbsp;<a rel=\"nofollow noopener noreferrer\" href=\"http:\/\/files.vagrantup.com\/precise64.box\" target=\"_blank\">http:\/\/files.vagrantup.com\/precise64.box<\/a><\/p>\n<p>\u5176\u4ed6\u7cfb\u7edf\u7684\u955c\u50cf\u4e0b\u8f7d\uff1a<a rel=\"nofollow noopener noreferrer\" href=\"http:\/\/www.vagrantbox.es\/\" target=\"_blank\">http:\/\/www.vagrantbox.es\/<\/a><\/p>\n<p>3. \u6dfb\u52a0\u955c\u50cf\u5230 Vagrant<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u4e0b\u8f7d\u7684\u955c\u50cf\u5b58\u653e\u8def\u5f84\u662f&nbsp;<code>~\/box\/precise64.box<\/code>\uff0c\u5728\u7ec8\u7aef\u91cc\u8f93\u5165\uff1a<br \/>$ vagrant box add ubuntu64&nbsp;~\/box\/precise64.box\n<\/p>\n<p>ubuntu64 \u662f\u6211\u4eec\u7ed9\u8fd9\u4e2a box \u547d\u7684\u540d\u5b57\uff0c<code>~\/box\/precise64.box<\/code>&nbsp;\u662f box \u6240\u5728\u8def\u5f84<\/p>\n<p>4. \u521d\u59cb\u5316\u5f00\u53d1\u73af\u5883<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u5f00\u53d1\u76ee\u5f55\uff08\u6bd4\u5982\uff1a<code>~\/dev<\/code>\uff09\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5df2\u6709\u7684\u76ee\u5f55\uff0c\u5207\u6362\u5230\u5f00\u53d1\u76ee\u5f55\u91cc\uff0c\u7528&nbsp;&nbsp;ubuntu64&nbsp;\u955c\u50cf\u521d\u59cb\u5316\u5f53\u524d\u76ee\u5f55\u7684\u73af\u5883\uff1a<br \/>$ cd ~\/dev  # \u5207\u6362\u76ee\u5f55<br \/>$ vagrant init&nbsp;&nbsp;ubuntu64&nbsp;# \u521d\u59cb\u5316<br \/>\n<br \/>$ vagrant up  # \u542f\u52a8\u73af\u5883<\/p>\n<p>\u4f60\u4f1a\u770b\u5230\u7ec8\u7aef\u663e\u793a\u4e86\u542f\u52a8\u8fc7\u7a0b\uff0c\u542f\u52a8\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u7528 SSH \u767b\u5f55\u865a\u62df\u673a\u4e86\uff0c\u5269\u4e0b\u7684\u6b65\u9aa4\u5c31\u662f\u5728\u865a\u62df\u673a\u91cc\u914d\u7f6e\u4f60\u8981\u8fd0\u884c\u7684\u5404\u79cd\u73af\u5883\u548c\u53c2\u6570\u4e86\u3002<br \/>$ vagrant ssh  # SSH \u767b\u5f55<br \/>$ cd \/vagrant  # \u5207\u6362\u5230\u5f00\u53d1\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u5bbf\u4e3b\u673a\u4e0a\u7684 `~\/dev`\n<\/p>\n<p><code>~\/dev<\/code>&nbsp;\u76ee\u5f55\u5bf9\u5e94\u865a\u62df\u673a\u4e2d\u7684\u76ee\u5f55\u662f&nbsp;<code>\/vagrant<\/code><\/p>\n<p>5. \u5176\u4ed6\u8bbe\u7f6e<\/p>\n<p>Vagrant \u521d\u59cb\u5316\u6210\u529f\u540e\uff0c\u4f1a\u5728\u521d\u59cb\u5316\u7684\u76ee\u5f55\u91cc\u751f\u6210\u4e00\u4e2a&nbsp;<code>Vagrantfile<\/code>&nbsp;\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u4e2a\u6027\u5316\u7684\u5b9a\u5236\u3002<\/p>\n<p>Vagrant \u9ed8\u8ba4\u662f\u4f7f\u7528\u7aef\u53e3\u6620\u5c04\u65b9\u5f0f\u5c06\u865a\u62df\u673a\u7684\u7aef\u53e3\u6620\u5c04\u672c\u5730\u4ece\u800c\u5b9e\u73b0\u7c7b\u4f3c&nbsp;<code>http:\/\/localhost:80<\/code>&nbsp;\u8fd9\u79cd\u8bbf\u95ee\u65b9\u5f0f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u8f83\u9ebb\u70e6\uff0c\u65b0\u5f00\u548c\u4fee\u6539\u7aef\u53e3\u7684\u65f6\u5019\u90fd\u5f97\u7f16\u8f91\u3002\u76f8\u6bd4\u8f83\u800c\u8a00\uff0chost-only \u6a21\u5f0f\u663e\u5f97\u65b9\u4fbf\u591a\u4e86\u3002\u6253\u5f00&nbsp;<code>Vagrantfile<\/code>\uff0c\u5c06\u4e0b\u9762\u8fd9\u884c\u7684\u6ce8\u91ca\u53bb\u6389\uff08\u79fb\u9664&nbsp;<code>#<\/code>\uff09\u5e76\u4fdd\u5b58\uff1a<br \/>config.vm.network :private_network, ip: &#8220;192.168.33.10&#8221;<\/p>\n<p>\u91cd\u542f\u865a\u62df\u673a\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u7528&nbsp;<code>192.168.33.10<\/code>&nbsp;\u8bbf\u95ee\u8fd9\u53f0\u673a\u5668\u4e86\uff0c\u4f60\u53ef\u4ee5\u628a IP \u6539\u6210\u5176\u4ed6\u5730\u5740\uff0c\u53ea\u8981\u4e0d\u4ea7\u751f\u51b2\u7a81\u5c31\u884c\u3002<\/p>\n<p>6. \u6253\u5305\u5206\u53d1<\/p>\n<p>\u5f53\u4f60\u914d\u7f6e\u597d\u5f00\u53d1\u73af\u5883\u540e\uff0c\u9000\u51fa\u5e76\u5173\u95ed\u865a\u62df\u673a\u3002\u5728\u7ec8\u7aef\u91cc\u5bf9\u5f00\u53d1\u73af\u5883\u8fdb\u884c\u6253\u5305\uff1a<br \/>$ vagrant package<br \/>\u6253\u5305\u5b8c\u6210\u540e\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u751f\u6210\u4e00\u4e2a&nbsp;<code>package.box<\/code>&nbsp;\u7684\u6587\u4ef6\uff0c\u5c06\u8fd9\u4e2a\u6587\u4ef6\u4f20\u7ed9\u5176\u4ed6\u7528\u6237\uff0c\u5176\u4ed6\u7528\u6237\u53ea\u8981\u6dfb\u52a0\u8fd9\u4e2a box \u5e76\u7528\u5176\u521d\u59cb\u5316\u81ea\u5df1\u7684\u5f00\u53d1\u76ee\u5f55\u5c31\u80fd\u5f97\u5230\u4e00\u4e2a\u4e00\u6a21\u4e00\u6837\u7684\u5f00\u53d1\u73af\u5883\u4e86\u3002<\/p>\n<p>7. \u5e38\u7528\u547d\u4ee4<br \/>$ vagrant init  # \u521d\u59cb\u5316<br \/>\n<br \/>$ vagrant up  # \u542f\u52a8\u865a\u62df\u673a<br \/>\n<br \/>$ vagrant halt  # \u5173\u95ed\u865a\u62df\u673a<br \/>\n<br \/>$ vagrant reload  # \u91cd\u542f\u865a\u62df\u673a<br \/>\n<br \/>$ vagrant ssh  # SSH \u81f3\u865a\u62df\u673a<br \/>\n<br \/>$ vagrant status  # \u67e5\u770b\u865a\u62df\u673a\u8fd0\u884c\u72b6\u6001<br \/>\n<br \/>$ vagrant destroy  # \u9500\u6bc1\u5f53\u524d\u865a\u62df\u673a\n<\/p>\n<p>\u66f4\u591a\u5185\u5bb9\u8bf7\u67e5\u9605\u5b98\u65b9\u6587\u6863&nbsp;<a rel=\"nofollow noopener noreferrer\" href=\"http:\/\/docs.vagrantup.com\/v2\/cli\/index.html\" target=\"_blank\">http:\/\/docs.vagrantup.com\/v2\/cli\/index.html<\/a><\/p>\n<p>8. \u6ce8\u610f\u4e8b\u9879<\/p>\n<p>\u4f7f\u7528 Apache\/Nginx \u65f6\u4f1a\u51fa\u73b0\u8bf8\u5982\u56fe\u7247\u4fee\u6539\u540e\u4f46\u9875\u9762\u5237\u65b0\u4ecd\u7136\u662f\u65e7\u6587\u4ef6\u7684\u60c5\u51b5\uff0c\u662f\u7531\u4e8e\u9759\u6001\u6587\u4ef6\u7f13\u5b58\u9020\u6210\u7684\u3002\u9700\u8981\u5bf9\u865a\u62df\u673a\u91cc\u7684 Apache\/Nginx \u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u4fee\u6539\uff1a<br \/># Apache \u914d\u7f6e\u6dfb\u52a0:<br \/>\n<br \/>EnableSendfile off\n<\/p>\n<p># Nginx \u914d\u7f6e\u6dfb\u52a0:<br \/>sendfile off;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vagrant&nbsp;\u662f\u4e00\u6b3e\u7528\u6765\u6784\u5efa\u865a\u62df\u5f00\u53d1\u73af\u5883\u7684\u5de5\u5177\uff0c\u975e\u5e38\u9002\u5408 php\/python\/ruby\/java [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-1037","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/1037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1037"}],"version-history":[{"count":0,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/1037\/revisions"}],"wp:attachment":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1037"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}