window上vagrant打造虚拟化平台

1.1准备工作:

    下载安装 VirtualBox :https://www.virtualbox.org/
     下载安装 Vagrant :   http://www.vagrantup.com/
     下载安装git bash :   https://git-scm.com/download/
    下载需要使用的 box :
    官方提供的范例:http://files.vagrantup.com/precise32.box
    还可以在 http://www.vagrantbox.es/ 这里下载更多不同系统甚至是已经配置好环境直接可以用的 box,虽然可以直接在Vagrant直接使用网址,由Vagrant自动下载安装,但是考虑到网络情况,还是建议自行先下载好。

1.2 系统环境

     window上安装git bash: 通过git bash 窗口来执行命令
    box镜像文件 : centos-6.6-x86_64.box
     Vagrant: 1.8 
    VirtualBox: 5.0

1.3 安装部署

1.3.1 挂载镜像的方式:

1.通过网络的形式下载以.box文件结尾的镜像文件. vagrant 命令支持.它会自动按照你给的地址下载

2.本地提前下载好box镜像文件,这样省去下载的过程,也可以直接加入vagarnt中使用

1.3.2 命令介绍

$ vagrant --help
Usage: vagrant [options] <command> [<args>]

-v, --version                   Print the version and exit.
    -h, --help                       Print this help.

Common commands:

     box             管理box的安装,添加,移除     
     connect            连接一个vagrant远程环境     
     destroy           停止并摧毁一个vagrant虚拟机
     global-status        导出用户的状态环境变量     
     halt             关机     
     help             帮助       
     init             初始化并自动创建一个Vagrantfile 文件     
     login            log in to HashiCorp‘s Atlas     
     package            打包一个vagrant虚拟机成一个box镜像     
     plugin            管理插件的安装卸载     
     port             列出端口的映射关系     
     powershell           通过powershell连接
     provision           vagrant虚拟机的信息 provisions the vagrant machine     push                deploys code in this environment to a configured destination     rdp                  通过window rdp 连接     reload              重启vagrant机器,重新加载Vagrantfile配置文件
      resume            恢复一个暂停的虚拟机
      share             share your Vagrant environment with anyone in the world
      snapshot            快照
     ssh                  通过ssh连接
     ssh-config             导出虚拟机ssh配置
     status                查看状态
     suspend               挂靠暂停一个虚拟机
     up                 启动虚拟机
     version               打印vagrant版本

$ vagrant box --help
Usage: vagrant box <subcommand> [<args>]

Available subcommands:

       add
     list
     outdated
     remove
     repackage
     update

1.3.3 本地下载好box镜像 vagrant add 导入镜像

自定义的名字centos6.6 随意写

[email protected] MINGW64 /e 
$ vagrant box list               
centos6.6 (virtualbox, 0)
[email protected] MINGW64 /e 
$ mkdir vagrantlinux          #新建目录,把他作为安装虚拟目录
[email protected] MINGW64 /e  
$ cd vagrantlinux/ 
$ vagrant init centos6.6         #执行完这个命令后,就会在当前目录说呢过成Vagrantfile文件
A `Vagrantfile` has been placed in this directory. You are nowready to `vagrant up` your first virtual environment! Please readthe comments in the Vagrantfile as well as documentation on`vagrantup.com` for more information on using Vagrant.

1.3.4 Vagrantfile文件

相当于虚拟机的配置文件,定义ip地址,分配多少内存,共享文件夹,执行命令等. 因此这个配置很重要,一些修改主要更改这个配置文件,暂时我只会这些,想要更多,请参照官方文档

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
  config.vm.box = "centos6.6"
  config.vm.box_check_update = false
  # config.vm.network "public_network"
  # config.vm.synced_folder "../data", "/vagrant_data"
        config.vm.define :nginx  do |nginx_config|
                nginx_config.vm.network "private_network", ip: "192.168.10.100"
                nginx_config.vm.provider "virtualbox" do |vb|
                nginx_config.vm.network "forwarded_port", guest: 80, host: 8080
                        vb.gui = false
                        vb.memory = "256"
                        vb.cpus = 2
                        vb.name = "my_vm01"
                end
        end
        config.vm.define :redis  do |redis_config|
                redis_config.vm.network "private_network", ip: "192.168.10.101"
                redis_config.vm.provider "virtualbox" do |vb|
                        vb.gui = false
                        vb.cpus = 2
                        vb.name = "my_vm02"
                        vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
                        vb.customize ["modifyvm", :id, "--memory", "256"]
                end
        end
config.vm.provision "shell", inline: <<-SHELL
    echo "192.168.50.10 my-vm01">>/etc/hosts
    echo "192.168.50.11 my-vm01">>/etc/hosts
  SHELL
end

1.3.5 启动  (只需要一个命令,俩个虚拟机正在后台,嗖嗖的建立,,,so easy)

$ vagrant up
Bringing machine ‘nginx‘ up with ‘virtualbox‘ provider...
Bringing machine ‘redis‘ up with ‘virtualbox‘ provider...
==> nginx: Importing base box ‘centos6.6‘...
==> nginx: Matching MAC address for NAT networking...
==> nginx: Setting the name of the VM: my_vm01
==> nginx: Clearing any previously set forwarded ports...
==> nginx: Clearing any previously set network interfaces...
==> nginx: Preparing network interfaces based on configuration...
    nginx: Adapter 1: nat
    nginx: Adapter 2: hostonly
==> nginx: Forwarding ports...
    nginx: 80 (guest) => 8080 (host) (adapter 1)
    nginx: 22 (guest) => 2222 (host) (adapter 1)
==> nginx: Running ‘pre-boot‘ VM customizations...
==> nginx: Booting VM...
==> nginx: Waiting for machine to boot. This may take a few minutes...
    nginx: SSH address: 127.0.0.1:2222
    nginx: SSH username: vagrant
    nginx: SSH auth method: private key
    nginx:
    nginx: Vagrant insecure key detected. Vagrant will automatically replace
    nginx: this with a newly generated keypair for better security.
    nginx:
    nginx: Inserting generated public key within guest...
    nginx: Removing insecure key from the guest if it‘s present...
    nginx: Key inserted! Disconnecting and reconnecting using new SSH key...
==> nginx: Machine booted and ready!
==> nginx: Checking for guest additions in VM...
    nginx: The guest additions on this VM do not match the installed version of
    nginx: VirtualBox! In most cases this is fine, but in rare cases it can
    nginx: prevent things such as shared folders from working properly. If you see
    nginx: shared folder errors, please make sure the guest additions within the
    nginx: virtual machine match the version of VirtualBox you have installed on
    nginx: your host and reload your VM.
    nginx:
    nginx: Guest Additions Version: 4.3.28
    nginx: VirtualBox Version: 5.0
==> nginx: Configuring and enabling network interfaces...
==> nginx: Mounting shared folders...
    nginx: /vagrant => E:/vagrantlinux
==> nginx: Running provisioner: shell...
    nginx: Running: inline script
==> redis: Importing base box ‘centos6.6‘...
==> redis: Matching MAC address for NAT networking...
==> redis: Setting the name of the VM: my_vm02
==> redis: Clearing any previously set forwarded ports...
==> redis: Fixed port collision for 22 => 2222. Now on port 2200.
==> redis: Clearing any previously set network interfaces...
==> redis: Preparing network interfaces based on configuration...
    redis: Adapter 1: nat
    redis: Adapter 2: hostonly
==> redis: Forwarding ports...
    redis: 22 (guest) => 2200 (host) (adapter 1)
==> redis: Running ‘pre-boot‘ VM customizations...
==> redis: Booting VM...
==> redis: Waiting for machine to boot. This may take a few minutes...
    redis: SSH address: 127.0.0.1:2200
    redis: SSH username: vagrant
    redis: SSH auth method: private key
    redis: Warning: Remote connection disconnect. Retrying...
    redis:
    redis: Vagrant insecure key detected. Vagrant will automatically replace
    redis: this with a newly generated keypair for better security.
    redis:
    redis: Inserting generated public key within guest...
    redis: Removing insecure key from the guest if it‘s present...
    redis: Key inserted! Disconnecting and reconnecting using new SSH key...
==> redis: Machine booted and ready!
==> redis: Checking for guest additions in VM...
    redis: The guest additions on this VM do not match the installed version of
    redis: VirtualBox! In most cases this is fine, but in rare cases it can
    redis: prevent things such as shared folders from working properly. If you see
    redis: shared folder errors, please make sure the guest additions within the
    redis: virtual machine match the version of VirtualBox you have installed on
    redis: your host and reload your VM.
    redis:
    redis: Guest Additions Version: 4.3.28
    redis: VirtualBox Version: 5.0
==> redis: Configuring and enabling network interfaces...
==> redis: Mounting shared folders...
    redis: /vagrant => E:/vagrantlinux
==> redis: Running provisioner: shell...
    redis: Running: inline script

1.4 查看状态

$ vagrant status
Current machine states:
nginx                       running (virtualbox)
redis                      running (virtualbox)

1.5 ssh连接

用户名: vagrant
密码: vagrant
[email protected] MINGW64 /e/vagrantlinux
$ vagrant ssh nginx
Last login: Sat May 30 12:27:44 2015 from 10.0.2.2Welcome to your Vagrant-built virtual machine.
[[email protected] ~]$ su - rootPasswort: 
[[email protected] ~]#

1.6 各个命令的查看

1.7 package打包虚拟机

大小查看

开了俩个虚拟机 占用资源也不是很大 ,还不错 .....

官方站点:http://docs.vagrantup.com/v2/

时间: 2024-08-10 00:25:27

window上vagrant打造虚拟化平台的相关文章

在 CentOS 7 上搭建 KVM 虚拟化平台

KVM 简介 Kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,自Linux 2.6.20之后集成在Linux的各个主要发行版本中.它使用Linux自身的调度器进行管理,所以相对于Xen,其核心源码很少.KVM目前已成为学术界的主流VMM之一. KVM的虚拟化需要硬件支持(如IntelVT技术或者AMDV技术).是基于硬件的完全虚拟化.而Xen早期则是基于软件模拟的Para-Virtualization,新版本则是基于硬件支持的完全虚拟化.但Xen本身有

CentOS7上部署KVM虚拟化平台

什么是虚拟化 虚拟化就是把硬件资源从物理方式转变为逻辑方式,打破原有物理结构,使用户可以灵活管理这些资源,并且允许1台物理机上同时运行多个操作系统,以实现资源利用率最大化和灵活管理的一项技术. 虚拟化的优势 1:减少服务器的数量,降低硬件采购成本.2:资源利用率最大化3:降低机房空间.散热.用电消耗成本.4:硬件资源可动态调整,提高企业IT业务灵活性.5:高可用性6:在不中断服务的情况下进行物理硬件调整.7:降低管理成本.8:具备更高效的灾备能力. ? 操作步骤 在虚拟机里添加一个40G的新磁盘

在CentOS7系统上部署KVM虚拟化平台

虚拟化简介:虚拟化就是把硬件资源从物理方式转变为逻辑方式,打破原有物理结构,使用户可以灵活管理这些资源,并且允许1台物理机上同时运行多个操作系统,以实现资源利用率最大化和灵活管理的一项技术. 半虚拟架构 ---xen--- Linux5.0 全虚拟架构 --- KVM---Linux6.0 容器的云时代--- docker 虚拟化的优势: 1.减少服务器数量,降低硬件采购成本. 2.资源利用率最大化. 3.降低机房空间,散热.用电消耗的成本. 4.硬件资源可动态调整,提高企业IT业务灵活性. 5

私有云计算保密技术谁家靠谱?云宏CNware?虚拟化平台安全体系设计

10月31日,2018年保密技术交流大会暨产品博览会在青岛隆重开幕.本次信息安全保密科技行业盛会,较往届专业性更强.规模更大,云集了国家有关主管部门领导.专家学者.优秀企业代表共襄盛会.云宏携高安全虚拟化平台CNware?参加本次大会,获得观展领导及专家的一致好评. CNware?高安全虚拟化平台体系 CNware?安全防护体系从物理机安全.虚拟机系统安全.数据安全.网络安全.管理安全等多模块进行安全性设计,搭载的安全核心技术包括虚拟化层防DDoS防御.虚拟防火墙.数据加密.完整性校验.三员管理

Vagrant - 轻量级虚拟化工具简介

深入讲解视频可登陆:https://ke.qq.com/course/1405491 或腾讯课堂搜索:“诗泽园”,找到对应课程 讨论QQ群:44509570(入群请注明来源) 问题描述 1.虚拟化工具学习成本高 2.环境无法直接共享 3.虚拟化平台不统一 4.无法快速保存.还原某版本测试环境 解决方案:Vagrant 1.可以很方便的就建立起来一个虚拟环境 2.可以很快速的就把某版本的测试环境还原出来 3.可配置.轻量级.便携式 4.可共享,降低了开发者搭建环境的时间,提高了生产力 5.解决了“

关于Windows高DPI的一些简单总结(Window上一般默认是96 dpi 作为100% 的缩放比率)

我们知道,关于高DPI的支持, Windows XP时代就开始有了, 那时关于高DPI的支持比较简单, 但是从Vista/Win7 到现在Win8 /Win8.1, Windows关于高DPI的支持已经发生了很大的变化, 下面我们依次简单介绍下. 如果说以前XP时代我们还有理由不关注高DPI,  那么在移动设备时代和大显示器的高分辨率时代, 我们就没有理由不关注高DPI了, 比如Surface Pro的分辨率是1920x1080, 这种情况下如果系统我们不设置高DPI, 基本上就没法触摸和操作了

华为FusionCompute虚拟化平台升级操作文档

华为FusionCompute虚拟化平台升级操作文档 一.问题分析与解决思路   问题描述:在一段时间内,FC平台中的多台CNA主机偶发性自动重启,随即导致主机中部署的虚拟机自动重启,严重影响线上业务. 解决方案:经研究,基本上排除了是服务器硬件问题导致的可能性,怀疑是FC虚拟化平台的问题.于是,收集了自动重启主机中的日志,提供给华为工程师分析,得出以下结论. [日志收集方法] (1)使用putty工具登录虚拟机所在的主机(以"gandalf"用户,通过管理IP地址登录,默认密码为[e

搭建红帽虚拟化平台RHEV——主机host的安装

搭建红帽虚拟化平台RHEV之主机host安装:如何给予rhel安装host主机,详情见下文: // 操作系统:RHEV-H FOR Red Hat Enterprise Linux Host(v.6.5 x86_64) 安装3.3版本的rhev必须安装6.5以上版本的操作系统软件 #安装官网下载的RHEL6.5.x86_64 DVD ISO:rhel-server-6.5-x86_64-dvd.iso Group install:Virtualization Host #关闭防火墙IPTABLE

KVM虚拟化平台部署及管理

前言 KVM即Kernel Virtual Machine,最初是由以色列公司Qumranet开发.2007年2月被导入Linux 2.6.20核心中,成为内核源代码的一部分.2008年9月4日,Redhat收购了Qumranet,至此Redhat拥有了自己的虚拟化解决方案,之后便舍弃Xen开始全面扶持KVM,从RHEL6开始KVM便被默认内置于内核中.本文介绍KVM虚拟化平台部署及管理. KVM简介 KVM特点 KVM必须在具备Intel VT或AMD-V功能的x86平台上运行.KVM包含一个