LoginSignup
3
3

More than 5 years have passed since last update.

Vagrant(1.8.1)でCentOSをインストールする

Last updated at Posted at 2016-03-06

目次

  • 目的
  • 関連サイト
  • 公式サイト
  • 環境
  • 手順

目的

以前、Windows7にVagrantをインストールしたが、OSをWindows10にアップグレードしたので、これにVagrantをインストールしなおしてみる。boxの取得元とboxの追加方法に変化があったようである。

  • Windows10のVirtual BoxにCentOSをインストールする
  • インストールにはVagrantを使用する
  • VagrantでインストールしたCentOSに接続する
  • CentOSの接続にはTeraTermを使用する

関連サイト

公式サイト

環境

ホストマシン

  • Windows 10 Home(64bit)
  • Vagrant 1.8.2
  • VirtualBox 5.0.16-105871

ゲストマシン(今回インストールする)

  • CentOS 7.2

手順

  • Vagrantのboxの選択
  • Vagrantにboxをadd
  • Vagrantのboxから仮想マシンを生成
  • 仮想マシンに接続

Vagrantのboxの選択

  • Vagrant Cloudにアクセスする。

  • 表示されたページ内の「Discover Vagrant Boxes」にある検索ボックスに"CentOS 7.2"を入力する。

VagrantCloud_001.png

  • 検索結果から目的にあったBoxを選ぶ。ここでは「puppetlabs/centos-7.2-64-nocm」を選ぶ。ただし、ここでリンクをクリックする必要はない。

VagrantCloud_002.png

Vagrantにboxをadd

  • VMを格納するフォルダを用意し、移動する。
C:\>cd C:\Users\hoge
C:\Users\hoge>mkdir "VirtualBox VMs"
C:\Users\hoge>cd "VirtualBox VMs"
  • Boxを追加する。 コマンドプロンプトで以下のとおり実行する。ここで「init」の後に続ける文字列は、先に検索した結果に表示された文字列となる。
C:\Users\hoge\VirtualBox VMs>vagrant init puppetlabs/centos-7.2-64-nocm
vagrant init puppetlabs/centos-7.2-64-nocm
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.
  • 追加されたboxを確認する。
C:\Users\hoge\VirtualBox VMs>vagrant box list
puppetlabs/centos-7.2-64-nocm (virtualbox, 1.0.0)

Vagrantのboxから仮想マシンを生成

  • 仮想マシンを起動する。
C:\Users\hoge\VirtualBox VMs>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'puppetlabs/centos-7.2-64-nocm'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'puppetlabs/centos-7.2-64-nocm' is up to date...
==> default: Setting the name of the VM: VirtualBoxVMs_default_1457271373412_95468
==> 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: Warning: Remote connection disconnect. Retrying...
    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: 4.3.22
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/hoge/VirtualBox VMs
  • 仮想マシンの確認。VirtualBoxを起動し、仮想マシンが存在し、"実行中"であることを確認する。

VagrantCloud_003.png

仮想マシンへの接続

vagrant upによって起動した仮想マシンではSSHサーバが起動しているため、ホストからSSHによって接続することが可能である。SSHでの接続方法はvagrantコマンド経由での接続と通常通りのSSHクライアントを起動しての接続がある。

vagrantコマンド経由での接続

Windowsがホストマシンの場合、vagrantコマンドは内部的に別のSSHクライアントを呼び出す。そのため、CygwinやMinGWなどでSSHのクライアントがインストールされている必要がある。なお、CygwinやMinGWなどでSSHのクライアントがインストールされていない場合、vagrantコマンド経由で接続しようとすると以下の様な出力を得る。

C:\Users\hoge\VirtualBox VMs> cd VirtualBoxVMs_default_1457271373412_95468
C:\Users\hoge\VirtualBox VMs\VirtualBoxVMs_default_1457271373412_95468>vagrant ssh
`ssh` executable not found in any directories in the %PATH% variable. Is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
contain an SSH client. Or use your favorite SSH client with the following
authentication information shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/hoge/VirtualBox VMs/.vagrant/machines/default/virtualbox/private_key

SSHクライアントを起動しての接続

SSHクライアントを使用して、仮想マシンへ接続する。ここでは、TeraTermを使用する。

  • TeraTermを起動する。ホストに"127.0.0.1"、サービスに"SSH"、TCPポートに"2222"、SSHバージョンに"SSH2"を入力する。

VagrantCloud_004.png

  • セキュリティ警告のダイアログが表示されるので、"このホストをknown hostsリストに追加する(A)"のチェックボックスをオンにして[続行]をクリックする。

VagrantCloud_005.png

  • SSH認証のダイアログが表示されるので、ユーザ名に"vagrant"、パスフレーズは空白、RSA/DSA/ECDSD/ED25519鍵を使うの部分にコマンドプロンプトにて「vagrant ssh」を実行した際に一番最後に出力された「Private key:」のパスを入力する。[OK]をクリックする。

VagrantCloud_006.png

  • SSH接続完了

VagrantCloud_007.png

以上

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3