GeoJackass

ちゃらんぽらんの絶対領域は、是を頑なに堅持

明日の鯖祭りのために

Vagrant SetUp Tips

Vagrantの悩みどころがいくつか解決したので、メモ

prerequisite

quick start

$ vagrant box add {title} {url}
$ vagrant init {title}
$ vagrant up
  • vagrantファイルを配備するdirは予め作成し移動する(for windows)
cd /d D:\vagrant\ubuntu14amd64

1 Boxの追加

vagrant box add {title} {url}

ex)

vagrant box add ubuntu14amd64 https://cloud-images.ubun
tu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box

2 仮想マシンの設定ファイルを作成する

vagrant init {title}

ex)

vagrant init ubuntu14amd64

3 仮想マシンの起動

vagrant up

4 仮想マシンへの接続

  • デフォルトでローカルループバックのアドレスを参照するので、下記の設定でsshクライアントでアクセスする
IP addr port user pwd
127.0.0.1 2222 vagrant vagrant

5 仮想マシンの一時停止

vagrant suspend

6 仮想マシンのネットワーク設定

  • default
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"
  • new
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

7 設定の変更を反映

vagrant reload
  • 通信の確認
ping 192.168.33.10

仮想マシンの起動

vagrant up
  • IPの接続に問題がない場合
IP addr port user pwd
192.168.33.10 22 vagrant vagrant

備考:要約するとvirtualenvwrapperみたいなものVMインスタンス毎のwrapper書いてくれるので設定が楽という話

ネットワークの設定のところは設定を開放しないと、127.0.0.1の喰い合いになってportが変わったり、vagrant upが走らないので必ず設定する