简单介绍使用
具体步骤
从这个地址下载centos7
https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
cmd,运行以下命令
1 2 3 4 5 6 7 8 9
|
vagrant box add CentOs7 E:/config/centos-7.0-x86_64.box
|

运行以下命令
1 2 3 4 5
|
vagrant init CentOs7
|

注意:如果你之间已经执行过vagrant init这个命令,会报错,需要把相应的文件删除即可,一般文件会在你操作的目录下,我的是C:\Users\lenovo,删除这个Vagrantfile,再次执行vagrant init CentOs7即可
至此,已经安装成功,直接vagrant up启动即可
打开xshell输入相应信息
1 2 3 4 5 6 7
| 127.0.0.1
root vagrant
端口:2222
|
使用xshell连接即可
若是要多个虚拟机做集群,需要在第4部之前修改Vagrantfile,然后下面vagrant up就可以了,下面是我的Vagrantfile配置,是三个虚拟机
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| Vagrant.configure("2") do |config|
config.vm.define "vagrant1" do |vb|
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 1
end
vb.vm.host_name = "vagrant1"
vb.vm.network :public_network, ip: "192.168.1.21"
vb.vm.box = "Centos7"
end
config.vm.define "vagrant2" do |vb|
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 1
end
vb.vm.host_name = "vagrant2"
vb.vm.network :public_network, ip: "192.168.1.22"
vb.vm.box = "Centos7"
end
config.vm.define "vagrant3" do |vb|
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 1
end
vb.vm.host_name = "vagrant3"
vb.vm.network :public_network, ip: "192.168.1.23"
vb.vm.box = "Centos7"
end
end
|
账号是root 密码是 vagrant
端口号每个不一样,非常好辨认

vagrant常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
vagrant init
vagrant up:
vagrant up 虚拟机名字
vagrant ssh:
vagrant suspend:
vagrant reload
vagrant halt:
vagrant status:
vagrant destroy:
|