第一步:新建一個目錄
[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配置文件