vagrant安装配置
vagrant box add web02 CentOS-7-Vagrant-1509-x86_64-01.box
添加box镜像
D:\work\web02>vagrant box add CentOS-7-Vagrant-1509-x86_64-01.box ==> box: Box file was not detected as metadata. Adding it directly... A name is required when adding a box file directly. Please pass the `--name` parameter to `vagrant box add`. See `vagrant box add -h` for more help. D:\work\web02>vagrant box add web02 CentOS-7-Vagrant-1509-x86_64-01.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'web02' (v0) for provider: box: Unpacking necessary files from: file://D:/work/web02/CentOS-7-Vagrant-1509-x86_64-01.box box: The box you're attempting to add already exists. Remove it before adding it again or add it with the `--force` flag. Name: web02 Provider: virtualbox Version: 0
每个box虚拟机需要一个独立的目录和镜像文件


第二步:初始化

初始化完成就会在目录生成一个Vagrantfile文件

下面修改这个文件

修改成这样

启动虚拟机web02

通过命令vagrant ssh命令进入虚拟机,用户是普通用户vagrant,它的密码是vagrant。通过命令sudo -i 进入root用户,添加root密码,然后配置网卡

启动网卡命令是service network restart
然后修改网卡设置,为桥接模式
vi /etc/ssh/sshd_config
去掉PasswordAuthentication yes 的注释,重启sshd
批量创建虚拟机
先创建一个目录,把box镜像复制过来,然后命令导入镜像,初始化,目录下生成文件,下面修改文件,写几个虚拟机的配置,然后启动
# -*- 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| config.vm.define "DB-master" do |vb| config.vm.provider "virtualbox" do |v| v.memory = "512" v.cpus = 2 end vb.vm.host_name = "DB-master" vb.vm.network :public_network, ip: "192.168.3.201" vb.vm.box = "CentOS-7-Vagrant-1509-x86_64-01.box" end config.vm.define "DB-node01" do |vb| config.vm.provider "virtualbox" do |v| v.memory = "512" v.cpus = 2 end vb.vm.host_name = "DB-node01" vb.vm.network :public_network, ip: "192.168.3.202" vb.vm.box = "CentOS-7-Vagrant-1509-x86_64-01.box" end config.vm.define "DB-node02" do |vb| config.vm.provider "virtualbox" do |v| v.memory = "512" v.cpus = 2 end vb.vm.host_name = "DB-node02" vb.vm.network :public_network, ip: "192.168.3.203" vb.vm.box = "CentOS-7-Vagrant-1509-x86_64-01.box" end config.vm.define "DB-node03" do |vb| config.vm.provider "virtualbox" do |v| v.memory = "512" v.cpus = 2 end vb.vm.host_name = "DB-node03" vb.vm.network :public_network, ip: "192.168.3.204" vb.vm.box = "CentOS-7-Vagrant-1509-x86_64-01.box" end end
后面不需要配置IP,直接连接
浙公网安备 33010602011771号