ぽぬメモ!

ただのゲーム好きオヤジ

今日のvagrantの備忘

備忘

Vagrantのインストール
MacBook-Air:~ Hoge brew cask install vagrant
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
bluetoothconnector                                              dmg2img
==> Updated Formulae
gitlab-runner            i2pd                     percona-server           telegraf                 youtube-dl
gmsh                     mplayer                  root                     vault
==> Deleted Formulae
percona-server@5.6

==> Satisfying dependencies
==> Downloading https://releases.hashicorp.com/vagrant/2.2.3/vagrant_2.2.3_x86_64.dmg
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'vagrant'.
==> Installing Cask vagrant
==> Running installer for vagrant; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
installer: Package name is Vagrant
installer: Upgrading at base path /
installer: The upgrade was successful.
🍺  vagrant was successfully installed!
Vagrantのバージョン確認
MacBook-Air:~ Hoge vagrant --version
Vagrant 2.2.3
virtualboxのインストール
MacBook-Air:~ Hoge brew cask install virtualbox
Updating Homebrew...
==> Caveats
To install and/or use virtualbox you may need to enable their kernel extension in

  System Preferences → Security & Privacy → General

For more information refer to vendor documentation or the Apple Technical Note:

  https://developer.apple.com/library/content/technotes/tn2459/_index.html

==> Satisfying dependencies
==> Downloading https://download.virtualbox.org/virtualbox/6.0.2/VirtualBox-6.0.2-128162-OSX.dmg
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'virtualbox'.
==> Installing Cask virtualbox
==> Running installer for virtualbox; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
installer: Package name is Oracle VM VirtualBox
installer: Upgrading at base path /
installer: The upgrade was successful.
🍺  virtualbox was successfully installed!
作業用のディレクトリの作成
MacBook-Air:~ Hoge mkdir ~/vagrant
MacBook-Air:~ Hoge cd ~/vagrant
vagrant環境にCentOS7をダウンロードし追加
MacBook-Air:vagrant Hoge$ vagrant box add centos7 http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.0_chef-provisionerless.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos7' (v0) for provider: 
    box: Downloading: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.0_chef-provisionerless.box
The box you're attempting to add already exists. Remove it before
adding it again or add it with the `--force` flag.

Name: centos7
Provider: virtualbox
Version: 0
vagrant環境のCentOS7を起動
MacBook-Air:vagrant Hoge$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos7'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant_default_1548278079343_36676
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: 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: 
    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.20
    default: VirtualBox Version: 6.0
==> default: Mounting shared folders...
    default: /vagrant => /Users/Hoge/vagrant
vagrant環境のCentOS7にログイン
MacBook-Air:vagrant Hoge$ vagrant ssh
Last login: Wed Feb 25 04:07:22 2015 from 10.0.2.2
vagrant環境のCentOS7、バージョン確認
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core) 
vagrant環境のCentOS7を最新にバージョンアップ
[vagrant@localhost ~]$ sudo yum update -y
読み込んだプラグイン:fastestmirror
base                                                                                                    | 3.6 kB  00:00:00     
extras                                                                                                  | 3.4 kB  00:00:00     
updates                                                                                                 | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                           | 166 kB  00:00:00     
(2/4): updates/7/x86_64/primary_db                                                                      | 1.3 MB  00:00:01     
(3/4): extras/7/x86_64/primary_db                                                                       | 156 kB  00:00:05     
(4/4): base/7/x86_64/primary_db                                                                         | 6.0 MB  00:00:08     
Determining fastest mirrors
 * base: ftp.jaist.ac.jp
 * extras: mirror.qoxy.com
 * updates: mirror.qoxy.com
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ ModemManager-glib.x86_64 0:1.1.0-6.git20130913.el7 を 更新
省略
依存性関連をインストールしました:
  audit-libs-python.x86_64 0:2.8.4-4.el7       checkpolicy.x86_64 0:2.5-8.el7           container-selinux.noarch 2:2.74-1.el7  
  containerd.io.x86_64 0:1.2.2-3.el7           docker-ce-cli.x86_64 1:18.09.1-3.el7     libcgroup.x86_64 0:0.41-20.el7         
  libseccomp.x86_64 0:2.3.1-3.el7              libsemanage-python.x86_64 0:2.5-14.el7   libtool-ltdl.x86_64 0:2.4.2-22.el7_3   
  policycoreutils-python.x86_64 0:2.5-29.el7   python-IPy.noarch 0:0.75-6.el7           setools-libs.x86_64 0:3.3.8-4.el7      

完了しました!
systemdを使ってDockerコンテナのCentOS7をサービスを起動
[admin@localhost vagrant]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[admin@localhost vagrant]$ sudo systemctl start docker
Docker Composeを使って複数のDockerコンテナを扱いやすくする
[admin@localhost vagrant]$ sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    797      0 --:--:-- --:--:-- --:--:--   797
100 10.3M  100 10.3M    0     0  2885k      0  0:00:03  0:00:03 --:--:-- 5541k
実行権限を付与する
[admin@localhost vagrant]$ sudo chmod +x /usr/local/bin/docker-compose
Dockerコンテナを再起動
[admin@localhost vagrant]$ sudo systemctl restart docker
ユーザーを追加
[admin@localhost vagrant]$ sudo gpasswd -a $USER docker
ユーザ admin をグループ docker に追加
おしまい
[admin@localhost vagrant]$ exit
exit
[vagrant@localhost ~]$ exit
ログアウト
Connection to 127.0.0.1 closed.