Vagrant小技巧

栏目: 服务器 · 发布时间: 7年前

内容简介: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小技巧》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

持续交付

持续交付

Jez Humble、David Farley / 乔梁 / 人民邮电出版社 / 2011-10 / 89.00元

Jez Humble编著的《持续交付(发布可靠软件的系统方法)》讲述如何实现更快、更可靠、低成本的自动化软件交付,描述了如何通过增加反馈,并改进开发人员、测试人员、运维人员和项目经理之间的协作来达到这个目标。《持续交付(发布可靠软件的系统方法)》由三部分组成。第一部分阐述了持续交付背后的一些原则,以及支持这些原则的实践。第二部分是本书的核心,全面讲述了部署流水线。第三部分围绕部署流水线的投入产出讨......一起来看看 《持续交付》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

html转js在线工具
html转js在线工具

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具