[hcai@P1-Gen4 ~]$ vagrant box add generic/alma9 ==> box: Loading metadata for box 'generic/alma9' box: URL: https://vagrantcloud.com/generic/alma9 This box can work with multiple providers! The providers that it can work with are listed below. Please review the list and choose the provider you will be working with.
config.vm.define"master01"do|master| master.vm.box="generic/alma9" master.vm.hostname="master01.example.com" master.vm.network"private_network",ip:"192.168.100.10", libvirt__network_name:'vagrant-lab' master.vm.provider"libvirt"do|kvm| kvm.memory=8192 kvm.cpus=2 kvm.uri='qemu:///system' end end
(1..2).eachdo|i| config.vm.define"worker0#{i}"do|worker| worker.vm.box="generic/alma9" worker.vm.hostname="worker1#{i}.example.com" worker.vm.network"private_network",ip:"192.168.100.1#{i}", libvirt__network_name:'vagrnt-lab' worker.vm.provider"libvirt"do|kvm| kvm.memory=4096 kvm.cpus=2 kvm.uri='qemu:///system' end end end end
上面定义了三台 VM,同时指定了使用的网络和具体的 IP 地址,且在虚拟机启动好后会自动配置 /etc/hosts 。
使用 Vagrant 管理虚拟机
在 Vagrantfile 所在的目录中,通过以下常用命令来管理虚拟机: 查看状态:
1 2 3 4 5 6 7 8 9 10
$ vagrant status Current machine states:
master01 not created (libvirt) worker01 not created (libvirt) worker02 not created (libvirt)
This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`.
评论· · · · · ·