Kashibuchi’s blog

勉強のこと、日々のこと

Vagrant でCentOSを使えるようにする

Windows 10で、VagrantVirtualBoxを使用してCentOS7の環境を用意する。

参考 qiita.com

C:\Users\kamin>vagrant -v
Vagrant 2.2.10

C:\Users\kamin>vagrant box list
bento/centos-6.8 (virtualbox, 2.3.4)
bento/centos-7.2 (virtualbox, 2.3.1)
bento/centos-7.4 (virtualbox, 201803.24.0)

C:\Users\kamin>

CentOS7.4までのBoxが入っている。 確認するとCentOS7.8があったのでこのBoxを追加するところから始めようと思う。

app.vagrantup.com

C:\Users\kamin>vagrant box list
bento/centos-6.8 (virtualbox, 2.3.4)
bento/centos-7.2 (virtualbox, 2.3.1)
bento/centos-7.4 (virtualbox, 201803.24.0)

C:\Users\kamin>vagrant box add bento/centos-7.8 --provider virtualbox
==> box: Loading metadata for box 'bento/centos-7.8'
    box: URL: https://vagrantcloud.com/bento/centos-7.8
==> box: Adding box 'bento/centos-7.8' (v202010.22.0) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/bento/boxes/centos-7.8/versions/202010.22.0/providers/virtualbox.box
Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com
    box:
==> box: Successfully added box 'bento/centos-7.8' (v202010.22.0) for 'virtualbox'!

C:\Users\kamin>

とりあえず成功。

不要なBoxも消しておく。

C:\Users\kamin>
C:\Users\kamin>vagrant box remove bento/centos-6.8
Removing box 'bento/centos-6.8' (v2.3.4) with provider 'virtualbox'...

C:\Users\kamin>vagrant box remove bento/centos-7.2
Box 'bento/centos-7.2' (v2.3.1) with provider 'virtualbox' appears
to still be in use by at least one Vagrant environment. Removing
the box could corrupt the environment. We recommend destroying
these environments first:

default (ID: bd687fa160974433b5c08eaf83e7e44d)

Are you sure you want to remove this box? [y/N] n

C:\Users\kamin>vagrant box remove bento/centos-7.4
Removing box 'bento/centos-7.4' (v201803.24.0) with provider 'virtualbox'...

C:\Users\kamin>vagrant box list
bento/centos-7.2 (virtualbox, 2.3.1)
bento/centos-7.8 (virtualbox, 202010.22.0)

C:\Users\kamin>

一つはなんか使っているっぽいので残した。 まあヨシ。

C:\Users\kamin>vagrant plugin install vagrant-omnibus
Installing the 'vagrant-omnibus' plugin. This can take a few minutes...
Fetching vagrant-omnibus-1.5.0.gem
Installed the plugin 'vagrant-omnibus (1.5.0)'!

C:\Users\kamin>vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching micromachine-3.0.0.gem
Fetching vagrant-vbguest-0.26.0.gem
Installed the plugin 'vagrant-vbguest (0.26.0)'!

C:\Users\kamin>vagrant plugin install vagrant-hostmanager
Installing the 'vagrant-hostmanager' plugin. This can take a few minutes...
Fetching vagrant-hostmanager-1.8.9.gem
Installed the plugin 'vagrant-hostmanager (1.8.9)'!

C:\Users\kamin>vagrant plugin list
vagrant-hostmanager (1.8.9, global)
vagrant-omnibus (1.5.0, global)
vagrant-vbguest (0.26.0, global)

C:\Users\kamin>

使うかわからんがプラグインも入れた。

さて。

C:\Users\kamin>cd C:\Users\kamin\dev\vagrant

C:\Users\kamin\dev\vagrant>mkdir mysql_centos7

C:\Users\kamin\dev\vagrant>cd mysql_centos7

C:\Users\kamin\dev\vagrant\mysql_centos7>
C:\Users\kamin\dev\vagrant\mysql_centos7>
C:\Users\kamin\dev\vagrant\mysql_centos7>
C:\Users\kamin\dev\vagrant\mysql_centos7>
C:\Users\kamin\dev\vagrant\mysql_centos7>vagrant init bento/centos-7.8
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.

C:\Users\kamin\dev\vagrant\mysql_centos7>dir
 ドライブ C のボリューム ラベルは OS です
 ボリューム シリアル番号は E8EF-CC55 です

 C:\Users\kamin\dev\vagrant\mysql_centos7 のディレクトリ

2020/11/12  22:00    <DIR>          .
2020/11/12  22:00    <DIR>          ..
2020/11/12  22:00             3,092 Vagrantfile
               1 個のファイル               3,092 バイト
               2 個のディレクトリ  664,753,324,032 バイトの空き領域

C:\Users\kamin\dev\vagrant\mysql_centos7>

ディレクトリを作成しvagrant initした。

    # using a specific IP.
    # config.vm.network "private_network", ip: "192.168.33.10"
++  config.vm.network "private_network", ip: "192.168.33.100"

    # Create a public network, which generally matched to bridged network.
    # Bridged networks make the machine appear as another physical device on

Vagrantfileを以上のように編集しローカル接続用のIPアドレスをテキトーに設定。 そして

C:\Users\kamin\dev\vagrant\mysql_centos7>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'bento/centos-7.8'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/centos-7.8' version '202010.22.0' is up to date...
==> default: Setting the name of the VM: mysql_centos7_default_1605186474268_36268
==> 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...
==> 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: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection aborted. 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!
GuestAdditions are newer than your host but, downgrades are disabled. Skipping.
==> 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: 6.1.16
    default: VirtualBox Version: 6.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/kamin/dev/vagrant/mysql_centos7

C:\Users\kamin\dev\vagrant\mysql_centos7>

「==> default: Machine booted and ready!」の文字があるので一応成功かと。

f:id:KashibuchiKyamin:20201112221209p:plain

TeraTermで接続してみる。

ユーザ名: vagrant

パスワード: vagrant

を入れて……

f:id:KashibuchiKyamin:20201112221341p:plain

入れたー。 わーい。

C:\Users\kamin\dev\vagrant\mysql_centos7>vagrant halt
==> default: Attempting graceful shutdown of VM...

C:\Users\kamin\dev\vagrant\mysql_centos7>

お片づけをして、ここまで。