トップ 一覧 ping 検索 ヘルプ RSS ログイン

Vagrantの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!!Vagrant
{{amazon B00F418SQ8}}

*[DB2 Express-C 11.1 をVagrant上のCentOs7にインストール|http://typea.info/blg/glob/2018/08/db2-express-c-111-vagrantcentos7.html]

!!基本
!Boxカタログ
*https://app.vagrantup.com/boxes/search

!初期化
*Vagrantfileが生成される
 $ 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
*Hyper-v で起動
**Poershell を管理者で実行
 PS> vagrant up --provider=hyperv

*以下のエラーの場合のトラブルシュート
*http://typea.info/blg/glob/2018/06/windows10-pro-hyper-v-vagrant-211-switchid.html

 \import_vm_xml.ps1 : パラメーター名 'switchid' に一致するパラメーターが見つかりません。発生場所 行:1 文字:327
 + ... achines/default/hyperv/Virtual Hard Disks/disk.vhd' -switchid 'c08cb7 ...
 +                                                         ~~~~~~~~~
     + CategoryInfo          : InvalidArgument: (:) [import_vm_xml.ps1]、ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,import_vm_xml.ps1

::起動時のパラメータ(--provider=hyperv)をVagrantfileに記述
 config.vm.provider "hyperv" do |vb|
   # Customize the amount of memory on the VM:
   vb.memory = "1024"
 end

!ssh接続
 $ vagrant ssh
!net work
*ネットワークを公開
*Vagrantfile
 config.vm.network :public_network
!シャットダウン 
 $ vagrant halt
!休止
 $ vagrant suspend
!ステータス確認
 $ vagrant status
!破棄
 $ vagrant destory

!ホストとのディレクトリ共有
*最初の引数がホストのディレクトリ、2つ目がゲスト
   config.vm.synced_folder "../vagrantdata", "/vagrant_data"

!スナップショット
*スナップショットをとる
 vagrant snapshot save {スナップショット名}
*確認
 vagrant snapshot list
*リストア
 vagrant snapshot restore {スナップショット名}
*削除
 vagrant snapshot delete {スナップショット名}

""名前を付けずに一時保存の場合、push と pop が利用できる
!!プロビジョニング
!GNOME GUI
*https://mseeeen.msen.jp/centos7-gnome-desktop-with-vagrant/
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true
  
    # Customize the amount of memory on the VM:
    vb.memory = "2048"
 end
 config.vm.provision "shell", inline: <<-SHELL
   sudo yum -y groupinstall "GNOME Desktop"
   sudo yum -y install epel-release
   sudo systemctl set-default graphical.target
   systemctl get-default
   sudo shutdown -r now
 SHELL

!!作成した環境をコピー
!配布パッケージの作成
*http://vdeep.net/vagrant-package
 > vagrant package [vm名] --output [名前.box]
*例
 >vagrant package default --output centos7db2.box
!作成したパッケージの取り込み
 >vagrant box add centos7db2 centos7db2.box
!Boxを確認
 >vagrant box list
 centos/7   (hyperv, 1804.02)
 centos7db2 (virtualbox, 0)
!Boxを利用可能に
 >vagrant init centos7db2
!Boxを削除
 >vagrant box remove centos7db2
!!Tips
!proxy
::Vagrant自体に設定するには、環境変数に以下を設定
*http_proxy
*https_proxy
::ゲストOSにプロキシーを適用するには、上記設定をした上で以下のプラグインを導入
*https://qiita.com/kota344@github/items/304979feaf965afffb1a
 > vagrant plugin install vagrant-proxyconf
*Vagrantfileに追記
 if Vagrant.has_plugin?("vagrant-proxyconf") && ENV['http_proxy']
     puts '- Proxy Setting ----------------------------------'
     puts ENV['http_proxy']
     config.proxy.http     = "http://" + ENV['http_proxy']
     config.proxy.https    = "https://" + ENV['http_proxy']
     config.proxy.no_proxy = "localhost,127.0.0.1"
     puts '--------------------------------------------------'
 end