Windows7(32bit版)のホスト環境にて、VirtualBox+VagrantでVyOS環境を構築した際のメモ。
当方の環境
ホストOS: Windows7 32bit版 / RAM: 4GB / CPU: Intel Core i3-2350M 2.30GHz
ゲストOS: higebu/vagrant版VyOS バージョン1.1.7
VirtualBox 5.1.28
Vagrant 2.0.0
構築手順
環境構築
1. VirtualBoxがPC(ホストOS側)にインストールされていない場合は、インストール。
インストール手順やVirtualBoxの設定に関しては、ここでは割愛。
2. VagrantをPCにインストール。
自分の場合、下記ダウンロードサイトにてWindows 32bitを選択。
https://www.vagrantup.com/downloads.html
ダウンロードした.msiファイルをダブルクリックすると、インストールが開始する。
インストールの完了後、cmd.exeを立ち上げる。
vagrant -vコマンドを打ち、Vagrantのバージョンが出力されればインストールが成功した事を示す。
C:\tmp>vagrant -v Vagrant 2.0.0
3. cmd.exeのウインドウ内にてVagrant作業用ディレクトリを作成。
自分の場合はCドライブ直下にvagrantディレクトリを作成。作成後はvagrantディレクトリに移動。
C:\tmp>mkdir C:\vagrant C:\tmp>cd C:\vagrant C:\vagrant>
VagrantでVyOSをデプロイ
4. 以下のコマンドをを打ってvagrantfileを生成後、vagrantfileを以下のとおりに編集。
本手順を何度か実行し、以下の内容に落ち着いた。
C:\vagrant>vagrant init higebu/vyos
以下はvagrantfileの内容。
# -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile for Vagrant version 2.0.0 VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.define :vyos117 do |vyos117| vyos117.vm.box = "higebu/vyos" vyos117.vm.network "public_network", bridge: "en0: Ethernet", ip: "192.168.1.100" vyos117.vm.network "private_network", ip: "192.168.100.1", netmask: "255.255.255.0" vyos117.vm.network "private_network", ip: "192.168.101.1", netmask: "255.255.255.0" end config.vm.provider "virtualbox" do |v| v.customize ["modifyvm", :id, "--ostype", "Debian_64"] v.cpus = 1 v.memory = 1024 end config.vm.host_name = "mtkVMRT99" config.ssh.insert_key = false end
11行目: eth1に適用される設定。Bridge設定である為に家庭内LANと同じネットワークに属する。
DHCPでIPアドレスを自動取得するeth0をセカンダリ、eth1をプライマリのWANインターフェースに設定した。
12行目: eth2に適用される設定。Host-only設定である為に外部からは見えない。
13行目: eth3に適用される設定。Host-only設定である為に外部からは見えない。
16行目: 64bitなDebian(Squeeze)ベースのシステムである為、Debian_64を指定。
18行目: 1GBに指定。何も指定しないと256MB。
20行目: VyOSのホスト名をここで設定出来る。
21行目: 複数の仮想マシン間でSSH設定を共通にする為に設定。
5. VyattaやVyOSをVagrantから制御する為ののVagrantプラグインをインストール。
C:\vagrant>vagrant plugin install vagrant-vyatta Installing the 'vagrant-vyatta' plugin. This can take a few minutes... Fetching: vagrant-share-1.1.9.gem (100%) Fetching: vagrant-vyatta-0.0.5.gem (100%) Installed the plugin 'vagrant-vyatta (0.0.5)'
6. 以下のコマンドを打ち、VyOSのboxファイルのダウンロードと展開、そしてVyOSの構築の実行。
C:\vagrant>vagrant up --provider virtualbox Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'higebu/vyos' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Loading metadata for box 'higebu/vyos' default: URL: https://vagrantcloud.com/higebu/vyos ==> default: Adding box 'higebu/vyos' (v1.1.7) for provider: virtualbox default: Downloading: https://vagrantcloud.com/higebu/boxes/vyos/versions/1.1.7/providers/virtualbox.box default: Progress: 100% (Rate: 507k/s, Estimated time remaining: --:--:--) ==> default: Successfully added box 'higebu/vyos' (v1.1.7) for 'virtualbox'! ==> default: Importing base box 'higebu/vyos'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'higebu/vyos' is up to date... ==> default: Setting the name of the VM: vagrant_default_1507345611761_84255 ==> default: Clearing any previously set network interfaces... There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below. <span style="font-size: 85%"> Command: ["hostonlyif", "create"] <span style="font-size: 85%"> Stderr: 0%... Progress state: E_FAIL VBoxManage.exe: error: Failed to create the host-only adapter VBoxManage.exe: error: Operation canceled by the user VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component VirtualBoxWrap, interface irtualBox VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreate(struct HandlerArg *)" a ine 94 of file VBoxManageHostonly.cpp
VirtualBoxのHost-only adapterが作成出来ないよと言って来た為、
VirtualBoxにてNetwork Adapter2のAttached toをHost-only adapterに変更。
再度、vagrant up --provider virtualboxを実行。
C:\vagrant>vagrant up --provider virtualbox Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'higebu/vyos' is up to date... ==> default: Clearing any previously set network interfaces... ==> default: Specific bridge 'en0: Ethernet' not found. You may be asked to specify ==> default: which network to bridge to. ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly default: Adapter 3: bridged ==> 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: 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.0.26 default: VirtualBox Version: 5.1 ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => C:/vagrant
7. cmd.exeのプロンプトが返ってきた。
boxファイルのダウンロードと展開が正常に完了した事を示す。
vagrant sshコマンドを叩き、VyOSにログイン。
C:\vagrant>vagrant ssh Linux vyos 3.13.11-1-amd64-vyos #1 SMP Wed Aug 12 02:08:05 UTC 2015 x86_64 Welcome to VyOS. This system is open-source software. The exact distribution terms for each module comprising the full system are described in the individual files in /usr/share/doc/*/copyright. vagrant@mtkVMRT99:~$
参考リンクおよび参考書
https://qiita.com/ozawan/items/160728f7c6b10c73b97e
https://app.vagrantup.com/higebu/boxes/vyos
https://www.amazon.co.jp/%E5%AE%9F%E8%B7%B5-Vagrant-Mitchell-Hashimoto/dp/4873116651/ref=sr_1_1?ie=UTF8&qid=1507517480&sr=8-1&keywords=vagrant