使用virtualbox和vagrant安装centos7

使用virtualbox和vagrant安装centos7

在windows环境下安装virtualbox 和vagarnt,并且使用vagrant 安装centos7

(1)virtualbox 的安装

下载virtualbox地址: https://www.oracle.com/virtualization/technologies/vm/downloads/virtualbox-downloads.html

下载virtualbox

安装virtualbox:
virtualbox执行文件
点击下一步,安装即可;

(2)vagrant 的安装

下载vagrant: https://www.vagrantup.com/downloads.htm

vagrant下载
安装vagrant:
windows版本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

vagrant box

安装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 sshssh登录虚拟机
vagrant suspend挂起虚拟机
vagrant reload重启虚拟机
vagrant halt关闭虚拟机
vagrant status查看虚拟机状态
vagrant destroy删除虚拟机
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值