Vagrant 创建和部署虚拟开发环境,各种集群的测试环境的搭建用多个vagrant虚拟机来模拟。
(1)下载工具
VirtualBox 下载地址:下载
Vagrant 下载地址:下载
(2)安装操作系统
vagrant 的box源 https://app.vagrantup.com/boxes/search
在文件夹centos中,执行:
vagrant init centos/7
vagrant up
(3)配置端口映射,让host机器来访问:
编辑.Vagrantfile
config.vm.network "forwarded_port", guest: 9411, host: 9411
config.vm.network "forwarded_port", guest: 3306, host: 3306
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 2280, host: 2280
config.vm.network "forwarded_port", guest: 7280, host: 7280
(4) Vagrant网络类型
Vagrant网络配置
NAT能力较弱,虚拟机之间无法互访,可使用bridged或者Host-Only的模式
Host-Only的配置
.Vagrantfile
config.vm.network "private_network", ip: "192.168.33.10"
重启虚拟机
vagrant up
互ping:
ping通,说明虚拟机之间可以相互访问
网友评论