第一步:新建一个目录
[root@vagrant ~]# mkdir vbox(存放虚拟机box文件)
[root@vagrant ~]# vagrant init centos/6 获取到Vagrantfile文件
第二步:然后下载镜像
[root@vagrant ~]# cd /vbox
[root@vagrant ~]# wget http://soft.51yuki.cn/CentOS-6-x86_64.box
第三步:配置
[root@vagrant vagrant]# mkdir centos6_yuki
[root@vagrant vagrant]# cd centos6_yuki/
[root@vagrant centos6_yuki]# ll
total 0
[root@vagrant centos6_yuki]# cp /vbox/Vagrantfile .
[root@vagrant centos6_yuki]# vagrant box add centos6_yuki /vbox/CentOS-6-x86_64.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos6_yuki' (v0) for provider:
box: Unpacking necessary files from: file:///vbox/CentOS-6-x86_64.box
==> box: Successfully added box 'centos6_yuki' (v0) for 'virtualbox'!
修改Vagrantfile文件,[root@vagrant centos6_yuki]# vim Vagrantfile
改变内容如下
config.vm.box = "centos6_yuki"
第四步:启动虚拟机
[root@vagrant centos6_yuki]# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos6_yuki'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: centos6_yuki_default_1517283402064_20252
==> default: Fixed port collision for 22 => 2222. Now on port 2201.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2201 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2201
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Rsyncing folder: /vagrant/centos6_yuki/ => /vagrant
5、进入虚拟机
[root@vagrant centos6_yuki]# vagrant ssh
[vagrant@localhost ~]$ uname -r
2.6.32-696.18.7.el6.x86_64
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS release 6.9 (Final)
- 第一章:Vagrant基础介绍
- 第二章:Vagrant的安装部署
- 第一节:在centos7.3的系统上安装部署vagrant
- 第二节:在windows server 2008 R2的系统上安装部署vagrant
- 第三章:vagrant常见命令
- 第一节:box
- 第二节:虚拟机相关的命令
- 第四章:vagrant管理虚拟机
- 第一节:初始化centos6的系统
- 第二节:初始化ubuntu16.04的系统
- 第三节:打包自己的box
- 第五章:Vagrant之网络配置
- 第一节:通过Forwarded Ports(转发端口)
- 第二节:Private Networks(私有网络)
- 第三节:Public Networks(公有网络)
- 第六章:常见错误
- 第七章:Vagrant之文件同步方式
- 第一节:synced_folder(把物理机的目录同步到虚拟机里某个目录)
- 第二节:通过NFS共享
- 第三节:通过rsync共享
- 第八章:Vagrantfile配置文件