初始化centos6的系统
第一步:新建一个目录
存放虚拟机box文件
[root@vagrant ~]# mkdir vbox
获取到Vagrantfile文件
[root@vagrant ~]# vagrant init centos/6
第二步:然后下载镜像
[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)