あーる学習帳

自分が勉強したことや気になることなど、99%自分用です。コードを書いてるのでPCから閲覧を推奨。

仮想環境構築②

ゲームは一日一時間(体感)。

 

昨日の続きで仮想環境構築。ドットインストールの動画を見直したところ、

Vagrant 1.8.6 ・VirtualBox 5.1.8

を使っているのでそれに合わせてみる。

どちらもリリースが2年前くらい。

Hyper-V無効化の状態(立ち上げ時に「Disable Hyper-V」を選択)で起動し、

VirtualBoxVagrantの順にインストールした後に環境構築のコマンドを実行。

 

今回は仮想マシン設定用のVagrantFileを作るところでエラー。

Bundler, the underlying system used to manage Vagrant plugins,
is reporting that a plugin or its dependency can't be found.
This is usually caused by manual tampering with the 'plugins.json'
file in the Vagrant home directory. To fix this error, please
remove that file and reinstall all your plugins using `vagrant
plugin install`.
C:/HashiCorp/Vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/resolver.rb:356:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'vagrant-vbguest x86-mingw32' in any of the gem sources listed in your Gemfile or available on this machine. (Bundler::GemNotFound)
from C:/HashiCorp/Vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/resolver.rb:331:in `each'
from C:/HashiCorp/Vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/resolver.rb:331:in `verify_gemfile_dependencies_are_found!'
from C:/HashiCorp/Vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/resolver.rb:200:in `start'
from C:/HashiCorp/Vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/resolver.rb:184:in `resolve'
from C:/HashiCorp/Vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/definition.rb:200:in `resolve'
from C:/HashiCorp/Vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'
from C:/HashiCorp/Vagrant/embedded/gems/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.6/lib/vagrant.rb:76:in `<top (required)>'
from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.6/bin/vagrant:105:in `<main>' 

C:\HashiCorp\Vagrant\embedded\plugins.json

というやつが悪さをしているようなので消してしまえ!というエラーらしい。

そいつを消してvagrant plugin installを実行したらまた同じエラー。

vagrant plugin install vagrant-vbguestだったり、

vagrant plugin expunge --reinstallもやってみたが、

実行したvagrantのコマンド全部で同じエラーが出ている。

インストールの段階で何か失敗しているっぽい?

Hyper-Vを有効にした状態(=通常のWIndows10)で起動し、再インストールしてみる。

やはりvagrant init bento/centos-6.8を実行すると上記のエラーが発生。

だんだん悲しくなってきたぞ…。

Windows10 のバージョン1709だとこの方法は難しい?

 

こちらに載っていた環境変数の設定を試してみることにする。

Windows 10にVirtualBoxとVagrantでCentOSの仮想環境を作ってみた

VirtualBoxVagrant共に最新版をインストールしたところ、

Vagrantプラグインのインストールを要求されたが

Vagrant Upまでこぎつけることができた。

そこでHyper-Vの設定が今の状態だとダメだと言われたので

Disable Hyper-Vの状態になるよう再起動。

ドキドキしながらVagrant Upを実行すると…

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=500,gid=500 vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

 なんか昨日見たぞ。仮想マシンは起動してるけど共有ができないやつ。

「/sbin/mount.vboxsf: mounting failed with the error: No such device」で検索すると結構な数の事例が出てくる。

ホストとゲスト間のフォルダ共有機能について、機能のバージョンが不一致していることが原因なのでプラグインを入れてみる。ダメでした。

ドットインストールに従うなら、「レッスンでは共有使わないから問題ないぜ!」とのことなのでもう無視して先に進めます。埒が明かないので。

 

お待ちかねのVagrant Statusを実行すると…

Current machine states:

default running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

現在実行されているとのこと。やったぜ。

 

続いて、PuTTYをインストール。

putty-64bit-0.70-installer.msiをダウンロードして実行。

その後PuTTY仮想マシンにログイン。パスワードは入力しても*とか出ないので注意。

このままでは仮想マシンが空っぽなので、以下のコマンドで中身を入れていく。

ドットインストールの内容をそのままコピペ。

# OSを最新状態にアップデート(めっちゃ時間かかる)
sudo yum -y update

# スクリプトを入手するためのgitをインストール
sudo yum -y install git

# gitを使ってアプリケーション設定用のスクリプトをダウンロード
git clone https://github.com/dotinstallres/centos6.git

# centos6フォルダができるのでそちらに移動
cd centos6

# スクリプトを実行(めちゃめちゃ時間かかる)
./run.sh

# もろもろの設定を反映
exec $SHELL -l

今夜は遅いのでここまで。

PuTTYのコマンドを実行している間にだいぶ時間があったので、寝る時間を惜しんでやるのはおすすめできないかも。

仮想環境構築①

放置していたドットインストールくん、またよろしく。

 

ローカル開発環境の構築(Windows10)

Webでなんやかんやしようとするとき、レンタルサーバーを借りるのはお金がかかるので自分のPCに仮想環境を作ってしまおうというお話。

VirtualBoxインストール(Ver5.2.12→5.1.38→5.1.30)

Vagrantインストール(Ver2.1.1→2.0.1)

 サーバー1つに付きVagrantでは1フォルダ必要。

CentOSを使う→「MyCentOS」というフォルダを作ってその中にサーバー立ち上げ。

自分はC:\(自分のフォルダ)\MyVagrantに作ることにする。

 

VagrantのコマンドでIPアドレスとサーバーの設定ファイルを持たせる。

普通のPCと同じように、IPは他と重複しないようにする。

以下は動画で使用していたコマンド。Pathは自分のものに合わせる。

# 今後複数の仮想マシンを作ることを想定して、それらをまとめるフォルダ(MyVagrant)を作る
mkdir MyVagrant

# MyVagrantに移動する
cd MyVagrant

# 仮想マシンを作るフォルダを作る(MyCentOS)
mkdir MyCentOS

# MyCentOSに移動する
cd MyCentOS

# 仮想マシン設定用のVagrantfileを作る
vagrant init bento/centos-6.8
→下記のエラー。
 エラー内に示されていた「vagrant plugin Update」を実行し、再度コマンドを入れたら解消

Vagrant failed to initialize at a very early stage:

The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory. Vagrant can
attempt to automatically correct this issue by running:

vagrant plugin repair

If Vagrant was recently updated, this error may be due to incompatible
versions of dependencies. To fix this problem please remove and re-install
all plugins. Vagrant can attempt to do this automatically by running:

vagrant plugin expunge --reinstall

Or you may want to try updating the installed plugins to their latest
versions:

vagrant plugin update

Error message given during initialization: Unable to resolve dependency: user requested 'vagrant-vbguest (> 0)' 


# Vagrantfileを編集して仮想マシンのIPアドレスを192.168.33.10にする vagrantfileをエディタで開き、
# config.vm.network "private_network", ip: "192.168.33.10"
の行のコメントアウトを外す(#を外す)
動画ではatomを使っていた。今のところVisualStudioCodeで代用。 # 仮想マシンを起動する(少し時間かかります) vagrant up
→エラーがたくさん。まずはエラー1.

→その後、VirtualBoxとVagrantを再インストールするとエラー2が発生。
→エラー2は書かれたPathにあったIndexとIndex.Lockというファイルを消したら正常に動くようになった。
→その後はvagrant upを実行できた。やたらインストールやらアップデートやら走ってるけど大丈夫か。
→またエラー。問題山積。エラー3を参照。

エラー1

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' is up to date...
==> default: A newer version of the box 'bento/centos-6.8' for provider 'virtualbox' is
==> default: available! You currently have version '2.3.1'. The latest is version
==> default: '2.3.4'. Run `vagrant box update` to update.
==> default: Setting the name of the VM: MycentOS_default_1527516530723_78621
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: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "c57744d7-5b10-49cd-a31c-73e9893f1ac0", "--type", "headless"]

Stderr: VBoxManage.exe: error: Raw-mode is unavailable courtesy of Hyper-V. (VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole

これはHyper-Vの設定をしてやると解消。

エラー2

The machine index which stores all required information about
running Vagrant environments has become corrupt. This is usually
caused by external tampering of the Vagrant data folder.

Vagrant cannot manage any Vagrant environments if the index is
corrupt. Please attempt to manually correct it. If you are unable
to manually correct it, then remove the data file at the path below.
This will leave all existing Vagrant environments "orphaned" and
they'll have to be destroyed manually.

Path: C:/Users/(ユーザー名)/.vagrant.d/data/machine-index/index

最後に書かれたフォルダにあったIndexとIndex.lockを削除。

その後最後実行したら解決。

エラー3

/sbin/mount.vboxsf: mounting failed with the error: No such device

仮想環境の起動は成功しているっぽいけど上記エラーが出る。

共有の設定だと思われるが…。

エラー3が解消できなかったので、これは明日へ持ち越し。

実行したいコマンドがあと1個残っていたが、これを叩けるのはいつの話になるだろうか…。

# 仮想マシンの状態を確認する
vagrant status

 

明日も続けて頑張る。水曜までには仮想環境構築のレッスンを終えたい。

 

※参照

今夜の教材 ドットインストール ローカル開発環境の構築(Win編) #1~#5

https://dotinstall.com/lessons/basic_localdev_win_v2

エラー1、エラー2への対処

[vagrant][windows10]Windows + VirtualBox (+ vagrant) でvagrant upできなくなったとき

Win10にVirtualBox+Vagrantを用いた環境構築する為の下準備

エラー3への対処

Windows上でVirtualBox+Vagrant+CentOSによる仮想環境構築

はじめに

あーるです。自分が気になることを書いていきます。

 

・プログラムの勉強

・映画の感想

・ゲームのなんやかんや

 

プログラミングで勉強したことの走り書きみたいな使い方をするのが大部分だと思う。

プログラミングの勉強ではまず以下のことに取り組む。

 

★Web系の言語(PHPなど)が書けるようになる

ログイン機能、画像投稿機能、データダウンロード機能が備わった掲示板を作るのが当面の学習目標。以下のブログで紹介されていたのでやってみたいと思った。

axia.co.jp

仕事は一応プログラマとはいえ、会社はいまだにVB6で開発しているところなので自分で学習していかないといろいろヤバいなと感じています。

ドットインストールや書籍、その他Webを検索して模索していく予定。

慣れている人からすれば簡単かもしれないけど、時間をかけてでもしっかりやっていきたい。

じっくりとはいいつつ、8月末~9月中旬には完成させたい。

 

自分の技術力向上や転職に向けたスキル獲得など、いろいろ思うところはあるけど頑張っていきます。