windows 下使用vargant 搭建虚拟机服务
使用vagrant
下载
vagrant[https://www.vagrantup.com/downloads.html]
下载管理工具VirtualBox[https://www.virtualbox.org/wiki/Downloads]
分别安装这两个
安装好后,可能还需要你安装一些组件,按照提示进行安装即可
vagrant plugin repair
vagrant plugin expunge --reinstall
在本地找一个新建一个文件夹,没有路径要求[C:\APP\HashiCorp\vm1]
在文件夹目录下cmd
第一次的第一个虚拟机需要执行镜像下载
什么版本,可以自己找
ubuntu
vagrant box add https://mirrors.huaweicloud.com/ubuntu-cloud-images/bionic/20200107/bionic-server-cloudimg-amd64-vagrant.box --name ubuntuvm4/bionic64
或者加载本地已经下载好的
vagrant box add C:\APPS\OnlyOne\mega\开发工具\HADOOP\cloud\ubuntu_cloud\bionic-server-cloudimg-amd64-vagrant.box --name ubuntu/bionic64
centos
vagrant box add https://mirrors.nju.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box --name centos7/bionic64
源链接可能会失效,如果失效,自己再找,一般就是华为源,清华源,阿里源
华为源,https://mirrors.huaweicloud.com/
清华源,https://mirrors.tuna.tsinghua.edu.cn/
南京大学源,https://mirrors.nju.edu.cn/
阿里源,http://mirrors.aliyun.com/
找不到就在里面疯狂找
初始化,ubuntu/bionic64为你上方设置的title
vagrant init  ubuntu/bionic64
这时会在对应文件夹下生成一个Vagrantfile的文件。
默认不配置,是单个虚拟机
配置多机的设置
servers = {
    :hadoop1 => '192.168.2.220',
    :hadoop2 => '192.168.2.221',
    :hadoop3 => '192.168.2.222',
    :hadoop4 => '192.168.2.223'
} 
第一种批量循环创建,分配的资源一样
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.box_check_update = false
  servers.each do |server_name, server_ip|
    config.vm.define server_name do |server_config|
	  server_config.vm.hostname = "#{server_name.to_s}"
	  server_config.vm.network :private_network, ip: server_ip
	  server_config.vm.provider "virtualbox" do |vb|
	    vb.name = server_name.to_s
		  vb.memory = "1024"
		  vb.cpus = 1
	    end
    end
  end
end
第二种 为每个主机单独作配置
Vagrant.configure("2") do |config|
  config.vm.define "vagrant1" do |vb|
      config.vm.provider "virtualbox" do |v|
      v.memory = 512
      v.cpus = 1
    end
  vb.vm.host_name = "vagrant1"
  vb.vm.network :public_network, ip: "10.0.2.16"
  vb.vm.box = "centos72"
  end
  config.vm.define "vagrant2" do |vb|
    config.vm.provider "virtualbox" do |v|
      v.memory = 512
      v.cpus = 1
    end
  vb.vm.host_name = "vagrant2"
  vb.vm.network :public_network, ip: "10.0.2.16"
  vb.vm.box = "centos72"
  end
  config.vm.define "vagrant3" do |vb|
    config.vm.provider "virtualbox" do |v|
      v.memory = 512
      v.cpus = 1
    end
  vb.vm.host_name = "vagrant3"
  vb.vm.network :public_network, ip: "10.0.2.16"
  vb.vm.box = "centos72"
  end
end
虚拟机默认磁盘10G,如果需要修改磁盘空间
先执行安装磁盘插件  vagrant plugin install vagrant-disksize
然后配置你想要分配的空间
  config.vm.box = "ubuntu/bionic64"
  config.vm.box_check_update = false
  config.disksize.size = '50GB'
执行启动
vagrant up hadoop4 启动,根据主机名启动 不跟主机名全启动
vagrant halt hadoop4 关机,根据主机名关机 不跟主机名全关
如果配置完,启动报错 CPU虚拟化没开启,需要进到bios
VisualBox报VT-x is disabled in the BIOS. (VERR_VMX_MSR_VMXON_DISABLED)
thinkpad重启F1进入BIOS,选择:
Sercurity => Virtualization=>Enable
如果报错
error: Could not find Host Interface Networking driver! Please reinstall
这是因为,你之前肯定卸载过虚拟机的虚拟网卡,所以这里找不到,那么需要重装虚拟网卡,如下
可以在安装virtualbox目录../Oracle VM VirtualBox中的 drivers\ network\ netadp6目录下有三个文件
VBoxNetAdp6.cat
VBoxNetAdp6.inf
VBoxNetAdp6.sys
这就是virtualbox虚拟网卡的驱动,右击VBoxNetAdp6.inf,点安装即可,安装完成后
重新 vagrant up 就可成功了。
默认用户:vagrant
密钥路径在 C:\APP\HashiCorp\vm1.vagrant\machines\hadoop1\virtualbox\下private_key文件
所有的配置都在:
C:\APP\HashiCorp\vm1\Vagrantfile 文件上
使用 vagrant 账户和密钥文件登录
创建root密码
	vagrant@hadoop2:~$ sudo su
	root@hadoop2:/home/vagrant# passwd root
	Enter new UNIX password:
	Retype new UNIX password:
	passwd: password updated successfully
	root@hadoop2:/home/vagrant#
修改
vim /etc/ssh/sshd_config
将以下参数改为yes 允许
PermitRootLogin yes
PasswordAuthentication yes
重启sshd
systemctl restart sshd
这样才可以直接使用root进行登陆
Vagrantfile 文件完整配置如下
单个虚拟机实例
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
servers = {
    :hadoop13 => '192.168.2.225'
}
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.
  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "centos7/bionic64"
  config.vm.box_check_update = false
  config.disksize.size = '50GB'
  servers.each do |server_name, server_ip|
    config.vm.define server_name do |server_config|
	  server_config.vm.hostname = "#{server_name.to_s}"
	  server_config.vm.network :private_network, ip: server_ip
	  server_config.vm.provider "virtualbox" do |vb|
	    vb.name = server_name.to_s
		  vb.memory = "4096"
		  vb.cpus = 2
	    end
    end
  end
  # if errorMsg is "Unknown configuration section 'disksize'."  that
  # you must install then "vagrant plugin install vagrant-disksize" plugin
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false
  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080
  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"
  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"
  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"
  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.
  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end
多个虚拟机
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
servers = {
    :hadoop1 => '192.168.2.220',
    :hadoop2 => '192.168.2.221',
    :hadoop3 => '192.168.2.222',
    :hadoop4 => '192.168.2.223'
}
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.
  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "ubuntu/bionic64"
  config.vm.box_check_update = false
  # config.disksize.size = '50GB'
  # if you don't specify disk space, the default disk space is 10G
  servers.each do |server_name, server_ip|
    config.vm.define server_name do |server_config|
	  server_config.vm.hostname = "#{server_name.to_s}"
	  server_config.vm.network :private_network, ip: server_ip
	  server_config.vm.provider "virtualbox" do |vb|
	    vb.name = server_name.to_s
		  vb.memory = "1024"
		  vb.cpus = 1
	    end
    end
  end
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false
  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080
  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"
  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"
  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"
  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.
  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end
接下来,就可以通过xshell进行登录操作了。
windows 下使用vargant 搭建虚拟机服务的更多相关文章
- Windows下Git服务器搭建[转]
		Windows下Git服务器搭建 作为对前两天Git服务器搭建的一个整理,我想分别从服务端和客户端两个角度来记录下整个搭建过程,为了达到目标,我们需要哪些操作. (一)服务端软件和账号的安装配置 ... 
- Windows下SVN服务器搭建方法整理(apache)
		http://skydream.iteye.com/blog/437959 http://www.cnblogs.com/liuke209/archive/2009/09/23/1572858.htm ... 
- 转载:Windows下三分钟搭建Shadowoscks服务器端
		Windows下三分钟搭建Shadowoscks服务器端 之前在V2EX上有人问为啥没人做个在Windows上一键运行Shadowsocks服务器端的程序,我只想说……这是因为没人关注我的libQtS ... 
- Redis在windows下的环境搭建
		Redis在windows下的环境搭建 下载windows版本redis,,官方下载地址:http://redis.io/download, 不过官方没有Windows版本,官网只提供linux版本的 ... 
- Windows下的环境搭建Erlang
		Windows下的环境搭建 Erlang 一.安装编译器 在http://www.erlang.org/download.html下载R16B01 Windows Binary File并安装. 二. ... 
- windows下如何快速搭建web.py开发框架
		在windows下如何快速搭建web.py开发框架 用Python进行web开发的话有很多框架供选择,比如最出名的Django,tornado等,除了这些框架之外,有一个轻量级的框架使用起来也是非常方 ... 
- 在windows下如何快速搭建web.py开发框架
		在windows下如何快速搭建web.py开发框架 用Python进行web开发的话有很多框架供选择,比如最出名的Django,tornado等,除了这些框架之外,有一个轻量级的框架使用起来也是非常方 ... 
- windows下sqli-labs的搭建及学习(POST篇)
		windows下sqli-labs的搭建及学习(GET篇): http://blog.csdn.net/sherlock17/article/details/64454449 Less-11:基于错误 ... 
- 【Hadoop】:Windows下使用IDEA搭建Hadoop开发环境
		笔者鼓弄了两个星期,终于把所有有关hadoop的环境配置好了,一是虚拟机上的完全分布式集群,但是为了平时写代码的方便,则在windows上也配置了hadoop的伪分布式集群,同时在IDEA上就可以编写 ... 
随机推荐
- Educational DP Contest  E - Knapsack 2 (01背包进阶版)
			题意:有\(n\)个物品,第\(i\)个物品价值\(v_{i}\),体积为\(w_{i}\),你有容量为\(W\)的背包,求能放物品的最大价值. 题解:经典01背包,但是物品的最大体积给到了\(10^ ... 
- 2019-2020 ACM-ICPC Brazil Subregional Programming Contest   Problem A Artwork  (并查集)
			题意:有一个矩形,有\(k\)个警报器,警报器所在半径\(r\)内不能走,问是否能从左上角走到右下角. 题解:用并查集将所有相交的圆合并,那么不能走的情况如下图所示 所以最后查询判断一下即可. 代码: ... 
- python代理池的构建2——代理ip是否可用的处理和检查
			上一篇博客地址:python代理池的构建1--代理IP类的构建,以及配置文件.日志文件.requests请求头 一.代理ip是否可用的处理(httpbin_validator.py) #-*-codi ... 
- entity framwork修改指定字段
			1.ef修改时指修改指定字段public void ChangePassword(int userId, string password) { var user = new User() { Id = ... 
- 使用Benchmark.NET测试代码性能
			今天,我们将研究如何使用Benchmark.Net来测试代码性能.借助基准测试,我们可以创建基准来验证所做的更改是否按预期工作并且不会导致性能下降. 并非每个项目都需要进行基准测试,但是如果您正在开发 ... 
- 016.NET5_MVC_视图组件扩展定制
			视图组件 1. 呈现页面响应的某一部分而不是整个响应 2. 包括在控制器和视图之间发生的关注分类和可测试优势 3.可以具有参数和业务逻辑 4. 通常在页面局部调用 如何自定义视图组件? 1.Razor ... 
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
			#1235 : New Teaching Buildings 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 Thanks to the generous finance ... 
- Web 开发之  HTTP/2 & SPDY &  HTTP 1.1  & HTTP 对比分析详解!
			1 https://zh.wikipedia.org/wiki/HTTP/2 HTTP/2 维基百科,自由的百科全书 HTTP/2(超文本传输协议第2版 ... 
- export html to canvas image
			export html to canvas image canvas.toDataURL https://developer.mozilla.org/en-US/docs/Web/API/HTMLCa ... 
- js location API All In One
			js location API All In One location "use strict"; /** * * @author xgqfrms * @license MIT * ... 
