内容简介:Vagantfile里加入这段:Vagantfile里加入这段:可以通过增加swap的方式增加虚机的内存,以免耗尽主机的内存,下面这段代码就是刚这件事的:
-
vagrant-cachier
这玩意在VM下载包的时候(agt,yum,etc.)可以缓存,如三台centOS的VM只需下载包一次。安装:
vagrant plugin install vagrant-cachier
Vagantfile里加入这段:
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
-
vagrant-hostsupdater
VM和主机里的hosts都会进行更新,这样VM和主机里的都可以通过hostname通讯。安装:
vagrant plugin install vagrant-hostmanager
Vagantfile里加入这段:
if Vagrant.has_plugin?("vagrant-hostmanager")
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
end
vagrant file
ENV["LC_ALL"] = "en_US.UTF-8"
Vagrant.configure(2) do |config|
# 停止启动时的更新检查
config.vm.box_check_update = false
# 指定虚机的OS
config.vm.box = "centos/7"
# 控制VM的内存和CPU
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 1
end
# 和主机共享目录
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
config.vm.synced_folder ".", "/vagrant", mount_options: ["dmode=777,fmode=777"]
else
config.vm.synced_folder ".", "/vagrant"
end
# 循环多个虚机
(1..1).each do |i|
config.vm.define "vm#{i}" do |node|
node.vm.hostname = "vm1"
node.vm.network "private_network", ip: "10.10.10.#{i}0"
node.vm.provision "shell",
inline: "echo hello from node vm#{i}"
end
end
swap
可以通过增加swap的方式增加虚机的内存,以免耗尽主机的内存,下面这段代码就是刚这件事的:
#!/bin/sh #create the swap space 1GB echo "Creating 1GB swap space in /swapfile..." fallocate -l 1G /swapfile ls -lh /swapfile #secure the swapfile echo "Securing the swapfile..." chown root:root /swapfile chmod 0600 /swapfile ls -lh /swapfile #turn the swapfile on echo "Turning the swapfile on..." mkswap /swapfile swapon /swapfile echo "Verifying..." swapon -s grep -i --color swap /proc/meminfo echo "Adding swap entry to /etc/fstab" echo "\n/swapfile none swap sw 0 0" >> /etc/fstab echo "Result: " cat /etc/fstab echo " ****** We are done !!! ********"
以上所述就是小编给大家介绍的《Vagrant小技巧》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Four
Scott Galloway / Portfolio / 2017-10-3 / USD 28.00
NEW YORK TIMES BESTSELLER USA TODAY BESTSELLER Amazon, Apple, Facebook, and Google are the four most influential companies on the planet. Just about everyone thinks they know how they got there.......一起来看看 《The Four》 这本书的介绍吧!