ºìÁªLinuxÃÅ»§
Linux°ïÖú

WindowsÏÂÅäÖÃVagrant»·¾³

·¢²¼Ê±¼ä:2014-07-07 10:37:42À´Ô´:ºìÁª×÷Õß:velcbo
VagrantÊÇÒ»¸ö»ùÓÚ Ruby µÄ¹¤¾ß£¬ÓÃÓÚ´´½¨ºÍ²¿ÊðÐéÄ⻯¿ª·¢»·¾³¡£ËüʹÓà Oracle µÄ¿ªÔ´VirtualBoxÐéÄ⻯ϵͳ¡£

Vagrant ÔÚ¿ìËٴ¿ª·¢»·¾³·½ÃæÊǺÜÔ޵ģ¬ÊÔÏëÒ»¸öÍŶÓÖУ¬´ó¼Ò¿ª·¢Í¬Ò»¸ö¶«Î÷£¬ÒÔǰÿ¸öÈ˶¼Òª×Ô¼º´î½¨Ò»Ì׿ª·¢»·¾³ £¬ÓÐÁË Vagrant£¬ÄãÖ»ÐèÒª´î½¨Ò»·Ý£¬È»ºó·Ö·¢¸øËùÓÐÍŶӳÉÔ±£¬ÕâÑù´ó¼Ò¶¼Á¢¿Ì¾ÍÓÐÍêÈ«ÏàͬµÄ¿ª·¢»·¾³ÁË£¬¼´±ãÓгÉÔ±ÔÚWindows Ï£¬Ò²¿ÉÒÔ·½±ãµÄʹÓà Linux »·¾³¿ª·¢¡£Èç¹ûÍŶÓÖÐÀ´ÁËÐÂÈË£¬Ò²²»ÐèÒªÊÖ°ÑÊÖ½ÌËûÔõô´î½¨¿ª·¢»·¾³£¬¸øËû¶ªÒ»¸öBox ¾ÍºÃÁË£¬Ö»ÒªËûÕÆÎÕÁË Vagrant µÄʹÓ÷½·¨£¬Á¢¿Ì¾Í¿ÉÒÔÈÚÈëµ½¿ª·¢ÖÐÀ´£¬¶ø²»ÐèÒª·ÑÐÄÈ¥°²×°¸´ÔӵĻ·¾³¡£

Vagrant µÄ¿çƽ̨µÄÌØÐÔ¼òÖ±ÊÇÌ«°ôÁË£¬Õâ¶¼ÒªÀûÒæÓÚ VirtualBox ÕâÑùÒ»¿îÓÅÐãµÄÈí¼þºÍ Vagrant ÕâЩÌì²Å¹¤³ÌʦÃÇ¡£

Vagrant »¹Ö§³ÖʹÓÃChefºÍPuppetÀ´Î¬»¤ÄãµÄÐéÄ⿪·¢»·¾³£¬²»¹ýÒòΪÎÒ¶ÔÕâÁ½¸ö¹¤¾ß²¢²»ÊìϤ£¬±¾ÎÄÖв»×÷½éÉÜ£¬Ö»¼òµ¥ ½éÉÜÈç¹ûÔÚ Windows ÏÂÅäÖÃÒ»¸ö Vagrant »·¾³¡£
°²×° Vagrant

´Ó Vagrant ¹ÙÍøÏÂÔØ×îÐ嵀 Vagrant ºÍ¶ÔÓ¦µÄ VirtualBox °²×°ºó£¬Ð½¨Ò»¸öÎļþ¼ÐÓÃÀ´ÅäÖà Vagrant

ÒòΪʹÓÃvagrant init precise32 http://files.vagrantup.com/precise32.boxÃüÁîÏÂÔØ box »á±È½ÏÂý£¬ ËùÒÔ×îºÃÊÇÌáǰʹÓÃѸÀ׵ȹ¤¾ßÏÂÔØºÃ box ·ÅÔÚÒ»¸öÎļþÖУ¬È»ºó³õʼ»¯Ê±Ê¹Óñ¾µØÂ·¾¶£¬»á¿ìºÜ¶à¡£

vagrant init precise32 ..\boxes\precise32.box

ÐèҪעÒâµÄÊÇ£¬ÕâÀïʹÓñ¾µØÂ·¾¶Ê±£¬ÐèҪʹÓà Windows ·ç¸ñµÄ·¾¶£¬¼´ÓÃ\À´×÷Ϊ·¾¶·Ö¸ô·û¡£

PS:¿ÉÓÃµÄ Vagrant Boxes ¼ûÕâÀhttp://www.vagrantbox.es/
¶Ë¿Úת·¢

Vagrant ÖÐÅäÖö˿Úת·¢·Ç³£·½±ã

Vagrant.configure("2") do |config|
# other config here

config.vm.network :forwarded_port, guest: 80, host: 8080
end

ÉÏÃæµÄÅäÖûὫ Vagrant ÖÐµÄ 80 ¶Ë¿ÚºÍÄã±¾»úµÄ 8080 ¶Ë¿Ú½¨Á¢×ª·¢¹ØÏµ£¬ÕâÑùÄãÔÚ±¾»ú·ÃÎÊ http://localhost:8080 ¾ÍÏ൱ÓÚ·ÃÎÊ Vagrant ÖÐµÄ http://localhost:80 ÁË¡£

¶Ë¿Úת·¢¿ÉÒÔÅäÖöà×é¡£
¹²ÏíÎļþ¼Ð

ʹÓà Vagrant ÓÐÒ»¸ö·Ç³£ÖØÒªµÄÒ»²½¾ÍÊǹ²ÏíÎļþ¼Ð£¨µÃÒæÓÚÇ¿´óµÄ VirtualBox£©

ÔÚVagrantfileÖÐÉèÖÃ

config.vm.synced_folder "E:/Blog", "/home/vagrant/Blog"

ÆäÖеÚÒ»¸ö²ÎÊýE:/BlogΪ±¾»úÉÏÐèÒª¹²ÏíµÄÎļþ¼Ð·¾¶£¬µÚ¶þ¸ö²ÎÊýΪ Vagrant ÐéÄâ»úÖеÄÓ³Éä·¾¶£¬×¢ÒâµÚ¶þ¸ö²ÎÊýÐèÒª ʹÓþø¶Ô·¾¶£¬Èç/home/vagrant/Blog
Á¬½ÓÖÁ Vagrant

ÅäÖúú󣬾ͿÉÒÔÆô¶¯ÐéÄâ»ú²¢Á¬½Óµ½ Vagrant ÁË¡£

Ê×ÏÈ£¬Ö´ÐÐvagrant up£¬µÈ´ýƬ¿Ì£¬vagrant ¾ÍÆô¶¯ºÃÁË¡£ ::

e:\Vagrant\precise32>vagrant reload
[default] Attempting graceful shutdown of VM...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] -- 5000 => 5000 (adapter 1)
[default] -- 3000 => 3000 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /home/vagrant/Blog
[default] -- /home/vagrant/Notes
[default] -- /home/vagrant/Projects

Èç¹ûÄãvagrant upºóÓÖÐÞ¸ÄÁË Vagrantfile£¬ÒªÊ¹Ö®ÉúЧ£¬ÐèÒªÖ´ÐÐvagrant reload

ÔÚ Windows Ï£¬²»ÄÜʹÓÃvagrant sshÀ´Ö±½Ó·ÃÎÊ vagrnat£¬²»¹ý¸ÃÃüÁî»á¸æËßÄãÈçºÎͨ¹ý ssh Á¬½Ó vagrant ::

e:\Vagrant\precise32>vagrant ssh
`ssh` executable not found in any directories in the %PATH% variable. Is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
contain an SSH client. Or use the PuTTY SSH client with the following
authentication information shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Documents and Settings/greatghoul/.vagrant.d/insecure_private_key

ÕâÑùÄã¾Í¿ÉÒÔʹÓÃÀàËÆ putty µÄ ssh ¿Í»§¶ËÀ´·ÃÎÊ vagrant À´½øÐпª·¢ÁË£¬ÕâÀKÁ¦ÍƼö Chrome À©Õ¹Secure Shell¡£

À´Ô´£ºLinuxÉçÇø
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ