使用virtualbox和vagrant安装centos7
在windows环境下安装virtualbox 和vagarnt,并且使用vagrant 安装centos7
(1)virtualbox 的安装
下载virtualbox地址: https://www.oracle.com/virtualization/technologies/vm/downloads/virtualbox-downloads.html
安装virtualbox:
点击下一步,安装即可;
(2)vagrant 的安装
下载vagrant: https://www.vagrantup.com/downloads.htm
安装vagrant:
点击:下一步安装即可。
注意: 由于官网下载vagrant比较慢,建议使用已经下载好存储在百度网盘中的文件
百度网盘地址:https://pan.baidu.com/s/1O1x30YAumg28IqI7QoxfsQ
密码:h12q
查看是否安装成功:
使用cmd打开操作窗口,使用vagrant命令查看是否安装成功,如下图,表面安装成功:
C:\Users\Administrator>vagrant
Usage: vagrant [options] <command> [<args>]
-v, --version Print the version and exit.
-h, --help Print this help.
Common commands:
box manages boxes: installation, removal, etc.
cloud manages everything related to Vagrant Cloud
destroy stops and deletes all traces of the vagrant machine
global-status outputs status Vagrant environments for this user
halt stops the vagrant machine
help shows the help for a subcommand
init initializes a new Vagrant environment by creating a Vagrantfile
login
package packages a running vagrant environment into a box
plugin manages plugins: install, uninstall, update, etc.
port displays information about guest port mappings
powershell connects to machine via powershell remoting
provision provisions the vagrant machine
push deploys code in this environment to a configured destination
rdp connects to machine via RDP
reload restarts vagrant machine, loads new Vagrantfile configuration
resume resume a suspended vagrant machine
snapshot manages snapshots: saving, restoring, etc.
ssh connects to machine via SSH
ssh-config outputs OpenSSH valid configuration to connect to the machine
status outputs status of the vagrant machine
suspend suspends the machine
up starts and provisions the vagrant environment
upload upload to machine via communicator
validate validates the Vagrantfile
version prints current and latest Vagrant version
winrm executes commands on a machine via WinRM
winrm-config outputs WinRM configuration to connect to the machine
For help on any individual command run `vagrant COMMAND -h`
Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.
C:\Users\Administrator>
(3) 安装centos7
查找vagrant box地址: https://app.vagrantup.com/boxes/search
安装centos7:
vagrant init centos/7
启动centos7:
vagrant up
启动centos7,需要下载相关文件,时间比较漫长,需要耐心等待
出现如下信息,安装完成;
连接virtualbox中的centos7:
vagrant ssh
(4)将端口转发的网卡(默认)设置,修改为固定ip
查询本机的 VirtualBox Host-Only Network
C:\Windows\System32>ipconfig
以太网适配器 VirtualBox Host-Only Network:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::f59f:cc5a:a18d:5355%20
IPv4 地址 . . . . . . . . . . . . : 192.168.56.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :
修改vagrantfile文件:
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# 打开下面的注释,并将ip网段设置为56网段
config.vm.network "private_network", ip: "192.168.56.10"
保存文件,重启vagrant
vagrant reload
常见命令
命令 | 解释 |
---|---|
vagrant box list | 查看目前已有的box |
vagrant box add | 新增加一个box |
vagrant box remove | 删除指定box |
vagrant init | 初始化配置vagrantfile |
vagrant up | 启动虚拟机 |
vagrant ssh | ssh登录虚拟机 |
vagrant suspend | 挂起虚拟机 |
vagrant reload | 重启虚拟机 |
vagrant halt | 关闭虚拟机 |
vagrant status | 查看虚拟机状态 |
vagrant destroy | 删除虚拟机 |