1.VirtualBox下载地址
https://www.virtualbox.org/wiki/Downloads
2.vagrant下载地址
https://www.vagrantup.com/downloads.html
vagrant 基本使用
1.创建centos7是Vagrantfile
vagrant init centos/7 # 自动会创建centos7的vagrantfile文件
2.创建centos虚拟机
vagrant up # 会自动执行当前问路径下的vagrantfile
3.如果启动报错 Raw-mode is unavailable courtesy of Hyper-V. 这个错误
https://www.jianshu.com/p/2e3429d45aea
4.进入虚拟机
vagrant ssh
5.退出
exit
6.查看虚拟机状态
vagrant status
7.停止虚拟机的运行
vagrant halt
8.删除当前虚拟机
vagrant destroy
9.查看本地所有的box
$ vagrant box list centos/7 (virtualbox, 1902.01)
10.删除某个box
vagrant box remove box-name # box-name 名称
vagrantfile 基本使用
1、设置box名称
config.vm.box = "centos/7"
2、虚拟机(VM)配置
vb.customize ["modifyvm", :id, "--name", "centos7-vagrant"]
3、网络配置
config.vm.network "public_network", ip: "192.168.0.4" # 固定的私有IP 或 config.vm.network "public_network", type: "dhcp" # 动态分配IP
4、共享目录
config.vm.synced_folder "D:/vagrant/data", "/vagrant_data"
5、端口转发
config.vm.network "forwarded_port", guest: 80, host: 8081
6、配置hostname
config.vm.hostname = "node1"
7.vagrantfile配置
Vagrant.configure("2") do |config| config.vm.box = "centos/7" config.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--name", "centos7-vagrant"] end config.vm.synced_folder "D:/miniui_net", "/vagrant_data" config.vm.network "forwarded_port", guest: 80, host: 8083 config.vm.hostname = "centos2" config.vm.network "public_network", ip: "192.168.31.61" end
vagrant 安装程序
1.查看有哪些包
vagrant plugin list
2.安装包
vagrant plugin install vagrant-scp(包名名称)