ãªãã¨ãªãæµãã§æ°ãã¤ãããä»®æ³ãã·ã³ãã³ãã³ãã©ã¤ã³ããçæãããèµ·åããããããã¼ã«ã§ãã vagrant ããããã¯ããã¦ãããã¨ãããã debian ä¿¡è ã§ãã俺ã¯å½ç¶ã®ããã« A list of base boxes for Vagrant ãã Debian ã®ææ° stable release ã§ãã wheezy ã® vanilla base box ãæ¾ã£ã¦ãããã¨ããã
ã¨ããããã¡ã¤ã«ãå£ãã¦ãã®ããªããªã®ããã¾ãèµ·åããªãããããããªãã®ã§èªåã§ä½ãå§ããã®ã ãæ¥æ¬èªã®ããã¥ã¡ã³ãããªãã®ã§ã¨ããããã¡ã¢çã«ããã«æ¸ãã¦ããã
ã¨ãããã vagrant æ¬ä½ã®ã¤ã³ã¹ãã¼ã«ã ãã gem install vagrant ã¨ããã¤ã³ã¹ãã¼ã«æ¹æ³ã¯ä½¿ããªããªã£ããå¤ããã¼ã¸ã§ã³ããå ¥ããªããä»ã¯ãªãã£ã·ã£ã«ãµã¤ãã® ダウンロードページ ããã¤ã³ã¹ãã¼ã©ãæ¾ã£ã¦ããããã«ãªã£ããããã
次㫠VirtualBox ãã¤ã³ã¹ãã¼ã«ãããæ°ãã vagrant 㯠VMware ã使ããããã«ãªã£ããããã®ã ããã¨ããããå¾æ¥éã VirtualBox ãå©ç¨ãã¦ã¿ããã¨ã«ããã
ä»å㯠Debian 7 wheezy ã® base box ãä½ãã®ã§ãDebian on CDs ããä»ç¾å¨ã® stable release ãæ¾ã£ã¦ããã俺ããã¤ã使ãã®ã¯æå°ãµã¤ãºã® debian-7.3.0-amd64-netinst.iso ã¨ãããã¤ã200M ç¨åº¦ãããªãã®ã§å®ã¯ãã¤ãæå ã«ããã¦ããã
VirtualBox ãèµ·åãã¦ãDebian ãæ®éã«ã¤ã³ã¹ãã¼ã«ãã*1ããã ã vagrant base box ç¨ã«ã¦ã¼ã¶ã¼åããã¹ã¯ã¼ã㯠vagrant v1 ç¨ã®ããã¥ã¡ã³ãã ã Vagrant Documentation - Base Boxes ã«ããããã«ã
Vagrant Documentation - Documentation - Base Boxes
- Hostname: vagrant-[os-name], e.g. vagrant-debian-lenny
- Domain: vagrantup.com
- Root Password: vagrant
- Main account login: vagrant
- Main account password: vagrant
ã¨ããããã«ãããä»å㯠wheezy ãªã®ã§ hostname 㯠vagrant-debian-wheezy ã«ããã
ä»å㯠vanilla wheezy ã欲ããã®ã§æå°æ§æã§ã¤ã³ã¹ãã¼ã«ãããã¤ã³ã¹ãã¼ã©ã®ãªãã·ã§ã³ã§åºã¦ãã desktop environment ã¨ãã¯å ¨é¨å¤ããã
ããã§ãã£ã¦ãä¸åº¦ root ã§ãã°ã¤ã³ãã
# apt-get install openssh-server sudo
追å ã§å ¥ããããã±ã¼ã¸ã¯ããã ãã
v1 ããã¥ã¡ã³ãã«ã¯ VirtualBox ã®ãã¼ã«ãå ¥ããããã«æ示ããã¦ããã©ããªããæ®éã« wheezy ã®ã¤ã³ã¹ãã¼ã©ã VirtualBox ç¨ã®ããã±ã¼ã¸å ¥ãã¦ããã¦ãããå¥ã«ããããªã£ã¦ã
sudo ã®ã»ããã¢ãã
ãã¦ãããã vagrant ç¨ã®ã»ããã¢ããã«å ¥ããvagrant 㯠base box ãæåã«èµ·åããã¨ãã«ã vagrant ã¨ããååã®ã¦ã¼ã¶ã¼ã§ sudo mkdir -p /vagrant ãªã©ãããããããã®ã¨ããã¹ã¯ã¼ããèªåå ¥åãããããªãã®ã§ãvisudo ã³ãã³ãã§
vagrant ALL=(ALL:ALL) NOPASSWD: ALL
ã¨ããè¡ãä»ãå ããããã¡ãã v1 ããã¥ã¡ã³ãã®ããã«
%sudo ALL=(ALL:ALL) ALL
ã¨ãªã£ã¦ãè¡ã
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
ã¨ç·¨éãã vigr 㧠vagrant ã¦ã¼ã¶ã¼ã sudo ã°ã«ã¼ãã«å ¥ãã¦ãæ§ããªãã ããã
ssh ã®ã»ããã¢ãã
ãããã vagrant ã¦ã¼ã¶ã¼ã ssh ã¢ã¯ã»ã¹ã§ããããã«ãinsecure key ãé
ç½®ããã
v1 ããã¥ã¡ã³ãã«ã¯ github ã«ããã¦ããéµã使ãã¨æ¸ãã¦ããã®ã ããããã ã¨ãã¾ã® vagrant ã§ã¯ã¢ã¯ã»ã¹ã§ããªãããã ããããããªãã®ã§ vagrant ãã¤ã³ã¹ãã¼ã«ãããã¹ãã§
$ ssh-keygen -y -f ~/.vagrant.d/insecure_private_key > ~/tmp/insecure_public_key
ã¨ããæãã§ç§å¯éµããå ¬ééµãä½ããããããªãããã®æ¹æ³ã§ VirtualBox ã§åãã¦ãä»®æ³ãã·ã³å ã® /home/vagrant/.ssh/authorized_keys ã«é ç½®ããã俺ã¯é©å½ãªã¦ã§ããµã¼ãã«ãã㦠wget ã§åå¾ããã
ãã¡ãã /home/vagrant/.ssh 以ä¸ã®ãªã¼ãã¼ã·ããã vagrant:vagrant ã«å¤æ´ã®ä¸ã.ssh ã®ãã¼ããã·ã§ã³ã 700 ã«å¤æ´ãã¦ããã
ã¤ãã§ã« v1 ããã¥ã¡ã³ãã«ãããã®ã ããsshd ãã¢ã¯ã»ã¹å ã¢ãã¬ã¹ãéå¼ããããã¨ãã¦æ¥ç¶ã«æéãããã£ããããªãããã«ã /etc/ssh/sshd_config ã«
UseDNS no
ãªãã¦è¡ã追å ãã¦ããã
ã¨ãã㧠sshd ã®éµãã¢ã£ã¦åãã®ä½¿ãã¾ããã®ãªããæ°æã¡æªããã ãã©ãbase box ãæåã«èµ·åãããæã«çæããªããæ¹æ³ã£ã¦ãªãããã§ããã? éµãåé¤ã㦠dpkg-reconfigure openssh-server ããã°ãããã ãããã©1度ã ãèªåã§ããã¨ãã©ãããã®ãã¹ãã¼ãããªãã
vagrant 㧠package ãã
ãã¦ããã¾ã§ã§ããããã¨ã¯ä»®æ³ãã·ã³ã shutdown ã㦠vagrant package ããã
äºåã« apt-get clean ãã¦ãããã¨ãå¿ããªãããã«ãããã§ãã£ãã·ã¥ããã¦ãããã±ã¼ã¸ãæ¶ããã
æ°ã«ãªã人ã¯äºåã« .bash_history ãªã©ãåé¤ãã¦ããããã¡ãªã¿ã« bash ã¯çµäºæã«ãã¹ããªãæ¸ãè¾¼ãã®ã§ãroot ã® .bash_history ã¯æå°ã§ã rm ~/.bash_hisotry; shutdown -h now ãªã©ãæ®ããã¨ã«ãªãã
ä»®æ³ãã·ã³ãçµäºãããã以ä¸ã®ãããªã³ãã³ã㧠base box ãä½æããã
$ vagrant package --base path/to/virtualmachine
ããããã¨ã«ã¬ã³ããã£ã¬ã¯ããªã« package.box ã¨ããååã§ä½æãããã ls -lh ãã¦ã¿ã㨠455M ã ã£ãã
ãããªæãã§ä½ã£ããã®ãã以ä¸ã«ç½®ãã¦ãããã
ãã¦å®éã«åä½ããããã¹ããã¦ã¿ããã
$ vagrant box add wheezy path/to/package.box
ã¨ããã¨æå ã® vagrant ã« wheezy ã¨ããååã® base box ã追å ãããã
é©å½ãªãã£ã¬ã¯ããªãæã£ã¦ã
$ vagrant init wheezy
ãã㧠wheezy ã¨ããååã§ããã¦ããã base box ããä»®æ³ãã·ã³ãä½ããã«ã¬ã³ããã£ã¬ã¯ããªã« Vagrantfile ãçæããã¦ãã¯ãã
ããã¦ããããâ¦â¦
$ vagrant up
ã§èµ·åããããã¾ãèµ·åã§ããã ããã?
ã©ãã§ããããã© vagrant up ã£ã¦ãªããé¿ããããããã¢ãã¡ã®åä½ã¨ããã¼ãã¼ã®å¤èº«ã®æã声ã¿ããã ããªãã´ã¡ã°ã©ã³ãã¢ãã!
ãã¾ãèµ·åã§ãããã
$ vagrant ssh
ã§æ¥ç¶ã§ããã確èªãããã
$ vagrant ssh-config --host v-d-w >> ~/.ssh/config
ã¨ãããããªæã㧠ssh è¨å®ãæ¸ãè¾¼ãã¨ã
$ ssh v-d-w
ã ãã§ã¢ã¯ã»ã¹ã§ããããã«ãªãã
ã¨ããããã§
ãä»®æ³æ©å µã´ã¡ã°ã©ã³ãã次åãã´ã¡ã°ã©ã³ãã¢ãã!ã