windows下安装VirtualBox和Vagrant
安装环境
- Windows10
- Vagrant 2.2.6 + VirtualBox 6.0.14
官网下载地址:
VirtualBox:https://www.virtualbox.org/
Vagrant:https://www.vagrantup.com/downloads.html
具体安装步骤
-
在上述官网地址中下载适合操作系统的版本,我这就以window10为例
-
安装好了之后要重启操作系统以便于重新配置电脑
-
检查是否安装成功了
- 运行
cmd - 输入
vagrant检查 Vagrant是否安装成功,如果有命令使用帮助表示安装成功,或者单独输入vagrant -v查看版本号的命令
- 运行
-
-
为 Vagrant 添加 box
vagrant box add osName filePath
vagrant box add centos/7 F:\installs\VirtualBox\box\virtualbox.box注意文件路径中不能有中文名,不能有空格- 通过
vagrant box list检验是否添加成功
-
初始化 vagrant
-
vagrant init在特定目录下执行,会生成 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. 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 = "base" # 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 # Puppet, Chef, Ansible, Salt, and Docker 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 -
修改具体几个参数
-
config.vm.box = "base"改为本地安装的 box , 不然要从远端拉取 -
config.vm.network "public_network"打开这个配置,与物理主机共享同一网段,类似桥接模式 -
虚拟机内存、名称、CPU配置:
config.vm.provider "virtualbox" do |vb| vb.memory = "3000" vb.name= "123-centos7" vb.cpus= 2 end
-
-
-
启动虚拟机,在上一步配置好的特定目录下执行
vagrant up- 打开观察 VirtualBox ,虚拟机启动好了会在VB中自动创建一个虚拟机实例
-
vagrant ssh进入启动的虚拟机控制台
此时可能会报错,vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic). ,可以参考我另一篇文章解决此问题。 https://blog.youkuaiyun.com/ai_0922/article/details/106366521
649

被折叠的 条评论
为什么被折叠?



