{"id":27846,"date":"2024-11-24T20:05:23","date_gmt":"2024-11-24T12:05:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=27846"},"modified":"2024-11-24T20:05:23","modified_gmt":"2024-11-24T12:05:23","slug":"vagrant%e7%9a%84vagrantfile%e7%9a%84%e9%85%8d%e7%bd%ae%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27846\/","title":{"rendered":"vagrant\u7684vagrantfile\u7684\u914d\u7f6e\u8bf4\u660e"},"content":{"rendered":"<p>\u5b98\u65b9\u6587\u6863\uff1ahttps:\/\/www.vagrantup.com\/docs\/index.html<\/p>\n<p><strong>Vagrant.configure(\u201c2\u2033) do |config|<\/strong><br \/>\n<strong>config.vm.box = \u201ccentos6\u2033<\/strong><\/p>\n<p>#\u6307\u5b9avm\u7684hostname\uff0c\u4f1a\u8986\u76d6vm\u4e2d\/etc\/hostsname\u4e2d\u7684\u8bbe\u7f6e\u3002<br \/>\n<strong>config.vm.hostname = \u201clocalhost\u201d<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong># config.vm.box_check_update = false<\/strong><\/p>\n<p># vagrant\u7684\u7f51\u7edc\u8fde\u63a5\u65b9\u5f0f\u6709\u4e09\u79cd\uff1a<br \/>\n# NAT : \u7f3a\u7701\u521b\u5efa\uff0c\u7528\u4e8e\u8ba9vm\u53ef\u4ee5\u901a\u8fc7host\u8f6c\u53d1\u8bbf\u95ee\u5c40\u57df\u7f51\u751a\u81f3\u4e92\u8054\u7f51\u3002<br \/>\n# host-only : \u53ea\u6709\u4e3b\u673a\u53ef\u4ee5\u8bbf\u95eevm\uff0c\u5176\u4ed6\u673a\u5668\u65e0\u6cd5\u8bbf\u95ee\u5b83\u3002<br \/>\n# bridge : \u6b64\u6a21\u5f0f\u4e0bvm\u5c31\u50cf\u5c40\u57df\u7f51\u4e2d\u7684\u4e00\u53f0\u72ec\u7acb\u7684\u673a\u5668\uff0c\u53ef\u4ee5\u88ab\u5176\u4ed6\u673a\u5668\u8bbf\u95ee\u3002<\/p>\n<p># \u7f3a\u7701\u521b\u5efa\uff0c\u7528\u4e8e\u8ba9vm\u53ef\u4ee5\u901a\u8fc7host\u8f6c\u53d1\u8bbf\u95ee\u5c40\u57df\u7f51\u751a\u81f3\u4e92\u8054\u7f51<br \/>\n# vagrant\u9ed8\u8ba4\u7684\u7aef\u53e3\u7f51\u7edc\u65b9\u5f0f,\u7aef\u53e3\u6620\u5c04,\u901a\u8fc7\u5bbf\u4e3b\u673a8080\u7aef\u53e3,\u8bbf\u95ee\u865a\u62df\u4e3b\u673a80\u7aef\u53e3<br \/>\n<strong># config.vm.network \u201cforwarded_port\u201d, guest: 80, host: 8080<\/strong><br \/>\n# guest\u548chost\u662f\u5fc5\u987b\u7684\uff0c\u8fd8\u6709\u51e0\u4e2a\u53ef\u9009\u5c5e\u6027\uff1a<br \/>\n# guest_ip\uff1a\u5b57\u7b26\u4e32\uff0cvm\u6307\u5b9a\u7ed1\u5b9a\u7684Ip\uff0c\u7f3a\u7701\u4e3a0.0.0.0<br \/>\n# host_ip\uff1a\u5b57\u7b26\u4e32\uff0chost\u6307\u5b9a\u7ed1\u5b9a\u7684Ip\uff0c\u7f3a\u7701\u4e3a0.0.0.0<br \/>\n# protocol\uff1a\u5b57\u7b26\u4e32\uff0c\u53ef\u9009TCP\u6216UDP\uff0c\u7f3a\u7701\u4e3aTCP<\/p>\n<p># \u53ea\u6709\u4e3b\u673a\u53ef\u4ee5\u8bbf\u95eevm\uff0c\u5176\u4ed6\u673a\u5668\u65e0\u6cd5\u8bbf\u95ee\u5b83<br \/>\n# host-only\u7684\u65b9\u5f0f,\u5b8c\u5168\u81ea\u5df1\u63a7\u5236ip,\u4e5f\u53ef\u4ee5\u91c7\u7528DHCP\u7684\u65b9\u5f0f<br \/>\n<strong>config.vm.network \u201cprivate_network\u201d, ip: \u201c192.168.80.120\u201d<\/strong><br \/>\n#config.vm.network \u201cprivate_network\u201d, type: \u201cdhcp\u201d<\/p>\n<p># \u6865\u63a5\u65b9\u5f0f\u8fde\u63a5,DHCP\u5206\u914dIP,\u4e5f\u53ef\u4ee5\u6307\u5b9a\u56fa\u5b9aIP,\u6307\u5b9a\u7f51\u5361<br \/>\n# \u6b64\u6a21\u5f0f\u4e0bvm\u5c31\u50cf\u5c40\u57df\u7f51\u4e2d\u7684\u4e00\u53f0\u72ec\u7acb\u7684\u673a\u5668\uff0c\u53ef\u4ee5\u88ab\u5176\u4ed6\u673a\u5668\u8bbf\u95ee<br \/>\n<strong># config.vm.network \u201cpublic_network\u201d<\/strong><br \/>\n# config.vm.network \u201cpublic_network\u201d, ip: \u201c192.168.0.17\u201d<br \/>\n# #config.vm.network \u201cpublic_network\u201d, bridge: \u201cen1: Wi-Fi (AirPort)\u201d<\/p>\n<p># \u5bbf\u4e3b\u673a\u548c\u865a\u62df\u673a\u7684\u5171\u4eab\u76ee\u5f55,\u592a\u65b9\u4fbf\u4e86<br \/>\n# \u9ed8\u8ba4,vagrant\u4f1a\u628a\u5de5\u4f5c\u76ee\u5f55\u6620\u5c04\u5230vm\u7684\/vagrant\u76ee\u5f55\uff0c\u5982\u679c\u9700\u8981\u589e\u52a0\u66f4\u591a\u540c\u6b65\u6587\u4ef6\u5939\uff0c<br \/>\n# \u4f7f\u7528\u4e0a\u9762\u7684\u914d\u7f6e\uff0c\u7b2c\u4e00\u4e2a\u6587\u4ef6\u5939\u4e3ahost\u4e3b\u673a\u7684\u76ee\u5f55\uff0c\u7b2c\u4e8c\u4e2a\u6587\u4ef6\u5939\u4e3avm\u4e2d\u7684\u76ee\u5f55\u3002<br \/>\n<strong>config.vm.synced_folder \u201c\/data\/vagrant\/www\u201d, \u201c\/data\/www\u201d<\/strong><\/p>\n<p># vm provider\u901a\u7528\u914d\u7f6e<br \/>\n# \u865a\u673a\u5bb9\u5668\u63d0\u4f9b\u8005\u914d\u7f6e\uff0c\u5bf9\u4e8e\u4e0d\u540c\u7684provider\uff0c\u7279\u6709\u7684\u4e00\u4e9b\u914d\u7f6e\uff0c<br \/>\n# \u6b64\u5904\u914d\u7f6e\u4fe1\u606f\u662f\u9488\u5bf9virtualbox\u5b9a\u4e49\u4e00\u4e2a\u63d0\u4f9b\u8005\uff0c\u547d\u540d\u4e3avb\uff0c\u8ddf\u524d\u9762\u4e00\u6837\uff0c<br \/>\n# \u8fd9\u4e2a\u540d\u5b57\u968f\u610f\u53d6\uff0c\u53ea\u8981\u8282\u70b9\u5185\u90e8\u8c03\u7528\u4e00\u81f4\u5373\u53ef\u3002<br \/>\n<strong>config.vm.provider \u201cvirtualbox\u201d do |vb|<\/strong><br \/>\n# vagrant up\u542f\u52a8\u65f6\uff0c\u662f\u5426\u81ea\u52a8\u6253\u5f00virtual box\u7684\u7a97\u53e3\uff0c\u7f3a\u7701\u4e3afalse<br \/>\n<strong># vb.gui = true<\/strong><\/p>\n<p>#\u6307\u5b9avm\u5185\u5b58\uff0c\u5355\u4f4d\u4e3aMB<br \/>\n<strong>vb.memory = \u201c1024\u201d<\/strong><\/p>\n<p>#\u8bbe\u7f6eCPU\u4e2a\u6570<br \/>\n<strong>vb.cpus = 1<\/strong><\/p>\n<p>#\u6307\u5b9avm-name\uff0c\u4e5f\u5c31\u662fvirtualbox\u7ba1\u7406\u63a7\u5236\u53f0\u4e2d\u7684\u865a\u673a\u540d\u79f0\uff0c\u6216\u8005\u8bf4\u662fvirtual box\u5de5\u4f5c\u76ee\u5f55\u7684\u540d\u5b57<br \/>\n#\u9ed8\u8ba4\u662f\u968f\u673a\u751f\u6210\u7684<br \/>\n<strong>#vb.name = \u201ccentos6\u2033<\/strong><br \/>\nend<\/p>\n<p># \u9664\u4e86\u4ee5\u4e0a\u7684\u901a\u7528\u914d\u7f6e\u5916,\u9488\u5bf9\u4e0d\u540c\u7684 provider,\u6709\u4e0d\u540c\u7684\u8bbe\u7f6e,\u5305\u62ec\u5b9a\u4e49\u663e\u5b58,\u589e\u52a0\u5149\u9a71\u7b49<br \/>\n# \u8be6\u7ec6\u7684\u529f\u80fd\u63a5\u53e3\u548c\u4f7f\u7528\u8bf4\u660e\uff0c\u53ef\u4ee5\u53c2\u8003virtualbox\u5b98\u65b9\u6587\u6863\u3002<\/p>\n<p># \u6307\u5b9abox\u955c\u50cfpush\u53d1\u5e03\u7684\u5730\u5740\uff0c\u4f9bbox\u955c\u50cf\u7ba1\u7406\u8005\u4f7f\u7528\u3002\u666e\u901a\u4f7f\u7528\u8005\u4e0d\u9700\u5173\u5fc3\u3002<br \/>\n<strong># config.push.define \u201catlas\u201d do |push|<\/strong><br \/>\n<strong># push.app = \u201cYOUR_ATLAS_USERNAME\/YOUR_APPLICATION_NAME\u201d<\/strong><br \/>\n<strong># end<\/strong><\/p>\n<p>#\u542f\u52a8\u540e\u6267\u884cshell\u4ee3\u7801,\u4e5f\u53ef\u4ee5\u91c7\u7528shell\u811a\u672c\u7684\u65b9\u5f0f<br \/>\n<strong># config.vm.provision \u201cshell\u201d, inline: &lt;&lt;-SHELL<\/strong><br \/>\n<strong># apt-get update<\/strong><br \/>\n<strong># apt-get install -y apache2<\/strong><br \/>\n<strong># SHELL<\/strong><br \/>\n<strong>#config.vm.provision :shell, :path =&gt; \u201cboot.sh\u201d<\/strong><\/p>\n<p><strong>end<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u65b9\u6587\u6863\uff1ahttps:\/\/www.vagrantup.com\/docs\/index.html Vagrant.configure(\u201c2\u2033) do |config| config.vm.box = \u201ccentos6\u2033 #\u6307\u5b9avm\u7684hostname\uff0c\u4f1a\u8986\u76d6vm\u4e2d\/etc\/hostsname\u4e2d\u7684\u8bbe\u7f6e\u3002 config.vm.hostname = \u201clocalhost\u201d &nbsp; # config.vm.box_check_update = false # vagrant\u7684\u7f51\u7edc\u8fde\u63a5\u65b9\u5f0f\u6709\u4e09\u79cd\uff1a # NAT : \u7f3a\u7701\u521b\u5efa\uff0c\u7528\u4e8e\u8ba9vm\u53ef\u4ee5\u901a\u8fc7host\u8f6c\u53d1\u8bbf\u95ee\u5c40\u57df\u7f51\u751a\u81f3\u4e92\u8054\u7f51\u3002 # host-only : \u53ea\u6709\u4e3b\u673a\u53ef\u4ee5\u8bbf\u95eevm\uff0c\u5176\u4ed6\u673a\u5668\u65e0\u6cd5\u8bbf\u95ee\u5b83\u3002 # bridge : \u6b64\u6a21\u5f0f\u4e0bvm\u5c31\u50cf\u5c40\u57df\u7f51\u4e2d\u7684\u4e00\u53f0\u72ec\u7acb\u7684\u673a\u5668\uff0c\u53ef\u4ee5\u88ab\u5176\u4ed6\u673a\u5668\u8bbf\u95ee\u3002 # \u7f3a\u7701\u521b\u5efa\uff0c\u7528\u4e8e\u8ba9vm\u53ef\u4ee5\u901a\u8fc7host\u8f6c\u53d1\u8bbf\u95ee\u5c40\u57df\u7f51\u751a\u81f3\u4e92\u8054\u7f51 # vagrant\u9ed8\u8ba4\u7684\u7aef\u53e3\u7f51\u7edc\u65b9\u5f0f,\u7aef\u53e3\u6620\u5c04,\u901a\u8fc7\u5bbf\u4e3b\u673a8080\u7aef\u53e3,\u8bbf\u95ee\u865a\u62df\u4e3b\u673a80\u7aef\u53e3 # config.vm.network \u201cforwarded_port\u201d, guest: 80, host: 8080 # guest\u548chost\u662f\u5fc5\u987b\u7684\uff0c\u8fd8\u6709\u51e0\u4e2a\u53ef\u9009\u5c5e\u6027\uff1a # guest_ip\uff1a\u5b57\u7b26\u4e32\uff0cvm\u6307\u5b9a\u7ed1\u5b9a\u7684Ip\uff0c\u7f3a\u7701\u4e3a0.0.0.0 # host_ip\uff1a\u5b57\u7b26\u4e32\uff0chost\u6307\u5b9a\u7ed1\u5b9a\u7684Ip\uff0c\u7f3a\u7701\u4e3a0.0.0.0 # protocol\uff1a\u5b57\u7b26\u4e32\uff0c\u53ef\u9009TCP\u6216UDP\uff0c\u7f3a\u7701\u4e3aTCP # \u53ea\u6709\u4e3b\u673a\u53ef\u4ee5\u8bbf\u95eevm\uff0c\u5176\u4ed6\u673a\u5668\u65e0\u6cd5\u8bbf\u95ee\u5b83 # host-only\u7684\u65b9\u5f0f,\u5b8c\u5168\u81ea\u5df1\u63a7\u5236ip,\u4e5f\u53ef\u4ee5\u91c7\u7528DHCP\u7684\u65b9\u5f0f config.vm.network \u201cprivate_network\u201d, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-27846","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27846"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27846\/revisions"}],"predecessor-version":[{"id":27852,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27846\/revisions\/27852"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}