centos 6.8安装git_如何使用 Vagrant 管理 centOS 和 Ubuntu 虚拟机

0212de58307d4470a1628dd46590c3b9.png

Vagrant 是我们的虚拟机管理软件, 它对接了 Vmware , VirtualBox, parallel box等等。一般来说我们使用 Virtual Box比较多,所以如果你要使用Vagrant,首先你必须在本机装上 virtual box或者是vmware,或者是其他的虚拟机厂商提供的虚拟机软件,然后Vagrant上给我们提供了命令行的方式,来管理这些虚拟机软件.

Vagrant,需要本地的 Web 应用环境,可以使用 Vagrant,通过命令行,去安装 CentOS 虚拟机的镜像,这个镜像在 Vagrant 里面称为 box ,我们可以使用命令,去管理这些 box ,添加,删除,启动,还有停止。

用 Vagrant 启动虚拟机以后,还可以使用 ssh 连接到虚拟机,虚拟机与本地电脑之间会有一个同步的目录,也就是你可以把项目的文件直接放到本地电脑上的某个目录下面,然后使用在虚拟机上配置的环境去运行它。

1. Vagrant 设置

1.1 下载 Vagrant 和 virtualBox(需要sec放行)

1.1.1 下载 vitrualbox VirtualBox 6.0.14 (released October 15 2019) 1.1.2 下载 Vagrant Vagrant 2.2.9下载 下载它并安装

902972e7481055a14305eff6e7b89228.png
x5s-iMac:~ x5$ vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.

查找所需的box 使用成熟的bento/centos-6.8

735f05276213057845ef415d529bc7c4.png

如果你下载网速过慢, 请使用下载工具下载: 直接下载链接

  • 共三个版本,请使用第2个 virtualbox的版本
  • 使用 vagrant box list 命令查看下载好的版本

1.2 Vgrant 安装

1.2.1 在桌面创建 项目的文件夹

mkdir wordpresser
cd wordpressor

1.2.2 安装 bento/centos-6.8

vagrant init bento/centos-6.8
x5s-iMac:wordpresser x5$ vagrant init bento/centos-6.8
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
打开桌面的wordpresser这个文件夹,可以看到这个目录里创建了一个 vigrantfile的文件
使用命令行可见:
x5s-iMac:wordpresser x5$ ls
Vagrantfile

1.3. 启动 Vagrant

Vagrant up

x5s-iMac:wordpresser x5$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'bento/centos-6.8'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/centos-6.8' version '2.3.4' is up to date...
==> default: Setting the name of the VM: wordpresser_default_1577977630498_13614
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:

  https://www.virtualbox.org/manual/ch04.html#sharedfolders

This option can be disabled globally with an environment variable:

  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1

or on a per folder basis within the Vagrantfile:

  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (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:2222
    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: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 5.1.18
    default: VirtualBox Version: 6.0
==> default: Mounting shared folders...  挂载共享目录-对应的是项目目录
    default: /vagrant => /Users/x5/Desktop/wordpresser 两个目录是同步的
x5s-iMac:wordpresser x5$ --结束

这一步骤实际是从下载的虚拟机bento/centos-6.8中复制了一份到这个项目的特定目录下, 我们所做的任何改变都只限于这个项目使用的这个虚拟机。

vagrant ssh
使用 vagrant 用户连接到这个centos

Vagrant 之 Ubuntu

系统环境: macOS Mojave 10.14.

  1. 安装 Vagrant
  2. 安装 VirtualBox

查找所需的虚拟机镜像, 比如 ubuntu.

9369f42b11abf720114949bdbc94604a.png

点击进入 xenial64的页面, 查看安装所需命令:

399ac7d74d789fcbb5e3fa3bb28e71f4.png
vagrant init ubuntu/xenial64

这样就下载了配置文件 Vagrantfile. cat 命令查看可以看到设置的

773711bcddd9307a82c9a57f3c97a1ca.png
default: SSH address: 127.0.0.1:2222          地址
    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: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 5.1.38
    default: VirtualBox Version: 6.1
==> default: Mounting shared folders...
    default: /vagrant => /Users/mask

安装完毕, 通过 vagrant ssh 进入虚拟机

命令行终端提示变化为虚拟机环境

vagrant@ubuntu-xenial:~$ 

安装完毕.

至此, 本文提示了 CentOS 以及 Ubuntu 的 Vagrant 安装.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值