{"id":6650,"date":"2018-07-27T09:46:40","date_gmt":"2018-07-27T01:46:40","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=6650"},"modified":"2019-06-12T10:33:55","modified_gmt":"2019-06-12T02:33:55","slug":"%e6%88%91%e7%9a%84vagrantfile","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/6650.html","title":{"rendered":"\u6211\u7684Vagrantfile"},"content":{"rendered":"<p>\u7528\u4e86 Vagrant \u6279\u91cf\u521b\u5efa\u5f88\u591a\u4e2a\u865a\u62df\u673a\uff0c\u7528\u4e8e salt \u4f7f\u7528\u5b66\u4e60\uff0cCassandra\u3001Spark \u96c6\u7fa4\u642d\u5efa\u6d4b\u8bd5\u7b49\u3002<\/p>\n<p>Vagrantfile \u5185\u5bb9\u5982\u4e0b<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\n# -*- mode: ruby -*-\r\n# vi: set ft=ruby :\r\n\r\n# Vagrantfile API\/syntax version. Don't touch unless you know what you're doing!\r\nVAGRANTFILE_API_VERSION = &quot;2&quot;\r\n\r\ndomain = 'example'\r\ndef_network = '172.31.0'\r\ndef_ram = '1536'\r\nos_ubuntu = &quot;ubuntu\/trusty64&quot;\r\nos_centos6 = &quot;bento\/centos-6.7&quot;\r\nos_centos7 = &quot;bento\/centos-7.2&quot;\r\n\r\nnodes = &#x5B;\r\n  { :hostname =&gt; 'master', :ip =&gt; def_network+'.11', :box =&gt; os_centos6, :ports =&gt; { 22 =&gt; 3211 } },\r\n  { :hostname =&gt; 'minion1', :ip =&gt; def_network+'.21', :box =&gt; os_centos6, :ports =&gt; { 22 =&gt; 3221 } },\r\n  { :hostname =&gt; 'minion2', :ip =&gt; def_network+'.22', :box =&gt; os_centos6, :ports =&gt; { 22 =&gt; 3222 } },\r\n  { :hostname =&gt; 'minion3', :ip =&gt; def_network+'.23', :box =&gt; os_ubuntu, :ports =&gt; { 22 =&gt; 3223 } },\r\n  { :hostname =&gt; 'minion4', :ip =&gt; def_network+'.24', :box =&gt; os_ubuntu, :ports =&gt; { 22 =&gt; 3224 } },\r\n\r\n  { :hostname =&gt; 'centos7', :ip =&gt; def_network+'.31', :box =&gt; os_centos7, :ram =&gt; 2048, :ports =&gt; { 22 =&gt; 3231, 80 =&gt; 80 } },\r\n  { :hostname =&gt; 'ubuntu16', :ip =&gt; def_network+'.32', :box =&gt; os_ubuntu, :ram =&gt; 4096, :ports =&gt; { 22 =&gt; 3232 } },\r\n  { :hostname =&gt; 'centos6', :ip =&gt; def_network+'.33', :box =&gt; os_centos6, :ram =&gt; 2048, :ports =&gt; { 22 =&gt; 3233 } },\r\n]\r\n\r\nVagrant.configure(VAGRANTFILE_API_VERSION) do |config|\r\n  nodes.each do |node|\r\n    config.vm.define node&#x5B;:hostname] do |node_config|\r\n      node_config.vm.provider 'virtualbox' do |vb|\r\n        vb.gui = false\r\n        vb.name = node&#x5B;:hostname]\r\n        vb.memory = node&#x5B;:ram] ? node&#x5B;:ram] : def_ram;\r\n        vb.customize &#x5B;&quot;setextradata&quot;, :id, &quot;VBoxInternal2\/SharedFoldersEnableSymlinksCreate\/&quot;+node&#x5B;:hostname], &quot;1&quot;]\r\n      end\r\n      node_config.ssh.insert_key = false\r\n      node_config.ssh.password = &quot;vagrant&quot;\r\n      node_config.vm.box = node&#x5B;:box]\r\n      node_config.vm.hostname = node&#x5B;:hostname] + '.' + domain\r\n      node_config.vm.network 'private_network', ip: node&#x5B;:ip], virtualbox__intnet: 'salt'\r\n      node_config.vm.synced_folder 'D:\\projects', '\/home\/vagrant\/projects', mount_options: &#x5B;&quot;dmode=755,fmode=755&quot;] #, disabled: true\r\n      if node.key?(:ports)\r\n        config.vm.network &quot;forwarded_port&quot;, guest: 22, host: 2222, id: &quot;ssh&quot;, disabled: &quot;true&quot; # \u7981\u7528\u9ed8\u8ba4\u7684ssh\u8f6c\u53d1\uff0c\u518d\u6dfb\u52a0\u81ea\u5b9a\u4e49\u8f6c\u53d1\r\n        node&#x5B;:ports].each do | guestport, hostport |\r\n          node_config.vm.network 'forwarded_port', guest: guestport, host: hostport\r\n        end\r\n      end\r\n    end\r\n  end\r\nend\r\n<\/pre>\n<p>\u9047\u5230\u7684\u95ee\u9898\uff0c\u4e3b\u8981\u662f node_config.vm.synced_folder \u8fd9\u4e2a\u6302\u8f7dhost\u4e3b\u76ee\u5f55\u65f6\u5019\uff0c\u6709\u65f6\u5019\u51fa\u73b0 GuestAdditions \u7248\u672c\u4e0d\u76f8\u540c\u7684\u9519\u8bef\uff0c\u7f51\u4e0a\u8bf4\u5b89\u88c5 vagrant \u63d2\u4ef6\u5c31\u53ef\u4ee5\u89e3\u51b3<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvagrant plugin install vagrant-winnfsd\r\nvagrant plugin install vagrant-vbguest\r\n<\/pre>\n<p>\u5982\u679chost\u673a\u5668\u662fwindows\u64cd\u4f5c\u7cfb\u7edf\uff0c\u800c\u865a\u62df\u673a\u662fLinux\uff0c\u90a3\u4e48\u5171\u4eabwindows\u91cc\u9762\u7684\u76ee\u5f55\u6302\u8f7d\u5230Linux\u4e2d\uff0c\u90a3\u5728Linux\u91cc\u9762\u4e0d\u53ef\u4ee5\u521b\u5efa\u8f6f\u94fe\u63a5\uff0c\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u4e2a\u914d\u7f6e\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvb.customize &#x5B;&quot;setextradata&quot;, :id, &quot;VBoxInternal2\/SharedFoldersEnableSymlinksCreate\/&quot;+node&#x5B;:hostname], &quot;1&quot;]\r\n<\/pre>\n<p>\u6216\u8005\uff0c\u5728virtualbox\u5b89\u88c5\u76ee\u5f55\u4e2d\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nVBoxManage setextradata YOURVMNAME VBoxInternal2\/SharedFoldersEnableSymlinksCreate\/YOURSHAREFOLDERNAME 1  \r\n<\/pre>\n<p>\u5176\u4e2d\uff0cYOURVMNAME\u4e3a\u865a\u62df\u673a\u4e2dlinux\u7cfb\u7edf\u7684\u540d\u79f0\uff0cYOURSHAREFOLDERNAME \u4e3a\u5171\u4eab\u7684\u76ee\u5f55\u540d\u79f0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u4e86 Vagrant \u6279\u91cf\u521b\u5efa\u5f88\u591a\u4e2a\u865a\u62df\u673a\uff0c\u7528\u4e8e salt \u4f7f\u7528\u5b66\u4e60\uff0cCassandra\u3001Spark \u96c6\u7fa4\u642d\u5efa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-6650","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=6650"}],"version-history":[{"count":10,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6650\/revisions"}],"predecessor-version":[{"id":6988,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6650\/revisions\/6988"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=6650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=6650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=6650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}