拝承です。

サーバエンジニアの個人的メモ。主にCentOSとMac。たまにWindows、カメラネタもあり。

VagrantでCentOS 7を立ち上げる

OSイメージの入手から、起動して終了してみるまで

boxの追加

ここで仮想マシンのテンプレートを探す

Discover Vagrant Boxes | Atlas by HashiCorp

 

 CentOS 7のboxをダウンロード

$ vagrant box add centos/7

==> box: Loading metadata for box 'centos/7'

    box: URL: https://atlas.hashicorp.com/centos/7

This box can work with multiple providers! The providers that it

can work with are listed below. Please review the list and choose

the provider you will be working with.

 

1) libvirt

2) virtualbox

 

Enter your choice: 2

==> box: Adding box 'centos/7' (v1603.01) for provider: virtualbox

    box: Downloading: https://atlas.hashicorp.com/centos/boxes/7/versions/1603.01/providers/virtualbox.box

==> box: Successfully added box 'centos/7' (v1603.01) for 'virtualbox'!

 

$ vagrant box list

centos/7 (virtualbox, 1603.01)

ダウンロードされた

Vagrant初期設定

仮想マシンごとにディレクトリを作成して初期化

$ cd ~

$ mkdir -p vagrant/vm1

$ cd vagrant/vm1

$ vagrant init centos/7

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.

仮想マシン起動

$ vagrant up

Bringing machine 'default' up with 'virtualbox' provider...

==> default: Importing base box 'centos/7'...

==> default: Matching MAC address for NAT networking...

==> default: Checking if box 'centos/7' is up to date...

==> default: Setting the name of the VM: vm1_default_1461916092013_42692

==> 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: Warning: Remote connection disconnect. Retrying...

    default: Warning: Remote connection disconnect. Retrying...

    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: No guest additions were detected on the base box for this VM! Guest

    default: additions are required for forwarded ports, shared folders, host only

    default: networking, and more. If SSH fails on this machine, please install

    default: the guest additions and repackage the box to continue.

    default: 

    default: This is not an error message; everything may continue to work properly,

    default: in which case you may ignore this message.

==> default: Rsyncing folder: /Users/tejitejt/vm1/ => /home/vagrant/sync

起動したっぽい

仮想マシンssh

$ vagrant ssh

[vagrant@localhost ~]$

プロンプトが変わった

[vagrant@localhost ~]$ cat /etc/redhat-release 

CentOS Linux release 7.2.1511 (Core)

きた〜

仮想マシンを抜ける

[vagrant@localhost ~]$ logout

Connection to 127.0.0.1 closed.

仮想マシンを落とす

$ vagrant halt

==> default: Attempting graceful shutdown of VM...

 

参考

ruby-rails.hatenadiary.com