LoginSignup
35
34

More than 5 years have passed since last update.

MacでVagrant(chef/centos-6.5)使ってみる

Last updated at Posted at 2014-12-09

Intro

単なる構築メモです。
chefがメンテしているCentOS6.5のイメージを入れてみます。

必要な物

VirtualBox

環境

  • MacBook Pro Retina, 15-inch, Late 2013
  • OS X 10.9.5(13F34)
  • iTerm or Terminal

手順

1.Vagrantダウンロード

http://www.vagrantup.com/downloads.html
からdmgをダウンロードし、インストール。(現時点では1.6.5)

$ vagrant --version
Vagrant 1.6.5

2.Vagrant用のディレクトリ作る

今回はホームにVagrantディレクトリを作ることにした。

mkdir -p ~/Vagrant

3.boxイメージをダウンロード

esのボックスイメージから落とそうと思ったが
メンテナンスが適当らしい。

https://vagrantcloud.com/discover/
からとってくるのが簡単らしい。今回はchefがメンテしてるCentOS6.5を使う。

下記コマンドでboxイメージなければダウンロードまで行ってVMを起動してくれる。
すごい!!時間がちょっとかかります。

cd ~/Vagrant
mkdir chef-centos-6.5
cd chef-centos-6.5
vagrant init chef/centos-6.5
vagrant up

正常終了すればOK

起動が終わるとboxが追加されてるのがわかります

$ vagrant box list
chef/centos-6.5 (virtualbox, 1.0.0)

4.ログインテスト

普通にログインできればOK

$ vagrant ssh
Last login: Fri Mar  7 16:57:20 2014 from 10.0.2.2
[vagrant@localhost ~]$

5.sshの設定しておく

vagrant ssh-config >> ~/.ssh/config
~/.ssh/config
Host centos65 #ここを任意に変える
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/takaito/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
ssh centos65

でssh接続できればOK

6.Vagrantファイルをいじる

開発用途(ElasticSearch/fluent/rubyなどいろいろいじる)なのでメモリ増加やIPの設定など。

Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "chef/centos-6.5"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.network "public_network"
  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.customize ["modifyvm", :id, "--memory", "4096"]
  end
end

7.その他コマンドまとめ

#起動
vagrant up

#サスペンド
vagrant suspend

#停止
vagrant halt

#再起動
vagrant reload

#状態確認
vagrant status

#rootの初期パスワード
vagrant

追記

chefのboxはbentoに移行されていた!
https://atlas.hashicorp.com/bento/boxes/

参考URL

http://www.vagrantbox.es/
https://vagrantcloud.com/discover/popular
http://easyramble.com/install-vagrant-virtualbox-on-mac.html

35
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
34