文章目录

  • 一、下载安装
    • 1.安装vagrant
    • 2.安装virtualbox
  • 二、准备centos7
    • 1.拉取box镜像
    • 2.Vagrantfile通用写法
    • 3.将virtualbox.box文件添加到vagrant管理的镜像中
    • 4.启动vagrant
  • 三、客户端连接centos7
    • 1.root账户登录
    • 2.客户端连接

一、下载安装

1.安装vagrant

vagrant下载地址:https://www.vagrantup.com/

点击Download,选择相应的操作系统和版本下载即可,傻瓜式安装 -> 一直下一步。
命令行输入vagrant -v,显示相应的版本号说明安装成功。

2.安装virtualbox

virtualbox下载地址:https://www.virtualbox.org/

virtualbox也是傻瓜式安装。
[win10中若出现]安装virtualbox快完成时立即回滚,并提示安装出现严重错误。
(1)打开服务
(2)找到Device Install Service和Device Setup Manager,然后启动
(3)再次尝试安装

二、准备centos7

1.拉取box镜像

(1)创建centos7文件夹,并进入其中[目录全路径不要有中文字符]。

(2)打开cmd,运行vagrant init centos/7
此时会在当前目录下生成Vagrantfile,同时指定使用的镜像为centos/7。关键是这个镜像在哪里,我已经提前准备好了,名称是virtualbox.box文件。

box下载地址:https://pan.baidu.com/s/1b2FNKebL6n0ddsvZSE-k3g 提取码:zymk

2.Vagrantfile通用写法

修改第一步初始化来的Vagrantfile,可以直接用我的,根据自己需要修改一下cpu核数和内存大小,我设置的是20G。

# -*- mode: ruby -*-
# vi: set ft=ruby :# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|# The most common configuration options are documented and commented below.# For a complete reference, please see the online documentation at# https://docs.vagrantup.com.# Every Vagrant development environment requires a box. You can search for# boxes at https://vagrantcloud.com/search.config.vm.box = "centos/7"# Disable automatic box update checking. If you disable this, then# boxes will only be checked for updates when the user runs# `vagrant box outdated`. This is not recommended.# config.vm.box_check_update = false# Create a forwarded port mapping which allows access to a specific port# within the machine from a port on the host machine. In the example below,# accessing "localhost:8080" will access port 80 on the guest machine.# NOTE: This will enable public access to the opened port# config.vm.network "forwarded_port", guest: 80, host: 8080# Create a forwarded port mapping which allows access to a specific port# within the machine from a port on the host machine and only allow access# via 127.0.0.1 to disable public access# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"# Create a private network, which allows host-only access to the machine# using a specific IP.# config.vm.network "private_network", ip: "192.168.33.10"# Create a public network, which generally matched to bridged network.# Bridged networks make the machine appear as another physical device on# your network.config.vm.network "public_network"# Share an additional folder to the guest VM. The first argument is# the path on the host to the actual folder. The second argument is# the path on the guest to mount the folder. And the optional third# argument is a set of non-required options.# config.vm.synced_folder "../data", "/vagrant_data"# Provider-specific configuration so you can fine-tune various# backing providers for Vagrant. These expose provider-specific options.# Example for VirtualBox:## config.vm.provider "virtualbox" do |vb|#   # Display the VirtualBox GUI when booting the machine#   vb.gui = true##   # Customize the amount of memory on the VM:#   vb.memory = "1024"# endconfig.vm.provider "virtualbox" do |vb|vb.memory = "20480"vb.name= "vm1"vb.cpus= 2end## View the documentation for the provider you are using for more# information on available options.# Enable provisioning with a shell script. Additional provisioners such as# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the# documentation for more information about their specific syntax and use.# config.vm.provision "shell", inline: <<-SHELL#   apt-get update#   apt-get install -y apache2# SHELL
end

3.将virtualbox.box文件添加到vagrant管理的镜像中

(1)添加镜像并起名叫centos/7:vagrant box add centos/7 D:\TOOLS\BOX\virtualbox.box
(2)vagrant box list 查看本地的box[这时候可以看到centos/7]

4.启动vagrant

执行vagrant up[打开virtual box观察,可以发现centos7创建成功]。
(执行vagrant halt 可以优雅关闭centos7)

此过程会把宿主主机的2222端口映射在虚拟主机的22端口,设置网络为桥接模式。

三、客户端连接centos7

我用的连接工具是MobaXterm,用xshell也是一样的。

1.root账户登录

vagrant ssh 进入到虚拟机中 sudo -i 进入根目录
vi /etc/ssh/sshd_config 修改PasswordAuthentication yes
passwd修改密码,比如abc123
systemctl restart sshd
使用账号root,密码abc123进行登录

2.客户端连接

这里可以看到我的虚拟ip是192.168.199.222




至此,通过vagrant+virtualbox的方式就成功搭建了一台centos7虚拟机。

vagrant+virtualbox搭建centos7相关推荐

  1. vbox linux centos 6,VirtualBox搭建 CentOS7.6

    1.首先选择系统类型Linux和版本Red Hat(64-bit) (32位的电脑则选择32-bit),内存大小选择适中,虚拟硬盘选择现在创建 2.文件大小按自己的需求选择,文件类型选择VDI,存储选 ...

  2. 【运维开发】Mac OS(10.13.6)使用 vagrant+VirtualBox +centos7搭建k8s集群

    Mac OS(10.13.6)使用 vagrant+VirtualBox +centos7搭建k8s集群步骤 环境准备工作 下载VirtualBox 地址:https://www.virtualbox ...

  3. Vagrant+VirtualBox快速搭建Linux环境

    Vagrant+VirtualBox快速搭建Linux环境 虚拟机 Oracle VM VirtualBox VMware 虚拟机的选择 Vagrant介绍 Vagrant安装centos7 虚拟机固 ...

  4. 利用Vagrant and VirtualBox搭建core os环境

    利用Vagrant and VirtualBox搭建core os环境 系统环境 ubuntu 14.04 x64 vagrant 1.7.4 virtualbox 4.3.10 git 1.9.1 ...

  5. VirtualBox+Vagrant快速搭建linux虚拟环境

    VirtualBox+Vagrant快速搭建linux虚拟环境 1.下载安装VirtualBox 下载 Virtual Box 官网: https://www.virtualbox.org/ 2.BI ...

  6. Vagrant系列(一)----win10搭建Vagrant+VirtualBox环境

    一.Vagrant是什么?     vagrant是一个操作虚拟机的工具.是一个基于Ruby的工具,用于创建和部署虚拟化开发环境.    通过命令和配置文件来管理虚拟机,很快就能完成一套开发环境的部署 ...

  7. VirtualBox 搭建虚拟环境

    使用前的准备: 使用VirtualBox 必须要开启硬件虚拟化,进入BIOS 选择Intel Virtual Technology并回车,将光标移至Enabled,然后再回车,最后按F10保存并退出 ...

  8. 光速搭建centos7虚拟机

    官网下载与安装 0 你有个很会连接网络的windows电脑和迅雷(很会会) 1 安装最新版VirtualBox 2 安装最新版vagrant 3 https://app.vagrantup.com/b ...

  9. virtualbox搭建一个局域网

    virtualbox搭建一个局域网, 要求: 虚拟机之间可以通信 虚拟机主机直接互通 虚拟机可以上网 系统配置: Win10,只有一个无线网卡 Virtualbox 6.0 虚拟机系统为centos7 ...

最新文章

  1. 2014:超越炒作,进入部署SDN的时代
  2. 软件质量保证与测试文档怎么写,软件质量保证与测试整理版.pdf
  3. 【168天】黑马程序员27天视频学习笔记【Day07】
  4. sun服务器清理内存日志_sun服务器系统日志
  5. 前端面试常考题:JS垃圾回收机制
  6. JavaScript鼠标经过图片加亮显示
  7. js中当前时间的获得以及日期格式的转换
  8. destoon php文件,Destoon模板制作简明教程
  9. 深入浅出设计模式---3、代理模式和工厂模式
  10. 云优CMS采集不需要云优CMS授权
  11. 这8款数据恢复软件你见过吗?数据恢复软件推荐
  12. 官方VM tools下载地址
  13. 通过网易云API爬取评论
  14. 最新MQ与RabbitMQ面试题
  15. krpano默认皮肤详解
  16. 【FXP】连接站点并上传包文件:
  17. jmeter实现手机号归属地接口测试案例
  18. mysql数据血缘分析,数仓字段血缘解析实现—hive版
  19. 表单验证:名称、电话号码、邮箱
  20. RRT、RRT-connect、RRT*等算法、A*等等路径规划算法

热门文章

  1. 动态规划:8行代码搞定最大子数组和问题
  2. 本周涨粉一倍,我决定再开源一个商超管理系统
  3. Qmail 日志文件格式
  4. 学生HTML个人网页作业作品----(画家企业8页)
  5. 【汇编语言】Arm处理器之中断处理
  6. 华为电脑分类四个系列_华为笔记本系列推荐榜单
  7. 个人征信报告解析(机构版)
  8. layui 利用tab选项卡实现:上一步,下一步操作
  9. 暗时间----有感而发
  10. windows下使用vscode开发stm32