初始化centos6的系统

第一步:新建一个目录

存放虚拟机box文件

  1. [root@vagrant ~]# mkdir vbox

获取到Vagrantfile文件

  1. [root@vagrant ~]# vagrant init centos/6

第二步:然后下载镜像

  1. [root@vagrant ~]# cd /vbox
  2. [root@vagrant ~]# wget http://soft.51yuki.cn/CentOS-6-x86_64.box

第三步:配置

  1. [root@vagrant vagrant]# mkdir centos6_yuki
  2. [root@vagrant vagrant]# cd centos6_yuki/
  3. [root@vagrant centos6_yuki]# ll
  4. total 0
  5. [root@vagrant centos6_yuki]# cp /vbox/Vagrantfile .
  6. [root@vagrant centos6_yuki]# vagrant box add centos6_yuki /vbox/CentOS-6-x86_64.box
  7. ==> box: Box file was not detected as metadata. Adding it directly...
  8. ==> box: Adding box 'centos6_yuki' (v0) for provider:
  9. box: Unpacking necessary files from: file:///vbox/CentOS-6-x86_64.box
  10. ==> box: Successfully added box 'centos6_yuki' (v0) for 'virtualbox'!

修改Vagrantfile文件,

  1. [root@vagrant centos6_yuki]# vim Vagrantfile

改变内容如下

  1. config.vm.box = "centos6_yuki"

第四步:启动虚拟机

  1. [root@vagrant centos6_yuki]# vagrant up
  2. Bringing machine 'default' up with 'virtualbox' provider...
  3. ==> default: Importing base box 'centos6_yuki'...
  4. ==> default: Matching MAC address for NAT networking...
  5. ==> default: Setting the name of the VM: centos6_yuki_default_1517283402064_20252
  6. ==> default: Fixed port collision for 22 => 2222. Now on port 2201.
  7. ==> default: Clearing any previously set network interfaces...
  8. ==> default: Preparing network interfaces based on configuration...
  9. default: Adapter 1: nat
  10. ==> default: Forwarding ports...
  11. default: 22 (guest) => 2201 (host) (adapter 1)
  12. ==> default: Booting VM...
  13. ==> default: Waiting for machine to boot. This may take a few minutes...
  14. default: SSH address: 127.0.0.1:2201
  15. default: SSH username: vagrant
  16. default: SSH auth method: private key
  17. default:
  18. default: Vagrant insecure key detected. Vagrant will automatically replace
  19. default: this with a newly generated keypair for better security.
  20. default:
  21. default: Inserting generated public key within guest...
  22. default: Removing insecure key from the guest if it's present...
  23. default: Key inserted! Disconnecting and reconnecting using new SSH key...
  24. ==> default: Machine booted and ready!
  25. ==> default: Checking for guest additions in VM...
  26. default: No guest additions were detected on the base box for this VM! Guest
  27. default: additions are required for forwarded ports, shared folders, host only
  28. default: networking, and more. If SSH fails on this machine, please install
  29. default: the guest additions and repackage the box to continue.
  30. default:
  31. default: This is not an error message; everything may continue to work properly,
  32. default: in which case you may ignore this message.
  33. ==> default: Rsyncing folder: /vagrant/centos6_yuki/ => /vagrant

5、进入虚拟机

  1. [root@vagrant centos6_yuki]# vagrant ssh
  2. [vagrant@localhost ~]$ uname -r
  3. 2.6.32-696.18.7.el6.x86_64
  4. [vagrant@localhost ~]$ cat /etc/redhat-release
  5. CentOS release 6.9 (Final)