2014年2月25日火曜日

vagrant で box 追加後SSH接続する

boxは以下にまとめられています。
http://www.vagrantbox.es/

今回はCentOSを例に導入してみます。



boxを導入

[user@localhost ~]$ vagrant box add CentOS01 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
Downloading box from URL: https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
Extracting box...te: 981k/s, Estimated time remaining: --:--:--)
Successfully added box 'CentOS01' with provider 'virtualbox'!
[user@localhost ~]$ vagrant init CentOS01                                                                                                                                                                         
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.
[user@localhost ~]$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'CentOS01'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant
ここで追加したboxに対しSSHを行おうとすると、怒られる。
[user@localhost ~]$ vagrant ssh                                                                                                                                                                                   
`ssh` binary could not be found. Is an SSH client installed?
んー。
[user@localhost ~]$ ss
ss          ssh-keygen  sshd        ssltap
sshコマンドがない。ので導入します。ssh コマンドはopenssh-clientsで導入出来ます。
[user@localhost ~]$ yum install openssh-clients
これでSSH接続出来るようになりました。
[user@localhost ~]$ 
vagrant ssh
[vagrant@vagrant-centos65 ~]$ pwd
/home/vagrant