断点续传安装安装Vagrant版本SQL Server2014

需求

在服务器版本的CentOS7.5下需要安装一个Window版本的Sql Server 2014,但由于virtualbox.box过大(14G),由于网络环境,直接用vagrant总是不能一次下载成功,而且vagrant没有断点续传的功能,导致vagrant总是要重新下载。

解决方法

通过实践发现vagrant是用virtualbox.box镜像文件作为虚拟机的模板,只要把virtualbox.box下载,再导致vagrant中就可以成功启动虚拟机了。所以就想到用wget断点续传下载好virtualbox.box,再手工加载到vagrant中,最后启动虚拟机即可。

处理过程

gusztavvargadr-w16s-sql14d的SQL Server

主要信息点

下载virtualbox.box

先得到virtualbox.box下载地址,通过vagrant up输出virtualbox.box下载地址

[root@htwy gusztavvargadr-w16s-sql14d]# vagrant init gusztavvargadr/w16s-sql14d
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.
[root@htwy gusztavvargadr-w16s-sql14d]# ll -a
total 4
drwxr-xr-x 2 root root   25 Sep 29 22:07 .
drwxr-xr-x 4 root root   31 Sep 29 22:07 ..
-rw-r--r-- 1 root root 3033 Sep 29 22:07 Vagrantfile
[root@htwy gusztavvargadr-w16s-sql14d]# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'gusztavvargadr/w16s-sql14d' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'gusztavvargadr/w16s-sql14d'
    default: URL: https://vagrantcloud.com/gusztavvargadr/w16s-sql14d
==> default: Adding box 'gusztavvargadr/w16s-sql14d' (v1808.0.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/gusztavvargadr/boxes/w16s-sql14d/versions/1808.0.0/providers/virtualbox.box
    default: Progress: 0% (Rate: 0/s, Estimated time remaining: --:--:--)

断点续传下载virtualbox.box

[root@htwy gusztavvargadr-w16s-sql14d]# wget -c -t 0 https://vagrantcloud.com/gusztavvargadr/boxes/w16s-sql14d/versions/1808.0.0/providers/virtualbox.box

导入virtualbox.box

等一段时间的下载,终于全部下载好virtualbox.box。要做的事就要把virtualbox.box导入进去

主要有几点

  1. 配置metadata.json,描述virtualbox.box信息
    name: vagrant box的app名
    version: X.Y.Z格式就行,最好跟app中描述的一致,Vagrantfile中不指定版本也是能运行的。
    name: virtualbox
    url: virtualbox.box的路径名
{
  "name": "gusztavvargadr/w16s-sql14d",
  "versions": 
  [ 
     { 
        "version": "1808.0.0",
        "providers": [
           {
             "name": "virtualbox",
             "url": "/data/work/vagrant/gusztavvargadr-w16s-sql14d/virtualbox.box"
           }
         ]
     }
  ]
}
  1. 导入virtualbox.box
    vagrant box add metadata.json

  2. 查看box
    vagrant box list

  3. 操作过程

[root@htwy gusztavvargadr-w16s-sql14d]# vagrant box list

[root@htwy gusztavvargadr-w16s-sql14d]# vim metadata.json 
[root@htwy gusztavvargadr-w16s-sql14d]# cat metadata.json 
{
  "name": "gusztavvargadr/w16s-sql14d",
  "versions": 
  [ 
     { 
        "version": "1808.0.0",
        "providers": [
           {
             "name": "virtualbox",
             "url": "/data/work/vagrant/gusztavvargadr-w16s-sql14d/virtualbox.box"
           }
         ]
     }
  ]
}
[root@htwy gusztavvargadr-w16s-sql14d]# vagrant box add metadata.json 
==> box: Loading metadata for box 'metadata.json'
    box: URL: file:///data/work/vagrant/gusztavvargadr-w16s-sql14d/metadata.json
==> box: Adding box 'gusztavvargadr/w16s-sql14d' (v1808.0.0) for provider: virtualbox
    box: Downloading: /data/work/vagrant/gusztavvargadr-w16s-sql14d/virtualbox.box
==> box: Successfully added box 'gusztavvargadr/w16s-sql14d' (v1808.0.0) for 'virtualbox'!
[root@htwy gusztavvargadr-w16s-sql14d]# vagrant box list
gusztavvargadr/w16s-sql14d  (virtualbox, 1808.0.0)
[root@htwy gusztavvargadr-w16s-sql14d]# 

运行虚拟机vagrant up

主要是 配置bridged 的网卡

[root@htwy gusztavvargadr-w16s-sql14d]# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'gusztavvargadr/w16s-sql14d'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'gusztavvargadr/w16s-sql14d' is up to date...
==> default: Setting the name of the VM: gusztavvargadr-w16s-sql14d_default_1538207071718_26664
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) em2
2) veth54c02fd
3) veth1b66282
4) vetha876862
5) vethd2c03a1
6) br-d729b10fd4b1
7) veth5eeef01
8) veth387d2ee
9) vethaca6e79
10) vethb3a1158
11) veth25b70f9
12) veth6777525
13) vethb85a56c
14) veth825f6b9
15) veth9435727
16) vethc3c57bc
17) vethab3b1d4
18) veth2794315
19) veth729ceab
20) vethf902bd3
21) vpn_default
22) vethcec6382
23) veth2ab7119
24) vethdcaf93c
25) veth393b4b1
26) veth34ee587
27) em3
28) em1
29) em4
30) vethc1e38f7
31) veth82a4c65
32) docker0
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
    default: Which interface should the network bridge to? 1
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 3389 (guest) => 33389 (host) (adapter 1)
    default: 5985 (guest) => 55985 (host) (adapter 1)
    default: 5986 (guest) => 55986 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: WinRM address: 127.0.0.1:55985
    default: WinRM username: vagrant
    default: WinRM execution_time_limit: PT2H
    default: WinRM transport: negotiate
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /data/work/vagrant/gusztavvargadr-w16s-sql14d

Vagrantfile

参考:WinRM Settings

Vagrantfile要进行一定的修改,主要区别点

[root@htwy gusztavvargadr-w16s-sql14d]# diff Vagrantfile Vagrantfile.old 
16,18d15
<   config.vm.guest = :windows
<   config.vm.communicator = "winrm"  
43c40
<   config.vm.network "public_network", ip: "192.168.31.103"
---
>   # config.vm.network "public_network"
  1. 对于操作系统为Window的虚拟机,指定下面两个配置项:
    config.vm.guest = :windows
    config.vm.communicator = "winrm"

  2. 配置局域网的IP地址,供其他用户访问使用
    config.vm.network "public_network", ip: "192.168.31.103"

[root@htwy gusztavvargadr-w16s-sql14d]# cat Vagrantfile
# -*- 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 = "gusztavvargadr/w16s-sql14d"
 
 #windows系统要指定下面两个配置项
  config.vm.guest = :windows
  config.vm.communicator = "winrm"  

  # 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", ip: "192.168.31.103"

  # 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"
  # end
  #
  # 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

访问数据库

测试访问信息:


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. Vagrant 的介绍 虚拟开发环境 平常我们经常会遇到这样的问题:在开发机上面开发完毕程序,放到正式环境之...
    斐波那契额阅读 1,874评论 1 12
  • 一、Vagrant 介绍 Vagrant 是一个软件,可以自动化虚拟机的安装和配置流程,用来管理虚拟机,如 Vir...
    zpei0411阅读 3,998评论 0 7
  • 最近服务器老是宕机,学习的时候很多环境有需要集群,忍无可忍的情况下终于决定自己装一波虚拟机宫学习使用。本人系统为D...
    行书以鉴阅读 1,966评论 0 1
  • 什么是Vagrant简单来说,Vagrant 就是一个虚拟机的集成管理器。 我们用它可以快速创建虚拟机,可以快速部...
    嗝喯唲阅读 681评论 0 0
  • 1,介绍Vagrant 我们做web开发的时候经常要安装各种本地测试环境,比如apache,php,mysql,r...
    meng_philip123阅读 2,553评论 0 12